diff mbox series

[FFmpeg-devel,v2,3/7] libavcodec/qsvenc: Add gop_size reset support to qsvenc

Message ID 20220906092258.994742-3-wenbin.chen@intel.com
State Accepted
Commit d60f657a50773ae8371585539bf484aa072bfc71
Headers show
Series [FFmpeg-devel,v2,1/7] libavcodec/qsvenc: skip parameter resetting on mjpeg_qsv | 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 Sept. 6, 2022, 9:22 a.m. UTC
Signed-off-by: Wenbin Chen <wenbin.chen@intel.com>
---
 doc/encoders.texi   |  3 +++
 libavcodec/qsvenc.c | 16 ++++++++++++++++
 libavcodec/qsvenc.h |  2 ++
 3 files changed, 21 insertions(+)
diff mbox series

Patch

diff --git a/doc/encoders.texi b/doc/encoders.texi
index aadb6ab9fd..bc1a4dae38 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -3348,6 +3348,9 @@  Change these value to reset qsv codec's qp configuration.
 @item @var{max_frame_size}
 Supported in h264_qsv and hevc_qsv.
 Change this value to reset qsv codec's MaxFrameSize configuration.
+
+@item @var{gop_size}
+Change this value to reset qsv codec's gop configuration.
 @end table
 
 @subsection H264 options
diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index 915a1abd26..9a0431630a 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -636,6 +636,7 @@  static int init_video_param(AVCodecContext *avctx, QSVEncContext *q)
     q->param.mfx.CodecProfile       = q->profile;
     q->param.mfx.TargetUsage        = avctx->compression_level;
     q->param.mfx.GopPicSize         = FFMAX(0, avctx->gop_size);
+    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;
@@ -1694,6 +1695,20 @@  static int update_max_frame_size(AVCodecContext *avctx, QSVEncContext *q)
     return updated;
 }
 
+static int update_gop_size(AVCodecContext *avctx, QSVEncContext *q)
+{
+    int updated = 0;
+    UPDATE_PARAM(q->old_gop_size, avctx->gop_size);
+    if (!updated)
+        return 0;
+
+    q->param.mfx.GopPicSize = FFMAX(0, avctx->gop_size);
+    av_log(avctx, AV_LOG_DEBUG, "reset GopPicSize to %d\n",
+           q->param.mfx.GopPicSize);
+
+    return updated;
+}
+
 static int update_parameters(AVCodecContext *avctx, QSVEncContext *q,
                              const AVFrame *frame)
 {
@@ -1704,6 +1719,7 @@  static int update_parameters(AVCodecContext *avctx, QSVEncContext *q,
 
     needReset = update_qp(avctx, q);
     needReset |= update_max_frame_size(avctx, q);
+    needReset |= update_gop_size(avctx, q);
     if (!needReset)
         return 0;
 
diff --git a/libavcodec/qsvenc.h b/libavcodec/qsvenc.h
index 3984ae7dd8..5f6955a3a7 100644
--- a/libavcodec/qsvenc.h
+++ b/libavcodec/qsvenc.h
@@ -251,6 +251,8 @@  typedef struct QSVEncContext {
     float old_b_quant_offset;
     // This is used for max_frame_size reset
     int old_max_frame_size;
+    // This is used for gop reset
+    int old_gop_size;
 } QSVEncContext;
 
 int ff_qsv_enc_init(AVCodecContext *avctx, QSVEncContext *q);