[FFmpeg-devel] [PATCH] lavc/vaapi_encode_h264: Enable MB rate control

Jun Zhao mypopydev at gmail.com
Thu May 11 03:29:38 EEST 2017


Enable the MB level rate control, verified in i965 driver master branch with Skylake. 
-------------- next part --------------
From b32e4c9c1de47b3bf76327b0ecd11ccf9e3c693f Mon Sep 17 00:00:00 2001
From: Jun Zhao <jun.zhao at intel.com>
Date: Tue, 9 May 2017 08:19:16 +0800
Subject: [PATCH] lavc/vaapi_encode_h264: Enable MB rate control.

Enables macroblock-level bitrate control that generally improves
subjective visual quality. It may have a negative impact on
performance and objective visual quality metrics. Default is off
and can't compatible with Constant QP.

Signed-off-by: Jun Zhao <jun.zhao at intel.com>
---
 libavcodec/vaapi_encode_h264.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/libavcodec/vaapi_encode_h264.c b/libavcodec/vaapi_encode_h264.c
index 92e29554ed..130a9302eb 100644
--- a/libavcodec/vaapi_encode_h264.c
+++ b/libavcodec/vaapi_encode_h264.c
@@ -168,6 +168,7 @@ typedef struct VAAPIEncodeH264Options {
     int qp;
     int quality;
     int low_power;
+    int mbbrc;
 } VAAPIEncodeH264Options;
 
 
@@ -1157,6 +1158,12 @@ static av_cold int vaapi_encode_h264_configure(AVCodecContext *avctx)
 #endif
     }
 
+    if (ctx->va_rc_mode == VA_RC_CQP && opt->mbbrc != 0)
+        av_log(avctx, AV_LOG_WARNING, "The MB level bitrate control is not "
+               "compatible with Constant QP, it's will ignored it.\n");
+    else
+        ctx->rc_params.rc.rc_flags.bits.mb_rate_control = opt->mbbrc;
+
     return 0;
 }
 
@@ -1283,6 +1290,10 @@ static const AVOption vaapi_encode_h264_options[] = {
     { "low_power", "Use low-power encoding mode (experimental: only supported "
       "on some platforms, does not support all features)",
       OFFSET(low_power), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, FLAGS },
+    { "mbbrc", "MB level bitrate control",
+      OFFSET(mbbrc), AV_OPT_TYPE_FLAGS, { .i64 = 0 }, 0, 1, FLAGS, "mbbrc" },
+        { "off", NULL, 0,  AV_OPT_TYPE_CONST, { .i64 = 0 }, 0, 0, FLAGS, "mbbrc"},
+        { "on", NULL, 0,  AV_OPT_TYPE_CONST, { .i64 = 1 }, 0, 0, FLAGS, "mbbrc"},
     { NULL },
 };
 
-- 
2.11.0



More information about the ffmpeg-devel mailing list