[FFmpeg-cvslog] lavc: make rc_buffer_aggressivity/ rc_initial_cplx into private options of mpegvideo encoders

Anton Khirnov git at videolan.org
Sat Oct 18 14:28:09 CEST 2014


ffmpeg | branch: master | Anton Khirnov <anton at khirnov.net> | Sun Oct 27 13:51:16 2013 +0100| [66a68ddd1ac376b24db8695058bc8fc28f5bada6] | committer: Anton Khirnov

lavc: make rc_buffer_aggressivity/rc_initial_cplx into private options of mpegvideo encoders

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=66a68ddd1ac376b24db8695058bc8fc28f5bada6
---

 libavcodec/avcodec.h       |   12 +++++++-----
 libavcodec/mpegvideo.h     |    6 +++++-
 libavcodec/mpegvideo_enc.c |    4 ++++
 libavcodec/options_table.h |    8 ++++++--
 libavcodec/ratecontrol.c   |   10 +++++-----
 5 files changed, 27 insertions(+), 13 deletions(-)

diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index bd1a0e5..4b25cb1 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -2132,14 +2132,16 @@ typedef struct AVCodecContext {
      */
     int rc_min_rate;
 
-    float rc_buffer_aggressivity;
-
+#if FF_API_MPV_OPT
     /**
-     * initial complexity for pass1 ratecontrol
-     * - encoding: Set by user.
-     * - decoding: unused
+     * @deprecated use encoder private options instead
      */
+    attribute_deprecated
+    float rc_buffer_aggressivity;
+
+    attribute_deprecated
     float rc_initial_cplx;
+#endif
 
     /**
      * Ratecontrol attempt to use, at maximum, <value> of what can be used without an underflow.
diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
index 1b72960..71a4b24 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 2a25545..3de3b09 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 bf33f9a..ce6a3ae 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 3aa3e27..d89d6e4 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;



More information about the ffmpeg-cvslog mailing list