The private qp option continues to exist for compatibility.
---
 libavcodec/vaapi_encode_h264.c | 17 +++++++++++++----
 libavcodec/vaapi_encode_h265.c | 20 +++++++++++++++-----
 2 files changed, 28 insertions(+), 9 deletions(-)

diff --git a/libavcodec/vaapi_encode_h264.c b/libavcodec/vaapi_encode_h264.c
index deb99a7d2..326752579 100644
--- a/libavcodec/vaapi_encode_h264.c
+++ b/libavcodec/vaapi_encode_h264.c
@@ -1108,7 +1108,7 @@ static av_cold int 
vaapi_encode_h264_configure(AVCodecContext *avctx)
     priv->mb_height = FFALIGN(avctx->height, 16) / 16;
 
     if (ctx->va_rc_mode == VA_RC_CQP) {
-        priv->fixed_qp_p = opt->qp;
+        priv->fixed_qp_p = avctx->global_quality;
         if (avctx->i_quant_factor > 0.0)
             priv->fixed_qp_idr = (int)((priv->fixed_qp_p * 
avctx->i_quant_factor +
                                         avctx->i_quant_offset) + 0.5);
@@ -1239,10 +1239,19 @@ static av_cold int 
vaapi_encode_h264_init(AVCodecContext *avctx)
     // Only 8-bit encode is supported.
     ctx->va_rt_format = VA_RT_FORMAT_YUV420;
 
-    if (avctx->bit_rate > 0)
+    if (opt->qp >= 0) {
+        avctx->flags |= AV_CODEC_FLAG_QSCALE;
+        avctx->global_quality = opt->qp;
+    }
+
+    if (avctx->flags & AV_CODEC_FLAG_QSCALE) {
+        ctx->va_rc_mode = VA_RC_CQP;
+    } else if (avctx->bit_rate > 0) {
         ctx->va_rc_mode = VA_RC_CBR;
-    else
+    } else {
         ctx->va_rc_mode = VA_RC_CQP;
+        avctx->global_quality = 20;
+    }
 
     ctx->va_packed_headers =
         VA_ENC_PACKED_HEADER_SEQUENCE | // SPS and PPS.
@@ -1260,7 +1269,7 @@ static av_cold int vaapi_encode_h264_init(AVCodecContext 
*avctx)
 #define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
 static const AVOption vaapi_encode_h264_options[] = {
     { "qp", "Constant QP (for P-frames; scaled by qfactor/qoffset for I/B)",
-      OFFSET(qp), AV_OPT_TYPE_INT, { .i64 = 20 }, 0, 52, FLAGS },
+      OFFSET(qp), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 52, FLAGS },
     { "quality", "Set encode quality (trades off against speed, higher is 
faster)",
       OFFSET(quality), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 8, FLAGS },
     { "low_power", "Use low-power encoding mode (experimental: only supported "
diff --git a/libavcodec/vaapi_encode_h265.c b/libavcodec/vaapi_encode_h265.c
index e9133b431..b2c944262 100644
--- a/libavcodec/vaapi_encode_h265.c
+++ b/libavcodec/vaapi_encode_h265.c
@@ -1160,7 +1160,6 @@ static av_cold int 
vaapi_encode_h265_configure(AVCodecContext *avctx)
 {
     VAAPIEncodeContext      *ctx = avctx->priv_data;
     VAAPIEncodeH265Context *priv = ctx->priv_data;
-    VAAPIEncodeH265Options  *opt = ctx->codec_options;
 
     priv->ctu_width     = FFALIGN(ctx->surface_width,  32) / 32;
     priv->ctu_height    = FFALIGN(ctx->surface_height, 32) / 32;
@@ -1170,7 +1169,7 @@ static av_cold int 
vaapi_encode_h265_configure(AVCodecContext *avctx)
            ctx->surface_height, priv->ctu_width, priv->ctu_height);
 
     if (ctx->va_rc_mode == VA_RC_CQP) {
-        priv->fixed_qp_p = opt->qp;
+        priv->fixed_qp_p = avctx->global_quality;
         if (avctx->i_quant_factor > 0.0)
             priv->fixed_qp_idr = (int)((priv->fixed_qp_p * 
avctx->i_quant_factor +
                                         avctx->i_quant_offset) + 0.5);
@@ -1226,6 +1225,8 @@ static const VAAPIEncodeType vaapi_encode_type_h265 = {
 static av_cold int vaapi_encode_h265_init(AVCodecContext *avctx)
 {
     VAAPIEncodeContext *ctx = avctx->priv_data;
+    VAAPIEncodeH265Options *opt =
+        (VAAPIEncodeH265Options*)ctx->codec_options_data;
 
     ctx->codec = &vaapi_encode_type_h265;
 
@@ -1252,10 +1253,19 @@ static av_cold int 
vaapi_encode_h265_init(AVCodecContext *avctx)
     }
     ctx->va_entrypoint = VAEntrypointEncSlice;
 
-    if (avctx->bit_rate > 0)
+    if (opt->qp >= 0) {
+        avctx->flags |= AV_CODEC_FLAG_QSCALE;
+        avctx->global_quality = opt->qp;
+    }
+
+    if (avctx->flags & AV_CODEC_FLAG_QSCALE) {
+        ctx->va_rc_mode = VA_RC_CQP;
+    } else if (avctx->bit_rate > 0) {
         ctx->va_rc_mode = VA_RC_CBR;
-    else
+    } else {
         ctx->va_rc_mode = VA_RC_CQP;
+        avctx->global_quality = 25;
+    }
 
     ctx->va_packed_headers =
         VA_ENC_PACKED_HEADER_SEQUENCE | // VPS, SPS and PPS.
@@ -1272,7 +1282,7 @@ static av_cold int vaapi_encode_h265_init(AVCodecContext 
*avctx)
 #define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
 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 },
+      OFFSET(qp), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 52, FLAGS },
     { NULL },
 };
 
-- 
2.11.0
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to