diff mbox series

[FFmpeg-devel,v6,3/5] lavc/libopenh264enc: add bit rate control select support

Message ID 1588129250-30726-3-git-send-email-linjie.fu@intel.com
State Accepted
Commit 75fc3f97b0073d0ff57b4bd1e5ce8b36a5f9ac14
Headers show
Series [FFmpeg-devel,v6,1/5] lavc/libopenh264enc: Add qmin/qmax support
Related show

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

Fu, Linjie April 29, 2020, 3 a.m. UTC
RC_BITRATE_MODE:
    set BITS_EXCEEDED to iCurrentBitsLevel and allows QP adjust
    in RcCalculatePictureQp().

RC_BUFFERBASED_MODE:
    use buffer status to adjust the video quality.

RC_TIMESTAMP_MODE:
    bit rate control based on timestamp, introduced in release 1.4.

Default to use RC_QUALITY_MODE.

Signed-off-by: Linjie Fu <linjie.fu@intel.com>
---
 libavcodec/libopenh264enc.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

Comments

Martin Storsjö April 29, 2020, 8:52 a.m. UTC | #1
On Wed, 29 Apr 2020, Linjie Fu wrote:

> RC_BITRATE_MODE:
>    set BITS_EXCEEDED to iCurrentBitsLevel and allows QP adjust
>    in RcCalculatePictureQp().
>
> RC_BUFFERBASED_MODE:
>    use buffer status to adjust the video quality.
>
> RC_TIMESTAMP_MODE:
>    bit rate control based on timestamp, introduced in release 1.4.
>
> Default to use RC_QUALITY_MODE.
>
> Signed-off-by: Linjie Fu <linjie.fu@intel.com>
> ---
> libavcodec/libopenh264enc.c | 15 ++++++++++++++-
> 1 file changed, 14 insertions(+), 1 deletion(-)

LGTM

// Martin
diff mbox series

Patch

diff --git a/libavcodec/libopenh264enc.c b/libavcodec/libopenh264enc.c
index 245752d..dc3bd53 100644
--- a/libavcodec/libopenh264enc.c
+++ b/libavcodec/libopenh264enc.c
@@ -49,6 +49,9 @@  typedef struct SVCContext {
     int skip_frames;
     int skipped;
     int cabac;
+
+    // rate control mode
+    int rc_mode;
 } SVCContext;
 
 #define OFFSET(x) offsetof(SVCContext, x)
@@ -73,6 +76,16 @@  static const AVOption options[] = {
     { "max_nal_size", "set maximum NAL size in bytes", OFFSET(max_nal_size), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, VE },
     { "allow_skip_frames", "allow skipping frames to hit the target bitrate", OFFSET(skip_frames), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
     { "cabac", "Enable cabac", OFFSET(cabac), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE },
+
+    { "rc_mode", "Select rate control mode", OFFSET(rc_mode), AV_OPT_TYPE_INT, { .i64 = RC_QUALITY_MODE }, RC_OFF_MODE, RC_TIMESTAMP_MODE, VE, "rc_mode" },
+        { "off",       "bit rate control off",                                                 0, AV_OPT_TYPE_CONST, { .i64 = RC_OFF_MODE },         0, 0, VE, "rc_mode" },
+        { "quality",   "quality mode",                                                         0, AV_OPT_TYPE_CONST, { .i64 = RC_QUALITY_MODE },     0, 0, VE, "rc_mode" },
+        { "bitrate",   "bitrate mode",                                                         0, AV_OPT_TYPE_CONST, { .i64 = RC_BITRATE_MODE },     0, 0, VE, "rc_mode" },
+        { "buffer",    "using buffer status to adjust the video quality (no bitrate control)", 0, AV_OPT_TYPE_CONST, { .i64 = RC_BUFFERBASED_MODE }, 0, 0, VE, "rc_mode" },
+#if OPENH264_VER_AT_LEAST(1, 4)
+        { "timestamp", "bit rate control based on timestamp",                                  0, AV_OPT_TYPE_CONST, { .i64 = RC_TIMESTAMP_MODE },   0, 0, VE, "rc_mode" },
+#endif
+
     { NULL }
 };
 
@@ -136,7 +149,7 @@  FF_ENABLE_DEPRECATION_WARNINGS
     param.iPicHeight                 = avctx->height;
     param.iTargetBitrate             = avctx->bit_rate > 0 ? avctx->bit_rate : TARGET_BITRATE_DEFAULT;
     param.iMaxBitrate                = FFMAX(avctx->rc_max_rate, avctx->bit_rate);
-    param.iRCMode                    = RC_QUALITY_MODE;
+    param.iRCMode                    = s->rc_mode;
     if (avctx->qmax >= 0)
         param.iMaxQp                 = av_clip(avctx->qmax, 1, 51);
     if (avctx->qmin >= 0)