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

Zhong Li zhong.li at intel.com
Mon Mar 18 01:13:13 EET 2019


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 at intel.com>
---
 libavcodec/qsvenc.c | 12 ++++++++++++
 libavcodec/qsvenc.h |  5 +++++
 2 files changed, 17 insertions(+)

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
-- 
2.17.1



More information about the ffmpeg-devel mailing list