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

Jun Zhao mypopydev at gmail.com
Fri May 12 09:27:45 EEST 2017


V2: - Refine the name/value type to mb_rate_control/bool.
    - Only supported GEN9+ (SKL/APL/KBL/...)
    - i965 driver default use frame-level rate control algorithm (generate the QP for each frame), 
      when enable mb_rate_control, it's will enable the MB-level RC algorithm (generate the QP for each MB). 
    - enables MB-level bitrate control that generally improves subjective visual quality, 
      but have negative impact on performance and objective visual quality metric. 
-------------- next part --------------
From 9223a87e48c846f1ab7c65ba857d902de70349a8 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 V2] 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 | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/libavcodec/vaapi_encode_h264.c b/libavcodec/vaapi_encode_h264.c
index 92e29554ed..6b97a7fd85 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 mb_rate_control;
 } VAAPIEncodeH264Options;
 
 
@@ -1133,8 +1134,11 @@ static av_cold int vaapi_encode_h264_configure(AVCodecContext *avctx)
         priv->fixed_qp_p   = 26;
         priv->fixed_qp_b   = 26;
 
-        av_log(avctx, AV_LOG_DEBUG, "Using %s-bitrate = %"PRId64" bps.\n",
+        ctx->rc_params.rc.rc_flags.bits.mb_rate_control = opt->mb_rate_control;
+
+        av_log(avctx, AV_LOG_DEBUG, "Using %s-bitrate %s MB rate control = %"PRId64" bps.\n",
                ctx->va_rc_mode == VA_RC_CBR ? "constant" : "variable",
+               opt->mb_rate_control ? "with" : "without",
                avctx->bit_rate);
 
     } else {
@@ -1283,6 +1287,8 @@ 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 },
+    { "mb_rate_control", "MB level bitrate control (only supported on GEN9+)",
+      OFFSET(mb_rate_control), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS, "mb_rate_control" },
     { NULL },
 };
 
-- 
2.11.0



More information about the ffmpeg-devel mailing list