Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH v3] libavcodec/qsvenc: Enable fixed QP configure in qsv CQP runtime
@ 2022-06-23  5:32 Wenbin Chen
  2022-06-25  2:47 ` Xiang, Haihao
  2022-07-02  9:39 ` Anton Khirnov
  0 siblings, 2 replies; 7+ messages in thread
From: Wenbin Chen @ 2022-06-23  5:32 UTC (permalink / raw)
  To: ffmpeg-devel

From: Yue Heng <yue.heng@intel.com>

Enable dynamic QP configuration in runtime on qsv encoder. Through
AVFrame->metadata, we can set key "qsv_config_qp" to change QP
configuration when we encode video in CQP mode.

Signed-off-by: Yue Heng <yue.heng@intel.com>
Signed-off-by: Wenbin Chen <wenbin.chen@intel.com>
---
 doc/encoders.texi   | 10 +++++
 libavcodec/qsvenc.c | 89 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 99 insertions(+)

diff --git a/doc/encoders.texi b/doc/encoders.texi
index 1850c99fe9..02a91ffe96 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -3333,6 +3333,16 @@ Forcing I frames as IDR frames.
 For encoders set this flag to ON to reduce power consumption and GPU usage.
 @end table
 
+@subsection Runtime Options
+Following options can be used durning qsv encoding.
+
+@table @option
+@item @var{qsv_config_qp}
+Supported in h264_qsv and hevc_qsv.
+This option can be set in per-frame metadata. QP parameter can be dynamically
+changed when encoding in CQP mode.
+@end table
+
 @subsection H264 options
 These options are used by h264_qsv
 
diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index 902bada55b..2382c2f5f7 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -146,6 +146,14 @@ static const struct {
     { MFX_RATECONTROL_QVBR,    "QVBR" },
 };
 
