diff options
author | Wenbin Chen <wenbin.chen-at-intel.com@ffmpeg.org> | 2022-09-06 17:22:53 +0800 |
---|---|---|
committer | Haihao Xiang <haihao.xiang@intel.com> | 2022-09-09 09:39:44 +0800 |
commit | c679de9be0d76e4eadc42f68421a569ff304c3e6 (patch) | |
tree | d2cd9b0e08372fe55fdcc3ec77209616ed4509b0 | |
parent | 04e49bbbb1cdf4a67e6533dc8ae29a8de1ba6837 (diff) | |
download | ffmpeg-c679de9be0d76e4eadc42f68421a569ff304c3e6.tar.gz |
libavcodec/qsvenc: Add max_frame_size reset support to qsv
Signed-off-by: Wenbin Chen <wenbin.chen@intel.com>
-rw-r--r-- | doc/encoders.texi | 4 | ||||
-rw-r--r-- | libavcodec/qsvenc.c | 20 | ||||
-rw-r--r-- | libavcodec/qsvenc.h | 2 |
3 files changed, 26 insertions, 0 deletions
diff --git a/doc/encoders.texi b/doc/encoders.texi index d2046e437d..e619827c90 100644 --- a/doc/encoders.texi +++ b/doc/encoders.texi @@ -3331,6 +3331,10 @@ Following options can be used durning qsv encoding. @item @var{b_quant_offset} Supported in h264_qsv and hevc_qsv. 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. @end table @subsection H264 options diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c index 941a12ffbd..b1f49e95fa 100644 --- a/libavcodec/qsvenc.c +++ b/libavcodec/qsvenc.c @@ -827,6 +827,7 @@ static int init_video_param(AVCodecContext *avctx, QSVEncContext *q) q->extco2.ExtBRC = q->extbrc ? MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF; if (q->max_frame_size >= 0) q->extco2.MaxFrameSize = q->max_frame_size; + q->old_max_frame_size = q->max_frame_size; if (q->int_ref_type >= 0) q->extco2.IntRefType = q->int_ref_type; if (q->int_ref_cycle_size >= 0) @@ -1678,6 +1679,24 @@ static int update_qp(AVCodecContext *avctx, QSVEncContext *q) return updated; } +static int update_max_frame_size(AVCodecContext *avctx, QSVEncContext *q) +{ + int updated = 0; + + if (avctx->codec_id != AV_CODEC_ID_H264 && avctx->codec_id != AV_CODEC_ID_HEVC) + return 0; + + UPDATE_PARAM(q->old_max_frame_size, q->max_frame_size); + if (!updated) + return 0; + + q->extco2.MaxFrameSize = FFMAX(0, q->max_frame_size); + av_log(avctx, AV_LOG_DEBUG, + "Reset MaxFrameSize: %d;\n", q->extco2.MaxFrameSize); + + return updated; +} + static int update_parameters(AVCodecContext *avctx, QSVEncContext *q, const AVFrame *frame) { @@ -1687,6 +1706,7 @@ static int update_parameters(AVCodecContext *avctx, QSVEncContext *q, return 0; needReset = update_qp(avctx, q); + needReset |= update_max_frame_size(avctx, q); if (!needReset) return 0; diff --git a/libavcodec/qsvenc.h b/libavcodec/qsvenc.h index ff859f2a7e..9914351de4 100644 --- a/libavcodec/qsvenc.h +++ b/libavcodec/qsvenc.h @@ -251,6 +251,8 @@ typedef struct QSVEncContext { float old_i_quant_offset; float old_b_quant_factor; float old_b_quant_offset; + // This is used for max_frame_size reset + int old_max_frame_size; } QSVEncContext; int ff_qsv_enc_init(AVCodecContext *avctx, QSVEncContext *q); |