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

Submitted by Jun Zhao on May 12, 2017, 6:27 a.m.

Details

Message ID 264d9cfe-cb0d-838a-d990-f4025a85b797@gmail.com
State New
Headers show

Commit Message

Jun Zhao May 12, 2017, 6:27 a.m.
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.
From 9223a87e48c846f1ab7c65ba857d902de70349a8 Mon Sep 17 00:00:00 2001
From: Jun Zhao <jun.zhao@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@intel.com>
---
 libavcodec/vaapi_encode_h264.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

Comments

Michael Niedermayer May 12, 2017, 8:05 p.m.
On Fri, May 12, 2017 at 02:27:45PM +0800, Jun Zhao wrote:
> 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. 

>  vaapi_encode_h264.c |    8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> c835733e8022f49f94585253793fb6712509d1cb  0001-lavc-vaapi_encode_h264-Enable-MB-rate-control.patch
> From 9223a87e48c846f1ab7c65ba857d902de70349a8 Mon Sep 17 00:00:00 2001
> From: Jun Zhao <jun.zhao@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@intel.com>
> ---
>  libavcodec/vaapi_encode_h264.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)

Fails to build
libavcodec/vaapi_encode_h264.c: In function ‘vaapi_encode_h264_configure’:
libavcodec/vaapi_encode_h264.c:1137:40: error: ‘struct <anonymous>’ has no member named ‘mb_rate_control’
         ctx->rc_params.rc.rc_flags.bits.mb_rate_control = opt->mb_rate_control;
                                        ^
make: *** [libavcodec/vaapi_encode_h264.o] Error 1

[...]

Patch hide | download patch | download mbox

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 },
 };