From 25a42948c63e347391c98f3e95524244e7e7f628 Mon Sep 17 00:00:00 2001 From: Erik Slagter Date: Tue, 8 Dec 2009 20:01:46 +0000 Subject: [PATCH] Add MBtree support for libx264 Patch by Erik Slagter Originally committed as revision 20774 to svn://svn.ffmpeg.org/ffmpeg/trunk --- ffpresets/libx264-baseline.ffpreset | 2 +- ffpresets/libx264-default.ffpreset | 2 +- ffpresets/libx264-fastfirstpass.ffpreset | 2 +- ffpresets/libx264-hq.ffpreset | 2 +- ffpresets/libx264-ipod320.ffpreset | 2 +- ffpresets/libx264-ipod640.ffpreset | 2 +- ffpresets/libx264-lossless_fast.ffpreset | 2 +- ffpresets/libx264-lossless_max.ffpreset | 2 +- ffpresets/libx264-lossless_medium.ffpreset | 2 +- ffpresets/libx264-lossless_slow.ffpreset | 2 +- ffpresets/libx264-lossless_slower.ffpreset | 2 +- ffpresets/libx264-lossless_ultrafast.ffpreset | 2 +- ffpresets/libx264-main.ffpreset | 2 +- ffpresets/libx264-max.ffpreset | 2 +- ffpresets/libx264-normal.ffpreset | 2 +- ffpresets/libx264-slowfirstpass.ffpreset | 2 +- libavcodec/avcodec.h | 1 + libavcodec/libx264.c | 1 + libavcodec/options.c | 1 + 19 files changed, 19 insertions(+), 16 deletions(-) diff --git a/ffpresets/libx264-baseline.ffpreset b/ffpresets/libx264-baseline.ffpreset index ee7654bdec..a23b746ded 100644 --- a/ffpresets/libx264-baseline.ffpreset +++ b/ffpresets/libx264-baseline.ffpreset @@ -1,4 +1,4 @@ coder=0 bf=0 -flags2=-wpred-dct8x8 +flags2=-wpred-dct8x8+mbtree wpredp=0 diff --git a/ffpresets/libx264-default.ffpreset b/ffpresets/libx264-default.ffpreset index 75191e21b3..a10c633240 100644 --- a/ffpresets/libx264-default.ffpreset +++ b/ffpresets/libx264-default.ffpreset @@ -18,5 +18,5 @@ bf=3 refs=3 directpred=1 trellis=1 -flags2=+mixed_refs+wpred+dct8x8+fastpskip +flags2=+mixed_refs+wpred+dct8x8+fastpskip+mbtree wpredp=2 diff --git a/ffpresets/libx264-fastfirstpass.ffpreset b/ffpresets/libx264-fastfirstpass.ffpreset index 7278f771e1..7cf6faae41 100644 --- a/ffpresets/libx264-fastfirstpass.ffpreset +++ b/ffpresets/libx264-fastfirstpass.ffpreset @@ -18,5 +18,5 @@ bf=3 refs=1 directpred=3 trellis=0 -flags2=-bpyramid-wpred-mixed_refs-dct8x8+fastpskip +flags2=-bpyramid-wpred-mixed_refs-dct8x8+fastpskip+mbtree wpredp=2 diff --git a/ffpresets/libx264-hq.ffpreset b/ffpresets/libx264-hq.ffpreset index 9c14d8f554..eafc52e410 100644 --- a/ffpresets/libx264-hq.ffpreset +++ b/ffpresets/libx264-hq.ffpreset @@ -18,5 +18,5 @@ bf=3 refs=4 directpred=3 trellis=1 -flags2=+wpred+mixed_refs+dct8x8+fastpskip +flags2=+wpred+mixed_refs+dct8x8+fastpskip+mbtree wpredp=2 diff --git a/ffpresets/libx264-ipod320.ffpreset b/ffpresets/libx264-ipod320.ffpreset index 943b521348..b10205025e 100644 --- a/ffpresets/libx264-ipod320.ffpreset +++ b/ffpresets/libx264-ipod320.ffpreset @@ -1,6 +1,6 @@ coder=0 bf=0 -flags2=-wpred-dct8x8 +flags2=-wpred-dct8x8+mbtree level=13 maxrate=768000 bufsize=3000000 diff --git a/ffpresets/libx264-ipod640.ffpreset b/ffpresets/libx264-ipod640.ffpreset index 1ed3d9fb28..aa731dccc5 100644 --- a/ffpresets/libx264-ipod640.ffpreset +++ b/ffpresets/libx264-ipod640.ffpreset @@ -1,7 +1,7 @@ coder=0 bf=0 refs=1 -flags2=-wpred-dct8x8 +flags2=-wpred-dct8x8+mbtree level=30 maxrate=10000000 bufsize=10000000 diff --git a/ffpresets/libx264-lossless_fast.ffpreset b/ffpresets/libx264-lossless_fast.ffpreset index ea08d3c00b..9bbabf5f7c 100644 --- a/ffpresets/libx264-lossless_fast.ffpreset +++ b/ffpresets/libx264-lossless_fast.ffpreset @@ -15,6 +15,6 @@ qmin=10 qmax=51 qdiff=4 directpred=1 -flags2=+fastpskip +flags2=+fastpskip+mbtree cqp=0 wpredp=0 diff --git a/ffpresets/libx264-lossless_max.ffpreset b/ffpresets/libx264-lossless_max.ffpreset index 8c049c9c93..d4ba018b75 100644 --- a/ffpresets/libx264-lossless_max.ffpreset +++ b/ffpresets/libx264-lossless_max.ffpreset @@ -16,6 +16,6 @@ qmax=51 qdiff=4 refs=16 directpred=1 -flags2=+mixed_refs+dct8x8+fastpskip +flags2=+mixed_refs+dct8x8+fastpskip+mbtree cqp=0 wpredp=2 diff --git a/ffpresets/libx264-lossless_medium.ffpreset b/ffpresets/libx264-lossless_medium.ffpreset index 558be6c931..c4133c2279 100644 --- a/ffpresets/libx264-lossless_medium.ffpreset +++ b/ffpresets/libx264-lossless_medium.ffpreset @@ -15,6 +15,6 @@ qmin=10 qmax=51 qdiff=4 directpred=1 -flags2=+fastpskip +flags2=+fastpskip+mbtree cqp=0 wpredp=2 diff --git a/ffpresets/libx264-lossless_slow.ffpreset b/ffpresets/libx264-lossless_slow.ffpreset index ff641cf40f..1421b95603 100644 --- a/ffpresets/libx264-lossless_slow.ffpreset +++ b/ffpresets/libx264-lossless_slow.ffpreset @@ -16,6 +16,6 @@ qmax=51 qdiff=4 refs=2 directpred=1 -flags2=+dct8x8+fastpskip +flags2=+dct8x8+fastpskip+mbtree cqp=0 wpredp=2 diff --git a/ffpresets/libx264-lossless_slower.ffpreset b/ffpresets/libx264-lossless_slower.ffpreset index 854f74b236..942445921e 100644 --- a/ffpresets/libx264-lossless_slower.ffpreset +++ b/ffpresets/libx264-lossless_slower.ffpreset @@ -16,6 +16,6 @@ qmax=51 qdiff=4 refs=4 directpred=1 -flags2=+mixed_refs+dct8x8+fastpskip +flags2=+mixed_refs+dct8x8+fastpskip+mbtree cqp=0 wpredp=2 diff --git a/ffpresets/libx264-lossless_ultrafast.ffpreset b/ffpresets/libx264-lossless_ultrafast.ffpreset index 1c429f21ff..3c44488e8d 100644 --- a/ffpresets/libx264-lossless_ultrafast.ffpreset +++ b/ffpresets/libx264-lossless_ultrafast.ffpreset @@ -15,5 +15,5 @@ qmin=10 qmax=51 qdiff=4 directpred=1 -flags2=+fastpskip +flags2=+fastpskip+mbtree cqp=0 diff --git a/ffpresets/libx264-main.ffpreset b/ffpresets/libx264-main.ffpreset index d1dc7ddae9..0868c53cff 100644 --- a/ffpresets/libx264-main.ffpreset +++ b/ffpresets/libx264-main.ffpreset @@ -1 +1 @@ -flags2=-dct8x8 +flags2=-dct8x8+mbtree diff --git a/ffpresets/libx264-max.ffpreset b/ffpresets/libx264-max.ffpreset index 667ba85fef..4289ab531e 100644 --- a/ffpresets/libx264-max.ffpreset +++ b/ffpresets/libx264-max.ffpreset @@ -18,5 +18,5 @@ bf=3 refs=16 directpred=3 trellis=2 -flags2=+wpred+mixed_refs+dct8x8-fastpskip +flags2=+wpred+mixed_refs+dct8x8-fastpskip+mbtree wpredp=2 diff --git a/ffpresets/libx264-normal.ffpreset b/ffpresets/libx264-normal.ffpreset index ee790b6434..dd7991bab4 100644 --- a/ffpresets/libx264-normal.ffpreset +++ b/ffpresets/libx264-normal.ffpreset @@ -18,5 +18,5 @@ bf=3 refs=2 directpred=3 trellis=0 -flags2=+wpred+dct8x8+fastpskip +flags2=+wpred+dct8x8+fastpskip+mbtree wpredp=2 diff --git a/ffpresets/libx264-slowfirstpass.ffpreset b/ffpresets/libx264-slowfirstpass.ffpreset index fe073310de..ba49065c14 100644 --- a/ffpresets/libx264-slowfirstpass.ffpreset +++ b/ffpresets/libx264-slowfirstpass.ffpreset @@ -18,5 +18,5 @@ bf=3 refs=1 directpred=3 trellis=0 -flags2=+wpred+dct8x8+fastpskip +flags2=+wpred+dct8x8+fastpskip+mbtree wpredp=2 diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index f4fe7d676a..90f29963da 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -580,6 +580,7 @@ typedef struct RcOverride{ #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 nonlinear quantizer. #define CODEC_FLAG2_BIT_RESERVOIR 0x00020000 ///< Use a bit reservoir when encoding if possible +#define CODEC_FLAG2_MBTREE 0x00040000 ///< Use macroblock tree ratecontrol (x264 only) /* Unsupported options : * Syntax Arithmetic coding (SAC) diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c index 05c29805db..1fec3eded1 100644 --- a/libavcodec/libx264.c +++ b/libavcodec/libx264.c @@ -266,6 +266,7 @@ static av_cold int X264_init(AVCodecContext *avctx) } else x4->params.rc.f_vbv_buffer_init = 0.9; + x4->params.rc.b_mb_tree = !!(avctx->flags2 & CODEC_FLAG2_MBTREE); x4->params.rc.f_ip_factor = 1 / fabs(avctx->i_quant_factor); x4->params.rc.f_pb_factor = avctx->b_quant_factor; x4->params.analyse.i_chroma_qp_offset = avctx->chromaoffset; diff --git a/libavcodec/options.c b/libavcodec/options.c index fa64294a0d..d224c41618 100644 --- a/libavcodec/options.c +++ b/libavcodec/options.c @@ -391,6 +391,7 @@ static const AVOption options[]={ {"request_channels", "set desired number of audio channels", OFFSET(request_channels), FF_OPT_TYPE_INT, DEFAULT, 0, INT_MAX, A|D}, {"drc_scale", "percentage of dynamic range compression to apply", OFFSET(drc_scale), FF_OPT_TYPE_FLOAT, 1.0, 0.0, 1.0, A|D}, {"reservoir", "use bit reservoir", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_BIT_RESERVOIR, INT_MIN, INT_MAX, A|E, "flags2"}, +{"mbtree", "use macroblock tree ratecontrol (x264 only)", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_MBTREE, INT_MIN, INT_MAX, V|E, "flags2"}, {"bits_per_raw_sample", NULL, OFFSET(bits_per_raw_sample), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX}, {"channel_layout", NULL, OFFSET(channel_layout), FF_OPT_TYPE_INT64, DEFAULT, 0, INT64_MAX, A|E|D, "channel_layout"}, {"request_channel_layout", NULL, OFFSET(request_channel_layout), FF_OPT_TYPE_INT64, DEFAULT, 0, INT64_MAX, A|D, "request_channel_layout"},