# HG changeset patch # User bcoudurier # Date 1172975180 0 # Node ID 5464e5021a67a4e67c5a789ac7d86529f110d5c6 # Parent f23c20cf757981f0fa73809f73ad7d6503323ffc dummy support for mpeg2 non linear quant diff -r f23c20cf7579 -r 5464e5021a67 avcodec.h --- a/avcodec.h Sat Mar 03 21:33:33 2007 +0000 +++ b/avcodec.h Sun Mar 04 02:26:20 2007 +0000 @@ -37,8 +37,8 @@ #define AV_STRINGIFY(s) AV_TOSTRING(s) #define AV_TOSTRING(s) #s -#define LIBAVCODEC_VERSION_INT ((51<<16)+(36<<8)+0) -#define LIBAVCODEC_VERSION 51.36.0 +#define LIBAVCODEC_VERSION_INT ((51<<16)+(37<<8)+0) +#define LIBAVCODEC_VERSION 51.37.0 #define LIBAVCODEC_BUILD LIBAVCODEC_VERSION_INT #define LIBAVCODEC_IDENT "Lavc" AV_STRINGIFY(LIBAVCODEC_VERSION) @@ -385,6 +385,7 @@ #define CODEC_FLAG2_DROP_FRAME_TIMECODE 0x00002000 ///< timecode is in drop frame format #define CODEC_FLAG2_SKIP_RD 0x00004000 ///< RD optimal MB level residual skiping #define CODEC_FLAG2_CHUNKS 0x00008000 ///< input bitstream might be truncated at a packet boundaries instead of only at frame boundaries +#define CODEC_FLAG2_NON_LINEAR_QUANT 0x00010000 ///< use MPEG-2 non linear quantizer /* Unsupported options : * Syntax Arithmetic coding (SAC) diff -r f23c20cf7579 -r 5464e5021a67 mpeg12.c --- a/mpeg12.c Sat Mar 03 21:33:33 2007 +0000 +++ b/mpeg12.c Sun Mar 04 02:26:20 2007 +0000 @@ -419,9 +419,19 @@ #ifdef CONFIG_ENCODERS +static av_always_inline void put_qscale(MpegEncContext *s) +{ + if(s->q_scale_type){ + assert(s->qscale>=1 && s->qscale <=12); + put_bits(&s->pb, 5, inv_non_linear_qscale[s->qscale]); + }else{ + put_bits(&s->pb, 5, s->qscale); + } +} + void ff_mpeg1_encode_slice_header(MpegEncContext *s){ put_header(s, SLICE_MIN_START_CODE + s->mb_y); - put_bits(&s->pb, 5, s->qscale); /* quantizer scale */ + put_qscale(s); put_bits(&s->pb, 1, 0); /* slice extra information */ } @@ -567,7 +577,7 @@ if (s->pict_type == I_TYPE) { if(s->dquant && cbp){ put_mb_modes(s, 2, 1, 0, 0); /* macroblock_type : macroblock_quant = 1 */ - put_bits(&s->pb, 5, s->qscale); + put_qscale(s); }else{ put_mb_modes(s, 1, 1, 0, 0); /* macroblock_type : macroblock_quant = 0 */ s->qscale -= s->dquant; @@ -577,7 +587,7 @@ } else if (s->mb_intra) { if(s->dquant && cbp){ put_mb_modes(s, 6, 0x01, 0, 0); - put_bits(&s->pb, 5, s->qscale); + put_qscale(s); }else{ put_mb_modes(s, 5, 0x03, 0, 0); s->qscale -= s->dquant; @@ -591,7 +601,7 @@ if ((motion_x|motion_y) == 0) { if(s->dquant){ put_mb_modes(s, 5, 1, 0, 0); /* macroblock_pattern & quant */ - put_bits(&s->pb, 5, s->qscale); + put_qscale(s); }else{ put_mb_modes(s, 2, 1, 0, 0); /* macroblock_pattern only */ } @@ -599,7 +609,7 @@ } else { if(s->dquant){ put_mb_modes(s, 5, 2, 1, 0); /* motion + cbp */ - put_bits(&s->pb, 5, s->qscale); + put_qscale(s); }else{ put_mb_modes(s, 1, 1, 1, 0); /* motion + cbp */ } @@ -626,7 +636,7 @@ if (cbp) { if(s->dquant){ put_mb_modes(s, 5, 2, 1, 1); /* motion + cbp */ - put_bits(&s->pb, 5, s->qscale); + put_qscale(s); }else{ put_mb_modes(s, 1, 1, 1, 1); /* motion + cbp */ } @@ -664,7 +674,7 @@ put_mb_modes(s, 6, 3, 1, 0); else put_mb_modes(s, mb_type_len[s->mv_dir]+3, 2, 1, 0); - put_bits(&s->pb, 5, s->qscale); + put_qscale(s); } else { put_mb_modes(s, mb_type_len[s->mv_dir], 3, 1, 0); } @@ -698,7 +708,7 @@ put_mb_modes(s, 6, 3, 1, 1); else put_mb_modes(s, mb_type_len[s->mv_dir]+3, 2, 1, 1); - put_bits(&s->pb, 5, s->qscale); + put_qscale(s); } else { put_mb_modes(s, mb_type_len[s->mv_dir], 3, 1, 1); } diff -r f23c20cf7579 -r 5464e5021a67 mpeg12data.h --- a/mpeg12data.h Sat Mar 03 21:33:33 2007 +0000 +++ b/mpeg12data.h Sun Mar 04 02:26:20 2007 +0000 @@ -381,6 +381,11 @@ 56,64,72,80,88,96,104,112, }; +static const uint8_t inv_non_linear_qscale[13] = { + 0, 2, 4, 6, 8, + 9,10,11,12,13,14,15,16, +}; + const uint8_t ff_mpeg1_dc_scale_table[128]={ // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, diff -r f23c20cf7579 -r 5464e5021a67 mpegvideo.c --- a/mpegvideo.c Sat Mar 03 21:33:33 2007 +0000 +++ b/mpegvideo.c Sun Mar 04 02:26:20 2007 +0000 @@ -1015,6 +1015,7 @@ s->loop_filter= !!(s->flags & CODEC_FLAG_LOOP_FILTER); s->alternate_scan= !!(s->flags & CODEC_FLAG_ALT_SCAN); s->intra_vlc_format= !!(s->flags2 & CODEC_FLAG2_INTRA_VLC); + s->q_scale_type= !!(s->flags2 & CODEC_FLAG2_NON_LINEAR_QUANT); if(avctx->rc_max_rate && !avctx->rc_buffer_size){ av_log(avctx, AV_LOG_ERROR, "a vbv buffer size is needed, for encoding with a maximum bitrate\n"); @@ -1115,6 +1116,17 @@ } } + if(s->q_scale_type == 1){ + if(s->codec_id != CODEC_ID_MPEG2VIDEO){ + av_log(avctx, AV_LOG_ERROR, "non linear quant is only available for mpeg2\n"); + return -1; + } + if(avctx->qmax > 12){ + av_log(avctx, AV_LOG_ERROR, "non linear quant only supports qmax <= 12 currently\n"); + return -1; + } + } + if(s->avctx->thread_count > 1 && s->codec_id != CODEC_ID_MPEG4 && s->codec_id != CODEC_ID_MPEG1VIDEO && s->codec_id != CODEC_ID_MPEG2VIDEO && (s->codec_id != CODEC_ID_H263P || !(s->flags & CODEC_FLAG_H263P_SLICE_STRUCT))){ diff -r f23c20cf7579 -r 5464e5021a67 utils.c --- a/utils.c Sat Mar 03 21:33:33 2007 +0000 +++ b/utils.c Sun Mar 04 02:26:20 2007 +0000 @@ -718,6 +718,7 @@ {"max_partition_order", NULL, OFFSET(max_partition_order), FF_OPT_TYPE_INT, -1, INT_MIN, INT_MAX, A|E}, {"timecode_frame_start", "GOP timecode frame start number, in non drop frame format", OFFSET(timecode_frame_start), FF_OPT_TYPE_INT, 0, 0, INT_MAX, V|E}, {"drop_frame_timecode", NULL, 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_DROP_FRAME_TIMECODE, INT_MIN, INT_MAX, V|E, "flags2"}, +{"non_linear_q", "use non linear quantizer", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_NON_LINEAR_QUANT, INT_MIN, INT_MAX, V|E, "flags2"}, {NULL}, };