[FFmpeg-devel] [PATCH 2/2] vaapi_encode: work-around VBR driver bug in Intel Broxton/CherryView

Aman Gupta ffmpeg at tmm1.net
Tue Aug 13 03:25:38 EEST 2019


From: Aman Gupta <aman at tmm1.net>

The hardware encoder on these chipsets produces very low bitrates
in VBR mode if it receives VAEncMiscParameterTypeRateControl more than once.

/cc intel/intel-vaapi-driver#480

Signed-off-by: Aman Gupta <aman at tmm1.net>
---
 libavcodec/vaapi_encode.c   |  8 +++++++-
 libavutil/hwcontext_vaapi.c | 10 ++++++++++
 libavutil/hwcontext_vaapi.h |  6 ++++++
 3 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
index 231efba6cc..a5f46cdee0 100644
--- a/libavcodec/vaapi_encode.c
+++ b/libavcodec/vaapi_encode.c
@@ -163,7 +163,7 @@ static int vaapi_encode_issue(AVCodecContext *avctx,
     VAAPIEncodeContext *ctx = avctx->priv_data;
     VAAPIEncodeSlice *slice;
     VAStatus vas;
-    int err, i;
+    int err, i, send_global_params;
     char data[MAX_PARAM_BUFFER_SIZE];
     size_t bit_len;
     av_unused AVFrameSideData *sd;
@@ -236,6 +236,12 @@ static int vaapi_encode_issue(AVCodecContext *avctx,
 
     if (pic->type == PICTURE_TYPE_IDR) {
         for (i = 0; i < ctx->nb_global_params; i++) {
+            if (pic->encode_order != 0 &&
+                ctx->global_params_type[i] == VAEncMiscParameterTypeRateControl &&
+                ctx->hwctx->driver_quirks & AV_VAAPI_DRIVER_QUIRK_RC_PARAMS_ONCE) {
+                // send VAEncMiscParameterTypeRateControl only once to affected drivers
+                continue;
+            }
             err = vaapi_encode_make_misc_param_buffer(avctx, pic,
                                                       ctx->global_params_type[i],
                                                       ctx->global_params[i],
diff --git a/libavutil/hwcontext_vaapi.c b/libavutil/hwcontext_vaapi.c
index cf117640f2..a206ce8880 100644
--- a/libavutil/hwcontext_vaapi.c
+++ b/libavutil/hwcontext_vaapi.c
@@ -323,6 +323,16 @@ static const struct {
         "Splitted-Desktop Systems VDPAU backend for VA-API",
         AV_VAAPI_DRIVER_QUIRK_SURFACE_ATTRIBUTES,
     },
+    {
+        "Intel Broxton",
+        "Intel(R) Broxton",
+        AV_VAAPI_DRIVER_QUIRK_RC_PARAMS_ONCE,
+    },
+    {
+        "Intel CherryView",
+        "Intel(R) CherryView",
+        AV_VAAPI_DRIVER_QUIRK_RC_PARAMS_ONCE,
+    },
 };
 
 static int vaapi_device_init(AVHWDeviceContext *hwdev)
diff --git a/libavutil/hwcontext_vaapi.h b/libavutil/hwcontext_vaapi.h
index 0b2e071cb3..ea4181fab0 100644
--- a/libavutil/hwcontext_vaapi.h
+++ b/libavutil/hwcontext_vaapi.h
@@ -58,6 +58,12 @@ enum {
      * and the results of the vaQuerySurfaceAttributes() call will be faked.
      */
     AV_VAAPI_DRIVER_QUIRK_SURFACE_ATTRIBUTES = (1 << 3),
+
+    /**
+     * The driver does not react well to receiving global parameters with
+     * every IDR frame.
+     */
+    AV_VAAPI_DRIVER_QUIRK_RC_PARAMS_ONCE = (1 << 4),
 };
 
 /**
-- 
2.20.1



More information about the ffmpeg-devel mailing list