[FFmpeg-devel] [PATCH 1/2] vaapi_hevc: Add an option to set quality level

Zhong Li zhong.li at intel.com
Mon Aug 21 06:04:03 EEST 2017


Just like vaapi_h264 encoder, quality_level is set for tradeoff quality
and performance.

Signed-off-by: Zhong Li <zhong.li at intel.com>
---
 libavcodec/vaapi_encode_h265.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/libavcodec/vaapi_encode_h265.c b/libavcodec/vaapi_encode_h265.c
index cf6b9388d1..86bda4a27b 100644
--- a/libavcodec/vaapi_encode_h265.c
+++ b/libavcodec/vaapi_encode_h265.c
@@ -191,10 +191,19 @@ typedef struct VAAPIEncodeH265Context {
         VAEncMiscParameterBuffer misc;
         VAEncMiscParameterHRD hrd;
     } hrd_params;
+
+#if VA_CHECK_VERSION(0, 36, 0)
+    // Speed-quality tradeoff setting.
+    struct {
+        VAEncMiscParameterBuffer misc;
+        VAEncMiscParameterBufferQualityLevel quality;
+    } quality_params;
+#endif
 } VAAPIEncodeH265Context;
 
 typedef struct VAAPIEncodeH265Options {
     int qp;
+    int quality;
 } VAAPIEncodeH265Options;
 
 
@@ -1198,6 +1207,22 @@ static av_cold int vaapi_encode_h265_configure(AVCodecContext *avctx)
         av_assert0(0 && "Invalid RC mode.");
     }
 
+    if (opt->quality > 0) {
+#if VA_CHECK_VERSION(0, 36, 0)
+        priv->quality_params.misc.type =
+            VAEncMiscParameterTypeQualityLevel;
+        priv->quality_params.quality.quality_level = opt->quality;
+
+        ctx->global_params[ctx->nb_global_params] =
+            &priv->quality_params.misc;
+        ctx->global_params_size[ctx->nb_global_params++] =
+            sizeof(priv->quality_params);
+#else
+        av_log(avctx, AV_LOG_WARNING, "The encode quality option is not "
+               "supported with this VAAPI version.\n");
+#endif
+    }
+
     return 0;
 }
 
@@ -1272,6 +1297,8 @@ static av_cold int vaapi_encode_h265_init(AVCodecContext *avctx)
 static const AVOption vaapi_encode_h265_options[] = {
     { "qp", "Constant QP (for P-frames; scaled by qfactor/qoffset for I/B)",
       OFFSET(qp), AV_OPT_TYPE_INT, { .i64 = 25 }, 0, 52, FLAGS },
+    { "quality", "Set encode quality (trades off against speed, higher is faster)",
+      OFFSET(quality), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 7, FLAGS },
     { NULL },
 };
 
-- 
2.11.0



More information about the ffmpeg-devel mailing list