diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index bd1a0e53cb..4b25cb1478 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -2132,14 +2132,16 @@ typedef struct AVCodecContext { */ int rc_min_rate; +#if FF_API_MPV_OPT + /** + * @deprecated use encoder private options instead + */ + attribute_deprecated float rc_buffer_aggressivity; - /** - * initial complexity for pass1 ratecontrol - * - encoding: Set by user. - * - decoding: unused - */ + attribute_deprecated float rc_initial_cplx; +#endif /** * Ratecontrol attempt to use, at maximum, of what can be used without an underflow. diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h index 1b72960e49..71a4b24182 100644 --- a/libavcodec/mpegvideo.h +++ b/libavcodec/mpegvideo.h @@ -637,6 +637,8 @@ typedef struct MpegEncContext { float rc_qsquish; float rc_qmod_amp; int rc_qmod_freq; + float rc_initial_cplx; + float rc_buffer_aggressivity; char *rc_eq; @@ -693,7 +695,9 @@ typedef struct MpegEncContext { "defined in the section 'Expression Evaluation', the following functions are available: " \ "bits2qp(bits), qp2bits(qp). Also the following constants are available: iTex pTex tex mv " \ "fCode iCount mcVar var isI isP isB avgQP qComp avgIITex avgPITex avgPPTex avgBPTex avgTex.", \ - FF_MPV_OFFSET(rc_eq), AV_OPT_TYPE_STRING, .flags = FF_MPV_OPT_FLAGS }, + FF_MPV_OFFSET(rc_eq), AV_OPT_TYPE_STRING, .flags = FF_MPV_OPT_FLAGS }, \ +{"rc_init_cplx", "initial complexity for 1-pass encoding", FF_MPV_OFFSET(rc_initial_cplx), AV_OPT_TYPE_FLOAT, {.dbl = 0 }, -FLT_MAX, FLT_MAX, FF_MPV_OPT_FLAGS}, \ +{"rc_buf_aggressivity", "currently useless", FF_MPV_OFFSET(rc_buffer_aggressivity), AV_OPT_TYPE_FLOAT, {.dbl = 1.0 }, -FLT_MAX, FLT_MAX, FF_MPV_OPT_FLAGS}, \ extern const AVOption ff_mpv_generic_options[]; diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index 2a25545869..3de3b096c6 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -830,6 +830,10 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx) s->rc_qmod_amp = avctx->rc_qmod_amp; if (avctx->rc_qmod_freq) s->rc_qmod_freq = avctx->rc_qmod_freq; + if (avctx->rc_buffer_aggressivity != 1.0) + s->rc_buffer_aggressivity = avctx->rc_buffer_aggressivity; + if (avctx->rc_initial_cplx != 0.0) + s->rc_initial_cplx = avctx->rc_initial_cplx; if (avctx->rc_eq) { av_freep(&s->rc_eq); diff --git a/libavcodec/options_table.h b/libavcodec/options_table.h index bf33f9ae8f..ce6a3ae05f 100644 --- a/libavcodec/options_table.h +++ b/libavcodec/options_table.h @@ -176,10 +176,14 @@ static const AVOption avcodec_options[] = { {"minrate", "Set minimum bitrate tolerance (in bits/s). Most useful in setting up a CBR encode. It is of little use otherwise.", OFFSET(rc_min_rate), AV_OPT_TYPE_INT, {.i64 = DEFAULT }, INT_MIN, INT_MAX, V|A|E}, {"bufsize", "set ratecontrol buffer size (in bits)", OFFSET(rc_buffer_size), AV_OPT_TYPE_INT, {.i64 = DEFAULT }, INT_MIN, INT_MAX, A|V|E}, -{"rc_buf_aggressivity", "currently useless", OFFSET(rc_buffer_aggressivity), AV_OPT_TYPE_FLOAT, {.dbl = 1.0 }, -FLT_MAX, FLT_MAX, V|E}, +#if FF_API_MPV_OPT +{"rc_buf_aggressivity", "deprecated, use encoder private options instead", OFFSET(rc_buffer_aggressivity), AV_OPT_TYPE_FLOAT, {.dbl = 1.0 }, -FLT_MAX, FLT_MAX, V|E}, +#endif {"i_qfactor", "QP factor between P- and I-frames", OFFSET(i_quant_factor), AV_OPT_TYPE_FLOAT, {.dbl = -0.8 }, -FLT_MAX, FLT_MAX, V|E}, {"i_qoffset", "QP offset between P- and I-frames", OFFSET(i_quant_offset), AV_OPT_TYPE_FLOAT, {.dbl = 0.0 }, -FLT_MAX, FLT_MAX, V|E}, -{"rc_init_cplx", "initial complexity for 1-pass encoding", OFFSET(rc_initial_cplx), AV_OPT_TYPE_FLOAT, {.dbl = DEFAULT }, -FLT_MAX, FLT_MAX, V|E}, +#if FF_API_MPV_OPT +{"rc_init_cplx", "deprecated, use encoder private options instead", OFFSET(rc_initial_cplx), AV_OPT_TYPE_FLOAT, {.dbl = DEFAULT }, -FLT_MAX, FLT_MAX, V|E}, +#endif {"dct", "DCT algorithm", OFFSET(dct_algo), AV_OPT_TYPE_INT, {.i64 = DEFAULT }, 0, INT_MAX, V|E, "dct"}, {"auto", "autoselect a good one (default)", 0, AV_OPT_TYPE_CONST, {.i64 = FF_DCT_AUTO }, INT_MIN, INT_MAX, V|E, "dct"}, {"fastint", "fast integer", 0, AV_OPT_TYPE_CONST, {.i64 = FF_DCT_FASTINT }, INT_MIN, INT_MAX, V|E, "dct"}, diff --git a/libavcodec/ratecontrol.c b/libavcodec/ratecontrol.c index 3aa3e27602..d89d6e4e82 100644 --- a/libavcodec/ratecontrol.c +++ b/libavcodec/ratecontrol.c @@ -236,9 +236,9 @@ av_cold int ff_rate_control_init(MpegEncContext *s) return -1; } /* init stuff with the user specified complexity */ - if (s->avctx->rc_initial_cplx) { + if (s->rc_initial_cplx) { for (i = 0; i < 60 * 30; i++) { - double bits = s->avctx->rc_initial_cplx * (i / 10000.0 + 1.0) * s->mb_num; + double bits = s->rc_initial_cplx * (i / 10000.0 + 1.0) * s->mb_num; RateControlEntry rce; if (i % ((s->gop_size + 3) / 4) == 0) @@ -516,7 +516,7 @@ static double modify_qscale(MpegEncContext *s, RateControlEntry *rce, d = 1.0; else if (d < 0.0001) d = 0.0001; - q *= pow(d, 1.0 / s->avctx->rc_buffer_aggressivity); + q *= pow(d, 1.0 / s->rc_buffer_aggressivity); q_limit = bits2qp(rce, FFMAX((min_rate - buffer_size + rcc->buffer_index) * @@ -536,7 +536,7 @@ static double modify_qscale(MpegEncContext *s, RateControlEntry *rce, d = 1.0; else if (d < 0.0001) d = 0.0001; - q /= pow(d, 1.0 / s->avctx->rc_buffer_aggressivity); + q /= pow(d, 1.0 / s->rc_buffer_aggressivity); q_limit = bits2qp(rce, FFMAX(rcc->buffer_index * @@ -552,7 +552,7 @@ static double modify_qscale(MpegEncContext *s, RateControlEntry *rce, } av_dlog(s, "q:%f max:%f min:%f size:%f index:%f agr:%f\n", q, max_rate, min_rate, buffer_size, rcc->buffer_index, - s->avctx->rc_buffer_aggressivity); + s->rc_buffer_aggressivity); if (s->rc_qsquish == 0.0 || qmin == qmax) { if (q < qmin) q = qmin;