diff mbox series

[FFmpeg-devel] libavcodec/qsvenc.c: Disable MFX_GOP_STRICT when encode adpative gop

Message ID 20221116021338.502587-1-wenbin.chen@intel.com
State New
Headers show
Series [FFmpeg-devel] libavcodec/qsvenc.c: Disable MFX_GOP_STRICT when encode adpative gop | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Chen, Wenbin Nov. 16, 2022, 2:13 a.m. UTC
From: Wenbin Chen <wenbin.chen@intel.com>

b_strategy, p_strategy, adaptive_i and adaptive_b cannot work with
MFX_GOP_STRICT, so disable MFX_GOP_STRICT when these features are used.

Signed-off-by: Wenbin Chen <wenbin.chen@intel.com>
---
 libavcodec/qsvenc.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

Comments

Xiang, Haihao Nov. 17, 2022, 2:46 a.m. UTC | #1
On Wed, 2022-11-16 at 10:13 +0800, wenbin.chen-at-intel.com@ffmpeg.org wrote:
> From: Wenbin Chen <wenbin.chen@intel.com>
> 
> b_strategy, p_strategy, adaptive_i and adaptive_b cannot work with
> MFX_GOP_STRICT, so disable MFX_GOP_STRICT when these features are used.
> 
> Signed-off-by: Wenbin Chen <wenbin.chen@intel.com>
> ---
>  libavcodec/qsvenc.c | 10 +++++++++-
>  1 file changed, 9 insertions(+), 1 deletion(-)
> 
> diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
> index d5e9f2d420..6777a6fb5f 100644
> --- a/libavcodec/qsvenc.c
> +++ b/libavcodec/qsvenc.c
> @@ -644,6 +644,13 @@ static int check_enc_param(AVCodecContext *avctx,
> QSVEncContext *q)
>      return 1;
>  }
>  
> +static int is_adaptive_gop(QSVEncContext *q) {
> +    if (q->adaptive_b > 0 || q->adaptive_i > 0 ||
> +        q->b_strategy > 0 || q->p_strategy > 0)
> +        return 1;
> +    return 0;
> +}
> +
>  static int init_video_param_jpeg(AVCodecContext *avctx, QSVEncContext *q)
>  {
>      enum AVPixelFormat sw_format = avctx->pix_fmt == AV_PIX_FMT_QSV ?
> @@ -755,7 +762,8 @@ static int init_video_param(AVCodecContext *avctx,
> QSVEncContext *q)
>      q->old_gop_size                 = avctx->gop_size;
>      q->param.mfx.GopRefDist         = FFMAX(-1, avctx->max_b_frames) + 1;
>      q->param.mfx.GopOptFlag         = avctx->flags & AV_CODEC_FLAG_CLOSED_GOP
> ?
> -                                      MFX_GOP_CLOSED : MFX_GOP_STRICT;
> +                                      MFX_GOP_CLOSED : is_adaptive_gop(q) ?
> +                                      0 : MFX_GOP_STRICT;
>      q->param.mfx.IdrInterval        = q->idr_interval;
>      q->param.mfx.NumSlice           = avctx->slices;
>      q->param.mfx.NumRefFrame        = FFMAX(0, avctx->refs);

LGTM, will apply

-Haihao
diff mbox series

Patch

diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index d5e9f2d420..6777a6fb5f 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -644,6 +644,13 @@  static int check_enc_param(AVCodecContext *avctx, QSVEncContext *q)
     return 1;
 }
 
+static int is_adaptive_gop(QSVEncContext *q) {
+    if (q->adaptive_b > 0 || q->adaptive_i > 0 ||
+        q->b_strategy > 0 || q->p_strategy > 0)
+        return 1;
+    return 0;
+}
+
 static int init_video_param_jpeg(AVCodecContext *avctx, QSVEncContext *q)
 {
     enum AVPixelFormat sw_format = avctx->pix_fmt == AV_PIX_FMT_QSV ?
@@ -755,7 +762,8 @@  static int init_video_param(AVCodecContext *avctx, QSVEncContext *q)
     q->old_gop_size                 = avctx->gop_size;
     q->param.mfx.GopRefDist         = FFMAX(-1, avctx->max_b_frames) + 1;
     q->param.mfx.GopOptFlag         = avctx->flags & AV_CODEC_FLAG_CLOSED_GOP ?
-                                      MFX_GOP_CLOSED : MFX_GOP_STRICT;
+                                      MFX_GOP_CLOSED : is_adaptive_gop(q) ?
+                                      0 : MFX_GOP_STRICT;
     q->param.mfx.IdrInterval        = q->idr_interval;
     q->param.mfx.NumSlice           = avctx->slices;
     q->param.mfx.NumRefFrame        = FFMAX(0, avctx->refs);