---
 libavcodec/vaapi_encode.h      |  1 +
 libavcodec/vaapi_encode_h264.c | 21 ++++++++++++++++++---
 libavcodec/vaapi_encode_h265.c | 21 ++++++++++++++++++---
 3 files changed, 37 insertions(+), 6 deletions(-)

diff --git a/libavcodec/vaapi_encode.h b/libavcodec/vaapi_encode.h
index 9716578..163ed03 100644
--- a/libavcodec/vaapi_encode.h
+++ b/libavcodec/vaapi_encode.h
@@ -172,6 +172,7 @@ typedef struct VAAPIEncodeContext {
     int p_counter;
     int end_of_stream;

+    char codec_options[0];
 } VAAPIEncodeContext;


diff --git a/libavcodec/vaapi_encode_h264.c b/libavcodec/vaapi_encode_h264.c
index a00d478..5ab43cf 100644
--- a/libavcodec/vaapi_encode_h264.c
+++ b/libavcodec/vaapi_encode_h264.c
@@ -115,6 +115,10 @@ typedef struct VAAPIEncodeH264Context {
     } hrd_params;
 } VAAPIEncodeH264Context;

+typedef struct VAAPIEncodeH264Options {
+    int qp;
+} VAAPIEncodeH264Options;
+

 #define vseq_var(name)     vseq->name, name
 #define vseq_field(name)   vseq->seq_fields.bits.name, name
@@ -718,6 +722,7 @@ static av_cold int 
vaapi_encode_h264_init_internal(AVCodecContext *avctx)

     VAAPIEncodeContext      *ctx = avctx->priv_data;
     VAAPIEncodeH264Context *priv = ctx->priv_data;
+    VAAPIEncodeH264Options  *opt = (VAAPIEncodeH264Options*)ctx->codec_options;
     int i;

     switch (avctx->profile) {
@@ -809,7 +814,7 @@ static av_cold int 
vaapi_encode_h264_init_internal(AVCodecContext *avctx)
     } else {
         ctx->va_rc_mode = VA_RC_CQP;

-        priv->fixed_qp_p = avctx->global_quality;
+        priv->fixed_qp_p = opt->qp;
         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);
@@ -861,13 +866,21 @@ static av_cold int vaapi_encode_h264_init(AVCodecContext 
*avctx)
     return ff_vaapi_encode_init(avctx, &vaapi_encode_type_h264);
 }

+#define OFFSET(x) (offsetof(VAAPIEncodeContext, codec_options) + \
+                   offsetof(VAAPIEncodeH264Options, x))
+#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 },
+    { NULL },
+};
+
 static const AVCodecDefault vaapi_encode_h264_defaults[] = {
     { "profile",        "100" },
     { "level",          "51"  },
     { "b",              "0"   },
     { "bf",             "2"   },
     { "g",              "120" },
-    { "global_quality", "20"  },
     { "i_qfactor",      "1.0" },
     { "i_qoffset",      "0.0" },
     { "b_qfactor",      "1.2" },
@@ -878,6 +891,7 @@ static const AVCodecDefault vaapi_encode_h264_defaults[] = {
 static const AVClass vaapi_encode_h264_class = {
     .class_name = "h264_vaapi",
     .item_name  = av_default_item_name,
+    .option     = vaapi_encode_h264_options,
     .version    = LIBAVUTIL_VERSION_INT,
 };

@@ -886,7 +900,8 @@ AVCodec ff_h264_vaapi_encoder = {
     .long_name      = NULL_IF_CONFIG_SMALL("H.264/AVC (VAAPI)"),
     .type           = AVMEDIA_TYPE_VIDEO,
     .id             = AV_CODEC_ID_H264,
-    .priv_data_size = sizeof(VAAPIEncodeContext),
+    .priv_data_size = (sizeof(VAAPIEncodeContext) +
+                       sizeof(VAAPIEncodeH264Options)),
     .init           = &vaapi_encode_h264_init,
     .encode2        = &ff_vaapi_encode2,
     .close          = &ff_vaapi_encode_close,
diff --git a/libavcodec/vaapi_encode_h265.c b/libavcodec/vaapi_encode_h265.c
index 323efd4..899a394 100644
--- a/libavcodec/vaapi_encode_h265.c
+++ b/libavcodec/vaapi_encode_h265.c
@@ -184,6 +184,10 @@ typedef struct VAAPIEncodeH265Context {
     int64_t last_idr_frame;
 } VAAPIEncodeH265Context;

+typedef struct VAAPIEncodeH265Options {
+    int qp;
+} VAAPIEncodeH265Options;
+

 #define vseq_var(name)     vseq->name, name
 #define vseq_field(name)   vseq->seq_fields.bits.name, name
@@ -1139,6 +1143,7 @@ static av_cold int 
vaapi_encode_h265_init_internal(AVCodecContext *avctx)

     VAAPIEncodeContext      *ctx = avctx->priv_data;
     VAAPIEncodeH265Context *priv = ctx->priv_data;
+    VAAPIEncodeH265Options  *opt = (VAAPIEncodeH265Options*)ctx->codec_options;
     int i;

     switch (avctx->profile) {
@@ -1181,7 +1186,7 @@ static av_cold int 
vaapi_encode_h265_init_internal(AVCodecContext *avctx)

     ctx->va_rc_mode = VA_RC_CQP;

-    priv->fixed_qp_p = avctx->global_quality;
+    priv->fixed_qp_p = opt->qp;
     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,13 +1231,21 @@ static av_cold int 
vaapi_encode_h265_init(AVCodecContext *avctx)
     return ff_vaapi_encode_init(avctx, &vaapi_encode_type_h265);
 }

+#define OFFSET(x) (offsetof(VAAPIEncodeContext, codec_options) +        \
+                   offsetof(VAAPIEncodeH265Options, x))
+#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 },
+    { NULL },
+};
+
 static const AVCodecDefault vaapi_encode_h265_defaults[] = {
     { "profile",        "1"   },
     { "level",          "51"  },
     { "b",              "0"   },
     { "bf",             "2"   },
     { "g",              "120" },
-    { "global_quality", "25"  },
     { "i_qfactor",      "1.0" },
     { "i_qoffset",      "0.0" },
     { "b_qfactor",      "1.2" },
@@ -1243,6 +1256,7 @@ static const AVCodecDefault vaapi_encode_h265_defaults[] 
= {
 static const AVClass vaapi_encode_h265_class = {
     .class_name = "h265_vaapi",
     .item_name  = av_default_item_name,
+    .option     = vaapi_encode_h265_options,
     .version    = LIBAVUTIL_VERSION_INT,
 };

@@ -1251,7 +1265,8 @@ AVCodec ff_hevc_vaapi_encoder = {
     .long_name      = NULL_IF_CONFIG_SMALL("H.265/HEVC (VAAPI)"),
     .type           = AVMEDIA_TYPE_VIDEO,
     .id             = AV_CODEC_ID_HEVC,
-    .priv_data_size = sizeof(VAAPIEncodeContext),
+    .priv_data_size = (sizeof(VAAPIEncodeContext) +
+                       sizeof(VAAPIEncodeH265Options)),
     .init           = &vaapi_encode_h265_init,
     .encode2        = &ff_vaapi_encode2,
     .close          = &ff_vaapi_encode_close,
-- 
2.8.0.rc3

_______________________________________________
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to