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] libavcodec/qsvenc: Use parameter from AVCodecContext to reset qsv codec
@ 2022-07-06  9:14 Wenbin Chen
  2022-07-07  8:42 ` Anton Khirnov
  2022-07-14  4:46 ` Chen, Wenbin
  0 siblings, 2 replies; 3+ messages in thread
From: Wenbin Chen @ 2022-07-06  9:14 UTC (permalink / raw)
  To: ffmpeg-devel

Using parameter from AVCodecContext to reset qsv codec is more suitable
for MFXVideoENCODE_Reset()'s usage. Per-frame metadata is more suitable
for the usage of mfxEncodeCtrl being passed to
MFXVideoENCODE_EncodeFrameAsync(). Now change it to use the value
from AVCodecContext.

Signed-off-by: Wenbin Chen <wenbin.chen@intel.com>
---
 doc/encoders.texi   |  5 ++---
 libavcodec/qsvenc.c | 26 ++++++++------------------
 2 files changed, 10 insertions(+), 21 deletions(-)

diff --git a/doc/encoders.texi b/doc/encoders.texi
index 02a91ffe96..bf5fafd3fe 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -3337,10 +3337,9 @@ For encoders set this flag to ON to reduce power consumption and GPU usage.
 Following options can be used durning qsv encoding.
 
 @table @option
-@item @var{qsv_config_qp}
+@item @var{global_quality}
 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.
+Change this value to reset qsv codec's qp configuration.
 @end table
 
 @subsection H264 options
diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index 2382c2f5f7..82cb5a4865 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -1625,34 +1625,24 @@ 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);
+    if (q->param.mfx.RateControlMethod == MFX_RATECONTROL_CQP) {
+        qp = avctx->global_quality / FF_QP2LAMBDA;
+        new_qp = av_clip(qp, 0, 51);
+        UPDATE_PARAM(q->param.mfx.QPP, new_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);
+        if (updated)
+            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;
 }
-- 
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] 3+ messages in thread

* Re: [FFmpeg-devel] [PATCH] libavcodec/qsvenc: Use parameter from AVCodecContext to reset qsv codec
  2022-07-06  9:14 [FFmpeg-devel] [PATCH] libavcodec/qsvenc: Use parameter from AVCodecContext to reset qsv codec Wenbin Chen
@ 2022-07-07  8:42 ` Anton Khirnov
  2022-07-14  4:46 ` Chen, Wenbin
  1 sibling, 0 replies; 3+ messages in thread
From: Anton Khirnov @ 2022-07-07  8:42 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

Quoting Wenbin Chen (2022-07-06 11:14:40)
> Using parameter from AVCodecContext to reset qsv codec is more suitable
> for MFXVideoENCODE_Reset()'s usage. Per-frame metadata is more suitable
> for the usage of mfxEncodeCtrl being passed to
> MFXVideoENCODE_EncodeFrameAsync(). Now change it to use the value
> from AVCodecContext.
> 
> Signed-off-by: Wenbin Chen <wenbin.chen@intel.com>
> ---
>  doc/encoders.texi   |  5 ++---
>  libavcodec/qsvenc.c | 26 ++++++++------------------
>  2 files changed, 10 insertions(+), 21 deletions(-)

Thank you, looks better now.

-- 
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] 3+ messages in thread

* Re: [FFmpeg-devel] [PATCH] libavcodec/qsvenc: Use parameter from AVCodecContext to reset qsv codec
  2022-07-06  9:14 [FFmpeg-devel] [PATCH] libavcodec/qsvenc: Use parameter from AVCodecContext to reset qsv codec Wenbin Chen
  2022-07-07  8:42 ` Anton Khirnov
@ 2022-07-14  4:46 ` Chen, Wenbin
  1 sibling, 0 replies; 3+ messages in thread
From: Chen, Wenbin @ 2022-07-14  4:46 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

> Using parameter from AVCodecContext to reset qsv codec is more suitable
> for MFXVideoENCODE_Reset()'s usage. Per-frame metadata is more suitable
> for the usage of mfxEncodeCtrl being passed to
> MFXVideoENCODE_EncodeFrameAsync(). Now change it to use the value
> from AVCodecContext.
> 
> Signed-off-by: Wenbin Chen <wenbin.chen@intel.com>
> ---
>  doc/encoders.texi   |  5 ++---
>  libavcodec/qsvenc.c | 26 ++++++++------------------
>  2 files changed, 10 insertions(+), 21 deletions(-)
> 
> diff --git a/doc/encoders.texi b/doc/encoders.texi
> index 02a91ffe96..bf5fafd3fe 100644
> --- a/doc/encoders.texi
> +++ b/doc/encoders.texi
> @@ -3337,10 +3337,9 @@ For encoders set this flag to ON to reduce power
> consumption and GPU usage.
>  Following options can be used durning qsv encoding.
> 
>  @table @option
> -@item @var{qsv_config_qp}
> +@item @var{global_quality}
>  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.
> +Change this value to reset qsv codec's qp configuration.
>  @end table
> 
>  @subsection H264 options
> diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
> index 2382c2f5f7..82cb5a4865 100644
> --- a/libavcodec/qsvenc.c
> +++ b/libavcodec/qsvenc.c
> @@ -1625,34 +1625,24 @@ static int update_qp(AVCodecContext *avctx,
> QSVEncContext *q,
>                       const AVFrame *frame)

"const AVFrame *frame" is not used. It can be removed.

>  {
>      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);
> +    if (q->param.mfx.RateControlMethod == MFX_RATECONTROL_CQP) {
> +        qp = avctx->global_quality / FF_QP2LAMBDA;
> +        new_qp = av_clip(qp, 0, 51);
> +        UPDATE_PARAM(q->param.mfx.QPP, new_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);

"q->param" is passed to both "in" and "out" parameters in MFXVideoENCODE_Query() call,
so the value in q->param may be changed. There is a potential issue that codec will reset on
every frame.

I will fix these in my patch v2.

> -        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);
> +        if (updated)
> +            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;
>  }
> --
> 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".
_______________________________________________
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] 3+ messages in thread

end of thread, other threads:[~2022-07-14  4:47 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-06  9:14 [FFmpeg-devel] [PATCH] libavcodec/qsvenc: Use parameter from AVCodecContext to reset qsv codec Wenbin Chen
2022-07-07  8:42 ` Anton Khirnov
2022-07-14  4:46 ` 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