* [FFmpeg-devel] [PATCH 2/3] libavcodec/qsvenc: Add bitrate reset support to qsvenc
2022-09-23 2:44 [FFmpeg-devel] [PATCH 1/3] libavcodec/qsvenc: Add framerate reset support to qsv Wenbin Chen
@ 2022-09-23 2:44 ` Wenbin Chen
2022-09-23 2:44 ` [FFmpeg-devel] [PATCH 3/3] libavcodec/qsvenc: Add pic_timing_sei reset support to qsv Wenbin Chen
2022-09-27 4:15 ` [FFmpeg-devel] [PATCH 1/3] libavcodec/qsvenc: Add framerate " Xiang, Haihao
2 siblings, 0 replies; 4+ messages in thread
From: Wenbin Chen @ 2022-09-23 2:44 UTC (permalink / raw)
To: ffmpeg-devel
Signed-off-by: Wenbin Chen <wenbin.chen@intel.com>
---
doc/encoders.texi | 6 ++++++
libavcodec/qsvenc.c | 38 ++++++++++++++++++++++++++++++++++++++
libavcodec/qsvenc.h | 5 +++++
3 files changed, 49 insertions(+)
diff --git a/doc/encoders.texi b/doc/encoders.texi
index 4ed7ce1bb0..2b6412dbec 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -3363,6 +3363,12 @@ Change this value to reset qsv codec's low_delay_brc configuration.
@item @var{framerate}
Change this value to reset qsv codec's framerate configuration.
+
+@item @var{bit_rate}
+@item @var{rc_buffer_size}
+@item @var{rc_initial_buffer_occupancy}
+@item @var{rc_max_rate}
+Change these value to reset qsv codec's bitrate control configuration.
@end table
@subsection H264 options
diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index ce00cd302b..3371711872 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -718,6 +718,10 @@ static int init_video_param(AVCodecContext *avctx, QSVEncContext *q)
max_bitrate_kbps = avctx->rc_max_rate / 1000;
brc_param_multiplier = (FFMAX(FFMAX3(target_bitrate_kbps, max_bitrate_kbps, buffer_size_in_kilobytes),
initial_delay_in_kilobytes) + 0x10000) / 0x10000;
+ q->old_rc_buffer_size = avctx->rc_buffer_size;
+ q->old_rc_initial_buffer_occupancy = avctx->rc_initial_buffer_occupancy;
+ q->old_bit_rate = avctx->bit_rate;
+ q->old_rc_max_rate = avctx->rc_max_rate;
switch (q->param.mfx.RateControlMethod) {
case MFX_RATECONTROL_CBR:
@@ -1863,6 +1867,39 @@ static int update_frame_rate(AVCodecContext *avctx, QSVEncContext *q)
return updated;
}
+static int update_bitrate(AVCodecContext *avctx, QSVEncContext *q)
+{
+ int updated = 0;
+ int target_bitrate_kbps, max_bitrate_kbps, brc_param_multiplier;
+ int buffer_size_in_kilobytes, initial_delay_in_kilobytes;
+
+ UPDATE_PARAM(q->old_rc_buffer_size, avctx->rc_buffer_size);
+ UPDATE_PARAM(q->old_rc_initial_buffer_occupancy, avctx->rc_initial_buffer_occupancy);
+ UPDATE_PARAM(q->old_bit_rate, avctx->bit_rate);
+ UPDATE_PARAM(q->old_rc_max_rate, avctx->rc_max_rate);
+ if (!updated)
+ return 0;
+
+ buffer_size_in_kilobytes = avctx->rc_buffer_size / 8000;
+ initial_delay_in_kilobytes = avctx->rc_initial_buffer_occupancy / 8000;
+ target_bitrate_kbps = avctx->bit_rate / 1000;
+ max_bitrate_kbps = avctx->rc_max_rate / 1000;
+ brc_param_multiplier = (FFMAX(FFMAX3(target_bitrate_kbps, max_bitrate_kbps, buffer_size_in_kilobytes),
+ initial_delay_in_kilobytes) + 0x10000) / 0x10000;
+
+ q->param.mfx.BufferSizeInKB = buffer_size_in_kilobytes / brc_param_multiplier;
+ q->param.mfx.InitialDelayInKB = initial_delay_in_kilobytes / brc_param_multiplier;
+ q->param.mfx.TargetKbps = target_bitrate_kbps / brc_param_multiplier;
+ q->param.mfx.MaxKbps = max_bitrate_kbps / brc_param_multiplier;
+ q->param.mfx.BRCParamMultiplier = brc_param_multiplier;
+ av_log(avctx, AV_LOG_VERBOSE,
+ "Reset BufferSizeInKB: %d; InitialDelayInKB: %d; "
+ "TargetKbps: %d; MaxKbps: %d; BRCParamMultiplier: %d\n",
+ q->param.mfx.BufferSizeInKB, q->param.mfx.InitialDelayInKB,
+ q->param.mfx.TargetKbps, q->param.mfx.MaxKbps, q->param.mfx.BRCParamMultiplier);
+ return updated;
+}
+
static int update_parameters(AVCodecContext *avctx, QSVEncContext *q,
const AVFrame *frame)
{
@@ -1877,6 +1914,7 @@ static int update_parameters(AVCodecContext *avctx, QSVEncContext *q,
needReset |= update_rir(avctx, q);
needReset |= update_low_delay_brc(avctx, q);
needReset |= update_frame_rate(avctx, q);
+ needReset |= update_bitrate(avctx, q);
ret = update_min_max_qp(avctx, q);
if (ret < 0)
return ret;
diff --git a/libavcodec/qsvenc.h b/libavcodec/qsvenc.h
index 960197f159..6e1132d2e3 100644
--- a/libavcodec/qsvenc.h
+++ b/libavcodec/qsvenc.h
@@ -273,6 +273,11 @@ typedef struct QSVEncContext {
int old_low_delay_brc;
// This is used for framerate reset
AVRational old_framerate;
+ // These are used for bitrate control reset
+ int old_bit_rate;
+ int old_rc_buffer_size;
+ int old_rc_initial_buffer_occupancy;
+ int old_rc_max_rate;
} QSVEncContext;
int ff_qsv_enc_init(AVCodecContext *avctx, QSVEncContext *q);
--
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] 4+ messages in thread
* [FFmpeg-devel] [PATCH 3/3] libavcodec/qsvenc: Add pic_timing_sei reset support to qsv
2022-09-23 2:44 [FFmpeg-devel] [PATCH 1/3] libavcodec/qsvenc: Add framerate reset support to qsv Wenbin Chen
2022-09-23 2:44 ` [FFmpeg-devel] [PATCH 2/3] libavcodec/qsvenc: Add bitrate reset support to qsvenc Wenbin Chen
@ 2022-09-23 2:44 ` Wenbin Chen
2022-09-27 4:15 ` [FFmpeg-devel] [PATCH 1/3] libavcodec/qsvenc: Add framerate " Xiang, Haihao
2 siblings, 0 replies; 4+ messages in thread
From: Wenbin Chen @ 2022-09-23 2:44 UTC (permalink / raw)
To: ffmpeg-devel
Signed-off-by: Wenbin Chen <wenbin.chen@intel.com>
---
doc/encoders.texi | 4 ++++
libavcodec/qsvenc.c | 21 +++++++++++++++++++++
libavcodec/qsvenc.h | 2 ++
3 files changed, 27 insertions(+)
diff --git a/doc/encoders.texi b/doc/encoders.texi
index 2b6412dbec..741d545ea1 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -3369,6 +3369,10 @@ Change this value to reset qsv codec's framerate configuration.
@item @var{rc_initial_buffer_occupancy}
@item @var{rc_max_rate}
Change these value to reset qsv codec's bitrate control configuration.
+
+@item @var{pic_timing_sei}
+Supported in h264_qsv and hevc_qsv.
+Change this value to reset qsv codec's pic_timing_sei configuration.
@end table
@subsection H264 options
diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index 3371711872..c1a601f0b3 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -784,6 +784,7 @@ static int init_video_param(AVCodecContext *avctx, QSVEncContext *q)
q->extco.PicTimingSEI = q->pic_timing_sei ?
MFX_CODINGOPTION_ON : MFX_CODINGOPTION_UNKNOWN;
+ q->old_pic_timing_sei = q->pic_timing_sei;
if (q->rdo >= 0)
q->extco.RateDistortionOpt = q->rdo > 0 ? MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF;
@@ -1900,6 +1901,25 @@ static int update_bitrate(AVCodecContext *avctx, QSVEncContext *q)
return updated;
}
+static int update_pic_timing_sei(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_pic_timing_sei, q->pic_timing_sei);
+ if (!updated)
+ return 0;
+
+ q->extco.PicTimingSEI = q->pic_timing_sei ?
+ MFX_CODINGOPTION_ON : MFX_CODINGOPTION_UNKNOWN;
+ av_log(avctx, AV_LOG_DEBUG, "Reset PicTimingSEI: %s\n",
+ print_threestate(q->extco.PicTimingSEI));
+
+ return updated;
+}
+
static int update_parameters(AVCodecContext *avctx, QSVEncContext *q,
const AVFrame *frame)
{
@@ -1915,6 +1935,7 @@ static int update_parameters(AVCodecContext *avctx, QSVEncContext *q,
needReset |= update_low_delay_brc(avctx, q);
needReset |= update_frame_rate(avctx, q);
needReset |= update_bitrate(avctx, q);
+ needReset |= update_pic_timing_sei(avctx, q);
ret = update_min_max_qp(avctx, q);
if (ret < 0)
return ret;
diff --git a/libavcodec/qsvenc.h b/libavcodec/qsvenc.h
index 6e1132d2e3..486c996fc6 100644
--- a/libavcodec/qsvenc.h
+++ b/libavcodec/qsvenc.h
@@ -278,6 +278,8 @@ typedef struct QSVEncContext {
int old_rc_buffer_size;
int old_rc_initial_buffer_occupancy;
int old_rc_max_rate;
+ // This is used for SEI Timing reset
+ int old_pic_timing_sei;
} QSVEncContext;
int ff_qsv_enc_init(AVCodecContext *avctx, QSVEncContext *q);
--
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] 4+ messages in thread
* Re: [FFmpeg-devel] [PATCH 1/3] libavcodec/qsvenc: Add framerate reset support to qsv
2022-09-23 2:44 [FFmpeg-devel] [PATCH 1/3] libavcodec/qsvenc: Add framerate reset support to qsv Wenbin Chen
2022-09-23 2:44 ` [FFmpeg-devel] [PATCH 2/3] libavcodec/qsvenc: Add bitrate reset support to qsvenc Wenbin Chen
2022-09-23 2:44 ` [FFmpeg-devel] [PATCH 3/3] libavcodec/qsvenc: Add pic_timing_sei reset support to qsv Wenbin Chen
@ 2022-09-27 4:15 ` Xiang, Haihao
2 siblings, 0 replies; 4+ messages in thread
From: Xiang, Haihao @ 2022-09-27 4:15 UTC (permalink / raw)
To: ffmpeg-devel
On Fri, 2022-09-23 at 10:44 +0800, Wenbin Chen wrote:
> Signed-off-by: Wenbin Chen <wenbin.chen@intel.com>
> ---
> doc/encoders.texi | 3 +++
> libavcodec/qsvenc.c | 26 ++++++++++++++++++++++++++
> libavcodec/qsvenc.h | 2 ++
> 3 files changed, 31 insertions(+)
>
> diff --git a/doc/encoders.texi b/doc/encoders.texi
> index ac71f50ad2..4ed7ce1bb0 100644
> --- a/doc/encoders.texi
> +++ b/doc/encoders.texi
> @@ -3360,6 +3360,9 @@ Change these value to reset qsv codec's max/min qp
> configuration.
> @item @var{low_delay_brc}
> Supported in h264_qsv and hevc_qsv.
> Change this value to reset qsv codec's low_delay_brc configuration.
> +
> +@item @var{framerate}
> +Change this value to reset qsv codec's framerate configuration.
> @end table
>
> @subsection H264 options
> diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
> index 84c6e292aa..ce00cd302b 100644
> --- a/libavcodec/qsvenc.c
> +++ b/libavcodec/qsvenc.c
> @@ -705,6 +705,7 @@ static int init_video_param(AVCodecContext *avctx,
> QSVEncContext *q)
> q->param.mfx.FrameInfo.FrameRateExtN = avctx->time_base.den;
> q->param.mfx.FrameInfo.FrameRateExtD = avctx->time_base.num;
> }
> + q->old_framerate = avctx->framerate;
>
> ret = select_rc_mode(avctx, q);
> if (ret < 0)
> @@ -1838,6 +1839,30 @@ static int update_low_delay_brc(AVCodecContext *avctx,
> QSVEncContext *q)
> return updated;
> }
>
> +static int update_frame_rate(AVCodecContext *avctx, QSVEncContext *q)
> +{
> + int updated = 0;
> +
> + UPDATE_PARAM(q->old_framerate.num, avctx->framerate.num);
> + UPDATE_PARAM(q->old_framerate.den, avctx->framerate.den);
> + if (!updated)
> + return 0;
> +
> + if (avctx->framerate.den > 0 && avctx->framerate.num > 0) {
> + q->param.mfx.FrameInfo.FrameRateExtN = avctx->framerate.num;
> + q->param.mfx.FrameInfo.FrameRateExtD = avctx->framerate.den;
> + } else {
> + q->param.mfx.FrameInfo.FrameRateExtN = avctx->time_base.den;
> + q->param.mfx.FrameInfo.FrameRateExtD = avctx->time_base.num;
> + }
> + av_log(avctx, AV_LOG_DEBUG, "Reset framerate: %d/%d (%.2f fps).\n",
> + q->param.mfx.FrameInfo.FrameRateExtN,
> + q->param.mfx.FrameInfo.FrameRateExtD,
> + (double)q->param.mfx.FrameInfo.FrameRateExtN / q-
> >param.mfx.FrameInfo.FrameRateExtD);
> +
> + return updated;
> +}
> +
> static int update_parameters(AVCodecContext *avctx, QSVEncContext *q,
> const AVFrame *frame)
> {
> @@ -1851,6 +1876,7 @@ static int update_parameters(AVCodecContext *avctx,
> QSVEncContext *q,
> needReset |= update_gop_size(avctx, q);
> needReset |= update_rir(avctx, q);
> needReset |= update_low_delay_brc(avctx, q);
> + needReset |= update_frame_rate(avctx, q);
> ret = update_min_max_qp(avctx, q);
> if (ret < 0)
> return ret;
> diff --git a/libavcodec/qsvenc.h b/libavcodec/qsvenc.h
> index f2b7ee361f..960197f159 100644
> --- a/libavcodec/qsvenc.h
> +++ b/libavcodec/qsvenc.h
> @@ -271,6 +271,8 @@ typedef struct QSVEncContext {
> int old_min_qp_b;
> // This is used for low_delay_brc reset
> int old_low_delay_brc;
> + // This is used for framerate reset
> + AVRational old_framerate;
> } QSVEncContext;
>
> int ff_qsv_enc_init(AVCodecContext *avctx, QSVEncContext *q);
Patchset 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] 4+ messages in thread