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

Submitted by Zhong Li on Nov. 29, 2018, 8:29 a.m.

Details

Message ID 1543480147-4359-10-git-send-email-zhong.li@intel.com
State New
Headers show

Commit Message

Zhong Li Nov. 29, 2018, 8:29 a.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      | 7 +++++++
 libavcodec/qsvenc.h      | 3 +++
 libavcodec/qsvenc_h264.c | 5 +++++
 3 files changed, 15 insertions(+)

Patch hide | download patch | download mbox

diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index 2dd41d7..9c2f2a7 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -263,6 +263,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);
@@ -723,6 +728,8 @@  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;
 #endif
     }
diff --git a/libavcodec/qsvenc.h b/libavcodec/qsvenc.h
index 075c86b..1f9769e 100644
--- a/libavcodec/qsvenc.h
+++ b/libavcodec/qsvenc.h
@@ -168,6 +168,9 @@  typedef struct QSVEncContext {
     int repeat_pps;
     int num_mb_per_slice;
 
+    int win_brc_max_avg_kbps;
+    int win_brc_size;
+
     int a53_cc;
 
 #if QSV_HAVE_MF
diff --git a/libavcodec/qsvenc_h264.c b/libavcodec/qsvenc_h264.c
index 693a9e3..d943ede 100644
--- a/libavcodec/qsvenc_h264.c
+++ b/libavcodec/qsvenc_h264.c
@@ -158,6 +158,11 @@  static const AVOption options[] = {
     { "repeat_pps", "repeat pps for every frame", OFFSET(qsv.repeat_pps), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
     { "num_mb_per_slice","Suggested macroblocks numbers of each slice", OFFSET(qsv.num_mb_per_slice), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, VE },
 
+#if QSV_HAVE_CO3
+    { "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 },
+#endif
+
     { NULL },
 };