+#define UPDATE_PARAM(a, b)  \
+do {                        \
+    if ((a) != (b)) {       \
+        a = b;              \
+        updated = 1;        \
+    }                       \
+} while (0)                 \
+
 static const char *print_ratecontrol(mfxU16 rc_mode)
 {
     int i;
@@ -1613,6 +1621,83 @@ static int set_roi_encode_ctrl(AVCodecContext *avctx, const AVFrame *frame,
     return 0;
 }
 
+static int update_qp(AVCodecContext *avctx, QSVEncContext *q,
+                     const AVFrame *frame)
+{
+    int updated = 0, qp = 0, new_qp;
+    char *tail;
+    AVDictionaryEntry *entry = NULL;
+
+    if (avctx->codec_id != AV_CODEC_ID_H264 && avctx->codec_id != AV_CODEC_ID_HEVC)
+        return 0;
+
+    entry = av_dict_get(frame->metadata, "qsv_config_qp", NULL, 0);
+    if (entry && q->param.mfx.RateControlMethod == MFX_RATECONTROL_CQP) {
+        qp = strtol(entry->value, &tail, 10);
+        if (*tail) {
+            av_log(avctx, AV_LOG_WARNING, "Invalid qsv_config_qp string. Ignore this metadata\n");
+            return 0;
+        }
+        if (qp < 0 || qp > 51) {
+            av_log(avctx, AV_LOG_WARNING, "Invalid qp, clip to 0 ~ 51\n");
+            qp = av_clip(qp, 0, 51);
+        }
+        av_log(avctx, AV_LOG_DEBUG, "Configure qp: %d\n",qp);
+        UPDATE_PARAM(q->param.mfx.QPP, qp);
+        new_qp = av_clip(qp * fabs(avctx->i_quant_factor) +
+                            avctx->i_quant_offset, 0, 51);
+        UPDATE_PARAM(q->param.mfx.QPI, new_qp);
+        new_qp = av_clip(qp * fabs(avctx->b_quant_factor) +
+                            avctx->b_quant_offset, 0, 51);
+        UPDATE_PARAM(q->param.mfx.QPB, new_qp);
+        av_log(avctx, AV_LOG_DEBUG,
+                "using fixed qp = %d/%d/%d for idr/p/b frames\n",
+                q->param.mfx.QPI, q->param.mfx.QPP, q->param.mfx.QPB);
+    }
+    return updated;
+}
+
+static int update_parameters(AVCodecContext *avctx, QSVEncContext *q,
+                             const AVFrame *frame)
+{
+    int needReset = 0, ret = 0;
+
+    if (!frame)
+        return 0;
+
+    needReset = update_qp(avctx, q, frame);
+    if (!needReset)
+        return 0;
+
+    if (avctx->hwaccel_context) {
+        AVQSVContext *qsv = avctx->hwaccel_context;
+        int i, j;
+        q->param.ExtParam = q->extparam;
+        for (i = 0; i < qsv->nb_ext_buffers; i++)
+            q->param.ExtParam[i] = qsv->ext_buffers[i];
+        q->param.NumExtParam = qsv->nb_ext_buffers;
+
+        for (i = 0; i < q->nb_extparam_internal; i++) {
+            for (j = 0; j < qsv->nb_ext_buffers; j++) {
+                if (qsv->ext_buffers[j]->BufferId == q->extparam_internal[i]->BufferId)
+                    break;
+            }
+            if (j < qsv->nb_ext_buffers)
+                continue;
+            q->param.ExtParam[q->param.NumExtParam++] = q->extparam_internal[i];
+        }
+    } else {
+        q->param.ExtParam    = q->extparam_internal;
+        q->param.NumExtParam = q->nb_extparam_internal;
+    }
+    av_log(avctx, AV_LOG_DEBUG, "Parameter change, call msdk reset.\n");
+    ret = MFXVideoENCODE_Reset(q->session, &q->param);
+    if (ret < 0)
+        return ff_qsv_print_error(avctx, ret, "Error during resetting");
+
+    return 0;
+}
+
 static int encode_frame(AVCodecContext *avctx, QSVEncContext *q,
                         const AVFrame *frame)
 {
@@ -1731,6 +1816,10 @@ int ff_qsv_encode(AVCodecContext *avctx, QSVEncContext *q,
 {
     int ret;
 
+    ret = update_parameters(avctx, q, frame);
+    if (ret < 0)
+        return ret;
+
     ret = encode_frame(avctx, q, frame);
     if (ret < 0)
         return ret;
-- 
2.32.0

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

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [FFmpeg-devel] [PATCH v3] libavcodec/qsvenc: Enable fixed QP configure in qsv CQP runtime
  2022-06-23  5:32 [FFmpeg-devel] [PATCH v3] libavcodec/qsvenc: Enable fixed QP configure in qsv CQP runtime Wenbin Chen
@ 2022-06-25  2:47 ` Xiang, Haihao
  2022-07-02  9:39 ` Anton Khirnov
  1 sibling, 0 replies; 7+ messages in thread
From: Xiang, Haihao @ 2022-06-25  2:47 UTC (permalink / raw)
  To: ffmpeg-devel

On Thu, 2022-06-23 at 13:32 +0800, Wenbin Chen wrote:
> From: Yue Heng <yue.heng@intel.com>
> 
> Enable dynamic QP configuration in runtime on qsv encoder. Through
> AVFrame->metadata, we can set key "qsv_config_qp" to change QP
> configuration when we encode video in CQP mode.
> 
> Signed-off-by: Yue Heng <yue.heng@intel.com>
> Signed-off-by: Wenbin Chen <wenbin.chen@intel.com>
> ---
>  doc/encoders.texi   | 10 +++++
>  libavcodec/qsvenc.c | 89 +++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 99 insertions(+)
> 
> diff --git a/doc/encoders.texi b/doc/encoders.texi
> index 1850c99fe9..02a91ffe96 100644
> --- a/doc/encoders.texi
> +++ b/doc/encoders.texi
> @@ -3333,6 +3333,16 @@ Forcing I frames as IDR frames.
>  For encoders set this flag to ON to reduce power consumption and GPU usage.
>  @end table
>  
> +@subsection Runtime Options
> +Following options can be used durning qsv encoding.
> +
> +@table @option
> +@item @var{qsv_config_qp}
> +Supported in h264_qsv and hevc_qsv.
> +This option can be set in per-frame metadata. QP parameter can be dynamically
> +changed when encoding in CQP mode.
> +@end table
> +
>  @subsection H264 options
>  These options are used by h264_qsv
>  
> diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
> index 902bada55b..2382c2f5f7 100644
> --- a/libavcodec/qsvenc.c
> +++ b/libavcodec/qsvenc.c
> @@ -146,6 +146,14 @@ static const struct {
>      { MFX_RATECONTROL_QVBR,    "QVBR" },
>  };
>  
> +#define UPDATE_PARAM(a, b)  \
> +do {                        \
> +    if ((a) != (b)) {       \
> +        a = b;              \
> +        updated = 1;        \
> +    }                       \
> +} while (0)                 \
> +
>  static const char *print_ratecontrol(mfxU16 rc_mode)
>  {
>      int i;
> @@ -1613,6 +1621,83 @@ static int set_roi_encode_ctrl(AVCodecContext *avctx,
> const AVFrame *frame,
>      return 0;
>  }
>  
> +static int update_qp(AVCodecContext *avctx, QSVEncContext *q,
> +                     const AVFrame *frame)
> +{
> +    int updated = 0, qp = 0, new_qp;
> +    char *tail;
> +    AVDictionaryEntry *entry = NULL;
> +
> +    if (avctx->codec_id != AV_CODEC_ID_H264 && avctx->codec_id !=
> AV_CODEC_ID_HEVC)
> +        return 0;
> +
> +    entry = av_dict_get(frame->metadata, "qsv_config_qp", NULL, 0);
> +    if (entry && q->param.mfx.RateControlMethod == MFX_RATECONTROL_CQP) {
> +        qp = strtol(entry->value, &tail, 10);
> +        if (*tail) {
> +            av_log(avctx, AV_LOG_WARNING, "Invalid qsv_config_qp string.
> Ignore this metadata\n");
> +            return 0;
> +        }
> +        if (qp < 0 || qp > 51) {
> +            av_log(avctx, AV_LOG_WARNING, "Invalid qp, clip to 0 ~ 51\n");
> +            qp = av_clip(qp, 0, 51);
> +        }
> +        av_log(avctx, AV_LOG_DEBUG, "Configure qp: %d\n",qp);
> +        UPDATE_PARAM(q->param.mfx.QPP, qp);
> +        new_qp = av_clip(qp * fabs(avctx->i_quant_factor) +
> +                            avctx->i_quant_offset, 0, 51);
> +        UPDATE_PARAM(q->param.mfx.QPI, new_qp);
> +        new_qp = av_clip(qp * fabs(avctx->b_quant_factor) +
> +                            avctx->b_quant_offset, 0, 51);
> +        UPDATE_PARAM(q->param.mfx.QPB, new_qp);
> +        av_log(avctx, AV_LOG_DEBUG,
> +                "using fixed qp = %d/%d/%d for idr/p/b frames\n",
> +                q->param.mfx.QPI, q->param.mfx.QPP, q->param.mfx.QPB);
> +    }
> +    return updated;
> +}
> +
> +static int update_parameters(AVCodecContext *avctx, QSVEncContext *q,
> +                             const AVFrame *frame)
> +{
> +    int needReset = 0, ret = 0;
> +
> +    if (!frame)
> +        return 0;
> +
> +    needReset = update_qp(avctx, q, frame);
> +    if (!needReset)
> +        return 0;
> +
> +    if (avctx->hwaccel_context) {
> +        AVQSVContext *qsv = avctx->hwaccel_context;
> +        int i, j;
> +        q->param.ExtParam = q->extparam;
> +        for (i = 0; i < qsv->nb_ext_buffers; i++)
> +            q->param.ExtParam[i] = qsv->ext_buffers[i];
> +        q->param.NumExtParam = qsv->nb_ext_buffers;
> +
> +        for (i = 0; i < q->nb_extparam_internal; i++) {
> +            for (j = 0; j < qsv->nb_ext_buffers; j++) {
> +                if (qsv->ext_buffers[j]->BufferId == q->extparam_internal[i]-
> >BufferId)
> +                    break;
> +            }
> +            if (j < qsv->nb_ext_buffers)
> +                continue;
> +            q->param.ExtParam[q->param.NumExtParam++] = q-
> >extparam_internal[i];
> +        }
> +    } else {
> +        q->param.ExtParam    = q->extparam_internal;
> +        q->param.NumExtParam = q->nb_extparam_internal;
> +    }
> +    av_log(avctx, AV_LOG_DEBUG, "Parameter change, call msdk reset.\n");
> +    ret = MFXVideoENCODE_Reset(q->session, &q->param);
> +    if (ret < 0)
> +        return ff_qsv_print_error(avctx, ret, "Error during resetting");
> +
> +    return 0;
> +}
> +
>  static int encode_frame(AVCodecContext *avctx, QSVEncContext *q,
>                          const AVFrame *frame)
>  {
> @@ -1731,6 +1816,10 @@ int ff_qsv_encode(AVCodecContext *avctx, QSVEncContext
> *q,
>  {
>      int ret;
>  
> +    ret = update_parameters(avctx, q, frame);
> +    if (ret < 0)
> +        return ret;
> +
>      ret = encode_frame(avctx, q, frame);
>      if (ret < 0)
>          return ret;

LGTM, will apply.

-Haihao

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

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [FFmpeg-devel] [PATCH v3] libavcodec/qsvenc: Enable fixed QP configure in qsv CQP runtime
  2022-06-23  5:32 [FFmpeg-devel] [PATCH v3] libavcodec/qsvenc: Enable fixed QP configure in qsv CQP runtime Wenbin Chen
  2022-06-25  2:47 ` Xiang, Haihao
@ 2022-07-02  9:39 ` Anton Khirnov
  2022-07-02 14:21   ` Paul B Mahol
                     ` (2 more replies)
  1 sibling, 3 replies; 7+ messages in thread
From: Anton Khirnov @ 2022-07-02  9:39 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

Quoting Wenbin Chen (2022-06-23 07:32:42)
> From: Yue Heng <yue.heng@intel.com>
> 
> Enable dynamic QP configuration in runtime on qsv encoder. Through
> AVFrame->metadata, we can set key "qsv_config_qp" to change QP
> configuration when we encode video in CQP mode.
> 
> Signed-off-by: Yue Heng <yue.heng@intel.com>
> Signed-off-by: Wenbin Chen <wenbin.chen@intel.com>
> ---
>  doc/encoders.texi   | 10 +++++
>  libavcodec/qsvenc.c | 89 +++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 99 insertions(+)
> 
> diff --git a/doc/encoders.texi b/doc/encoders.texi
> index 1850c99fe9..02a91ffe96 100644
> --- a/doc/encoders.texi
> +++ b/doc/encoders.texi
> @@ -3333,6 +3333,16 @@ Forcing I frames as IDR frames.
>  For encoders set this flag to ON to reduce power consumption and GPU usage.
>  @end table
>  
> +@subsection Runtime Options
> +Following options can be used durning qsv encoding.
> +
> +@table @option
> +@item @var{qsv_config_qp}
> +Supported in h264_qsv and hevc_qsv.
> +This option can be set in per-frame metadata. QP parameter can be dynamically
> +changed when encoding in CQP mode.
> +@end table
> +
>  @subsection H264 options
>  These options are used by h264_qsv
>  
> diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
> index 902bada55b..2382c2f5f7 100644
> --- a/libavcodec/qsvenc.c
> +++ b/libavcodec/qsvenc.c
> @@ -146,6 +146,14 @@ static const struct {
>      { MFX_RATECONTROL_QVBR,    "QVBR" },
>  };
>  
> +#define UPDATE_PARAM(a, b)  \
> +do {                        \
> +    if ((a) != (b)) {       \
> +        a = b;              \
> +        updated = 1;        \
> +    }                       \
> +} while (0)                 \
> +
>  static const char *print_ratecontrol(mfxU16 rc_mode)
>  {
>      int i;
> @@ -1613,6 +1621,83 @@ static int set_roi_encode_ctrl(AVCodecContext *avctx, const AVFrame *frame,
>      return 0;
>  }
>  
> +static int update_qp(AVCodecContext *avctx, QSVEncContext *q,
> +                     const AVFrame *frame)
> +{
> +    int updated = 0, qp = 0, new_qp;
> +    char *tail;
> +    AVDictionaryEntry *entry = NULL;
> +
> +    if (avctx->codec_id != AV_CODEC_ID_H264 && avctx->codec_id != AV_CODEC_ID_HEVC)
> +        return 0;
> +
> +    entry = av_dict_get(frame->metadata, "qsv_config_qp", NULL, 0);

Why is this using frame metadata rather than the AVVideoEncParams side
data?

Frame metadata should not be used in encoders at all. Longer term it
should not be used at all by anything.

-- 
Anton Khirnov
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [FFmpeg-devel] [PATCH v3] libavcodec/qsvenc: Enable fixed QP configure in qsv CQP runtime
  2022-07-02  9:39 ` Anton Khirnov
@ 2022-07-02 14:21   ` Paul B Mahol
  2022-07-04  6:33   ` Chen, Wenbin
  2022-07-04  6:45   ` Anton Khirnov
  2 siblings, 0 replies; 7+ messages in thread
From: Paul B Mahol @ 2022-07-02 14:21 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

On Sat, Jul 2, 2022 at 11:39 AM Anton Khirnov <anton@khirnov.net> wrote:

> Quoting Wenbin Chen (2022-06-23 07:32:42)
> > From: Yue Heng <yue.heng@intel.com>
> >
> > Enable dynamic QP configuration in runtime on qsv encoder. Through
> > AVFrame->metadata, we can set key "qsv_config_qp" to change QP
> > configuration when we encode video in CQP mode.
> >
> > Signed-off-by: Yue Heng <yue.heng@intel.com>
> > Signed-off-by: Wenbin Chen <wenbin.chen@intel.com>
> > ---
> >  doc/encoders.texi   | 10 +++++
> >  libavcodec/qsvenc.c | 89 +++++++++++++++++++++++++++++++++++++++++++++
> >  2 files changed, 99 insertions(+)
> >
> > diff --git a/doc/encoders.texi b/doc/encoders.texi
> > index 1850c99fe9..02a91ffe96 100644
> > --- a/doc/encoders.texi
> > +++ b/doc/encoders.texi
> > @@ -3333,6 +3333,16 @@ Forcing I frames as IDR frames.
> >  For encoders set this flag to ON to reduce power consumption and GPU
> usage.
> >  @end table
> >
> > +@subsection Runtime Options
> > +Following options can be used durning qsv encoding.
> > +
> > +@table @option
> > +@item @var{qsv_config_qp}
> > +Supported in h264_qsv and hevc_qsv.
> > +This option can be set in per-frame metadata. QP parameter can be
> dynamically
> > +changed when encoding in CQP mode.
> > +@end table
> > +
> >  @subsection H264 options
> >  These options are used by h264_qsv
> >
> > diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
> > index 902bada55b..2382c2f5f7 100644
> > --- a/libavcodec/qsvenc.c
> > +++ b/libavcodec/qsvenc.c
> > @@ -146,6 +146,14 @@ static const struct {
> >      { MFX_RATECONTROL_QVBR,    "QVBR" },
> >  };
> >
> > +#define UPDATE_PARAM(a, b)  \
> > +do {                        \
> > +    if ((a) != (b)) {       \
> > +        a = b;              \
> > +        updated = 1;        \
> > +    }                       \
> > +} while (0)                 \
> > +
> >  static const char *print_ratecontrol(mfxU16 rc_mode)
> >  {
> >      int i;
> > @@ -1613,6 +1621,83 @@ static int set_roi_encode_ctrl(AVCodecContext
> *avctx, const AVFrame *frame,
> >      return 0;
> >  }
> >
> > +static int update_qp(AVCodecContext *avctx, QSVEncContext *q,
> > +                     const AVFrame *frame)
> > +{
> > +    int updated = 0, qp = 0, new_qp;
> > +    char *tail;
> > +    AVDictionaryEntry *entry = NULL;
> > +
> > +    if (avctx->codec_id != AV_CODEC_ID_H264 && avctx->codec_id !=
> AV_CODEC_ID_HEVC)
> > +        return 0;
> > +
> > +    entry = av_dict_get(frame->metadata, "qsv_config_qp", NULL, 0);
>
> Why is this using frame metadata rather than the AVVideoEncParams side
> data?
>
> Frame metadata should not be used in encoders at all. Longer term it
> should not be used at all by anything.
>

Disagreed. Stop sharing your agenda.


>
> --
> Anton Khirnov
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
>
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [FFmpeg-devel] [PATCH v3] libavcodec/qsvenc: Enable fixed QP configure in qsv CQP runtime
  2022-07-02  9:39 ` Anton Khirnov
  2022-07-02 14:21   ` Paul B Mahol
@ 2022-07-04  6:33   ` Chen, Wenbin
  2022-07-04  6:45   ` Anton Khirnov
  2 siblings, 0 replies; 7+ messages in thread
From: Chen, Wenbin @ 2022-07-04  6:33 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

> Quoting Wenbin Chen (2022-06-23 07:32:42)
> > From: Yue Heng <yue.heng@intel.com>
> >
> > Enable dynamic QP configuration in runtime on qsv encoder. Through
> > AVFrame->metadata, we can set key "qsv_config_qp" to change QP
> > configuration when we encode video in CQP mode.
> >
> > Signed-off-by: Yue Heng <yue.heng@intel.com>
> > Signed-off-by: Wenbin Chen <wenbin.chen@intel.com>
> > ---
> >  doc/encoders.texi   | 10 +++++
> >  libavcodec/qsvenc.c | 89
> +++++++++++++++++++++++++++++++++++++++++++++
> >  2 files changed, 99 insertions(+)
> >
> > diff --git a/doc/encoders.texi b/doc/encoders.texi
> > index 1850c99fe9..02a91ffe96 100644
> > --- a/doc/encoders.texi
> > +++ b/doc/encoders.texi
> > @@ -3333,6 +3333,16 @@ Forcing I frames as IDR frames.
> >  For encoders set this flag to ON to reduce power consumption and GPU
> usage.
> >  @end table
> >
> > +@subsection Runtime Options
> > +Following options can be used durning qsv encoding.
> > +
> > +@table @option
> > +@item @var{qsv_config_qp}
> > +Supported in h264_qsv and hevc_qsv.
> > +This option can be set in per-frame metadata. QP parameter can be
> dynamically
> > +changed when encoding in CQP mode.
> > +@end table
> > +
> >  @subsection H264 options
> >  These options are used by h264_qsv
> >
> > diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
> > index 902bada55b..2382c2f5f7 100644
> > --- a/libavcodec/qsvenc.c
> > +++ b/libavcodec/qsvenc.c
> > @@ -146,6 +146,14 @@ static const struct {
> >      { MFX_RATECONTROL_QVBR,    "QVBR" },
> >  };
> >
> > +#define UPDATE_PARAM(a, b)  \
> > +do {                        \
> > +    if ((a) != (b)) {       \
> > +        a = b;              \
> > +        updated = 1;        \
> > +    }                       \
> > +} while (0)                 \
> > +
> >  static const char *print_ratecontrol(mfxU16 rc_mode)
> >  {
> >      int i;
> > @@ -1613,6 +1621,83 @@ static int set_roi_encode_ctrl(AVCodecContext
> *avctx, const AVFrame *frame,
> >      return 0;
> >  }
> >
> > +static int update_qp(AVCodecContext *avctx, QSVEncContext *q,
> > +                     const AVFrame *frame)
> > +{
> > +    int updated = 0, qp = 0, new_qp;
> > +    char *tail;
> > +    AVDictionaryEntry *entry = NULL;
> > +
> > +    if (avctx->codec_id != AV_CODEC_ID_H264 && avctx->codec_id !=
> AV_CODEC_ID_HEVC)
> > +        return 0;
> > +
> > +    entry = av_dict_get(frame->metadata, "qsv_config_qp", NULL, 0);
> 
> Why is this using frame metadata rather than the AVVideoEncParams side
> data?

The usage of AVVideoEncParams relates to the "qp" variable in mfxEncodeCtrl which is passed
to MFXVideoENCODE_encoderFrameAsync(). This variable in qsv is for per-frame QP
configuration.
There are other parameter changing supports I want to add besides QP, for
example, gop_size, max_frame_size, intra_refresh. These parameter configurations are not
all included in mfxEncodeCtrl, so I choose to use MFXVideoENCODE_Reset() to do this. This
code changes the encoding parameters which means these changes are applied to all
the following frames, but AVVideoEncParams is per-frame configuration, so I think
AVVideoEncParams is not suitable for this.

> 
> Frame metadata should not be used in encoders at all. Longer term it
> should not be used at all by anything.
> 
> --
> Anton Khirnov
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [FFmpeg-devel] [PATCH v3] libavcodec/qsvenc: Enable fixed QP configure in qsv CQP runtime
  2022-07-02  9:39 ` Anton Khirnov
  2022-07-02 14:21   ` Paul B Mahol
  2022-07-04  6:33   ` Chen, Wenbin
@ 2022-07-04  6:45   ` Anton Khirnov
  2022-07-04  8:40     ` Chen, Wenbin
  2 siblings, 1 reply; 7+ messages in thread
From: Anton Khirnov @ 2022-07-04  6:45 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

Quoting Chen, Wenbin (2022-07-04 08:33:49)
> > Why is this using frame metadata rather than the AVVideoEncParams side
> > data?
> 
> The usage of AVVideoEncParams relates to the "qp" variable in mfxEncodeCtrl which is passed
> to MFXVideoENCODE_encoderFrameAsync(). This variable in qsv is for per-frame QP
> configuration.
> There are other parameter changing supports I want to add besides QP, for
> example, gop_size, max_frame_size, intra_refresh. These parameter configurations are not
> all included in mfxEncodeCtrl, so I choose to use MFXVideoENCODE_Reset() to do this. This
> code changes the encoding parameters which means these changes are applied to all
> the following frames, but AVVideoEncParams is per-frame configuration, so I think
> AVVideoEncParams is not suitable for this.

AVFrame metadata is also per-frame, so your logic does not make sense to
me.

You could also just update the AVCodecContext/private context values
directly or using AVOptions.

-- 
Anton Khirnov
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [FFmpeg-devel] [PATCH v3] libavcodec/qsvenc: Enable fixed QP configure in qsv CQP runtime
  2022-07-04  6:45   ` Anton Khirnov
@ 2022-07-04  8:40     ` Chen, Wenbin
  0 siblings, 0 replies; 7+ messages in thread
From: Chen, Wenbin @ 2022-07-04  8:40 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

> Quoting Chen, Wenbin (2022-07-04 08:33:49)
> > > Why is this using frame metadata rather than the AVVideoEncParams
> side
> > > data?
> >
> > The usage of AVVideoEncParams relates to the "qp" variable in
> mfxEncodeCtrl which is passed
> > to MFXVideoENCODE_encoderFrameAsync(). This variable in qsv is for per-
> frame QP
> > configuration.
> > There are other parameter changing supports I want to add besides QP, for
> > example, gop_size, max_frame_size, intra_refresh. These parameter
> configurations are not
> > all included in mfxEncodeCtrl, so I choose to use MFXVideoENCODE_Reset()
> to do this. This
> > code changes the encoding parameters which means these changes are
> applied to all
> > the following frames, but AVVideoEncParams is per-frame configuration,
> so I think
> > AVVideoEncParams is not suitable for this.
> 
> AVFrame metadata is also per-frame, so your logic does not make sense to
> me.
> 
> You could also just update the AVCodecContext/private context values
> directly or using AVOptions.

This is a possible way. I will change it. Thanks for your advice.

> 
> --
> Anton Khirnov
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-07-04  8:40 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-23  5:32 [FFmpeg-devel] [PATCH v3] libavcodec/qsvenc: Enable fixed QP configure in qsv CQP runtime Wenbin Chen
2022-06-25  2:47 ` Xiang, Haihao
2022-07-02  9:39 ` Anton Khirnov
2022-07-02 14:21   ` Paul B Mahol
2022-07-04  6:33   ` Chen, Wenbin
2022-07-04  6:45   ` Anton Khirnov
2022-07-04  8:40     ` Chen, Wenbin

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git