[FFmpeg-devel,v5] lavc/qsvenc: add BRC sliding window setting

Submitted by Zhong Li on March 17, 2019, 11:13 p.m.

Details

Message ID 20190317231313.7147-1-zhong.li@intel.com
State New
Headers show

Commit Message

Zhong Li March 17, 2019, 11:13 p.m.
WinBRCMaxAvgKbps is to specify maximum average bitrate over a
sliding window with size of WinBRCSize

WinBRCMaxAvgKbps will be ignored in CBR mode and equal to TargetKbps.

Signed-off-by: Zhong Li <zhong.li@intel.com>
---
 libavcodec/qsvenc.c | 12 ++++++++++++
 libavcodec/qsvenc.h |  5 +++++
 2 files changed, 17 insertions(+)

Comments

Hendrik Leppkes March 18, 2019, 9:31 a.m.
On Mon, Mar 18, 2019 at 7:29 AM Zhong Li <zhong.li@intel.com> wrote:
>
> WinBRCMaxAvgKbps is to specify maximum average bitrate over a
> sliding window with size of WinBRCSize
>
> WinBRCMaxAvgKbps will be ignored in CBR mode and equal to TargetKbps.
>

How are these modes different to ffmpeg rc_max_rate in conjunction
with rc_buffer_size, which are typically used for a VBV-like buffering
scheme in H264/5, which also seems to be a sliding window as I
understand it?

- Hendrik

Patch hide | download patch | download mbox

diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index 5aa020d47b..16d2aa887a 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -267,6 +267,11 @@  static void dump_video_param(AVCodecContext *avctx, QSVEncContext *q,
 #endif
 #endif
 
+#if QSV_HAVE_CO3
+    av_log(avctx, AV_LOG_VERBOSE,"WinBRCMaxAvgKbps: %"PRIu32"; WinBRCSize: %"PRId32"\n",
+           co3->WinBRCMaxAvgKbps, co3->WinBRCSize);
+#endif
+
     if (avctx->codec_id == AV_CODEC_ID_H264) {
         av_log(avctx, AV_LOG_VERBOSE, "Entropy coding: %s; MaxDecFrameBuffering: %"PRIu16"\n",
                co->CAVLC == MFX_CODINGOPTION_ON ? "CAVLC" : "CABAC", co->MaxDecFrameBuffering);
@@ -742,7 +747,14 @@  FF_ENABLE_DEPRECATION_WARNINGS
 #if QSV_HAVE_CO3
         q->extco3.Header.BufferId      = MFX_EXTBUFF_CODING_OPTION3;
         q->extco3.Header.BufferSz      = sizeof(q->extco3);
+        q->extco3.WinBRCMaxAvgKbps     = q->win_brc_max_avg_kbps;
+        q->extco3.WinBRCSize           = q->win_brc_size;
         q->extparam_internal[q->nb_extparam_internal++] = (mfxExtBuffer *)&q->extco3;
+#else
+        if (q->win_brc_max_avg_kbps || q->win_brc_size) {
+            av_log(avctx, AV_LOG_ERROR, "BRC sliding window setting is unsupported\n");
+            return AVERROR(ENOSYS);
+        }
 #endif
     }
 
diff --git a/libavcodec/qsvenc.h b/libavcodec/qsvenc.h
index 00afbd80aa..2c44cb836c 100644
--- a/libavcodec/qsvenc.h
+++ b/libavcodec/qsvenc.h
@@ -89,6 +89,8 @@ 
 { "adaptive_b",     "Adaptive B-frame placement",             OFFSET(qsv.adaptive_b),     AV_OPT_TYPE_INT, { .i64 = -1 }, -1,          1, VE },                         \
 { "b_strategy",     "Strategy to choose between I/P/B-frames", OFFSET(qsv.b_strategy),    AV_OPT_TYPE_INT, { .i64 = -1 }, -1,          1, VE },                         \
 { "forced_idr",     "Forcing I frames as IDR frames",         OFFSET(qsv.forced_idr),     AV_OPT_TYPE_BOOL,{ .i64 = 0  },  0,          1, VE },                         \
+{ "win_max_rate",   "maximum average bitrate (in kbps) over a sliding window", OFFSET(qsv.win_brc_max_avg_kbps), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, VE },       \
+{ "win_brc_size",   "sliding window size of win_max_rate",                     OFFSET(qsv.win_brc_size),         AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, VE },
 
 typedef int SetEncodeCtrlCB (AVCodecContext *avctx,
                              const AVFrame *frame, mfxEncodeCtrl* enc_ctrl);
@@ -169,6 +171,9 @@  typedef struct QSVEncContext {
     int repeat_pps;
     int low_power;
 
+    int win_brc_max_avg_kbps;
+    int win_brc_size;
+
     int a53_cc;
 
 #if QSV_HAVE_MF