* [FFmpeg-devel] [PATCH v2 1/7] libavcodec/qsvenc: skip parameter resetting on mjpeg_qsv
@ 2022-09-06 9:22 Wenbin Chen
2022-09-06 9:22 ` [FFmpeg-devel] [PATCH v2 2/7] libavcodec/qsvenc: Add max_frame_size reset support to qsv Wenbin Chen
` (6 more replies)
0 siblings, 7 replies; 8+ messages in thread
From: Wenbin Chen @ 2022-09-06 9:22 UTC (permalink / raw)
To: ffmpeg-devel
mjpeg_qsv don't support dynamic resetting, so skip it.
Signed-off-by: Wenbin Chen <wenbin.chen@intel.com>
---
libavcodec/qsvenc.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index 7ac5390f10..842cfb845e 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -1680,7 +1680,7 @@ static int update_parameters(AVCodecContext *avctx, QSVEncContext *q,
{
int needReset = 0, ret = 0;
- if (!frame)
+ if (!frame || avctx->codec_id == AV_CODEC_ID_MJPEG)
return 0;
needReset = update_qp(avctx, 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] 8+ messages in thread
* [FFmpeg-devel] [PATCH v2 2/7] libavcodec/qsvenc: Add max_frame_size reset support to qsv
2022-09-06 9:22 [FFmpeg-devel] [PATCH v2 1/7] libavcodec/qsvenc: skip parameter resetting on mjpeg_qsv Wenbin Chen
@ 2022-09-06 9:22 ` Wenbin Chen
2022-09-06 9:22 ` [FFmpeg-devel] [PATCH v2 3/7] libavcodec/qsvenc: Add gop_size reset support to qsvenc Wenbin Chen
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Wenbin Chen @ 2022-09-06 9:22 UTC (permalink / raw)
To: ffmpeg-devel
Signed-off-by: Wenbin Chen <wenbin.chen@intel.com>
---
doc/encoders.texi | 4 ++++
libavcodec/qsvenc.c | 20 ++++++++++++++++++++
libavcodec/qsvenc.h | 2 ++
3 files changed, 26 insertions(+)
diff --git a/doc/encoders.texi b/doc/encoders.texi
index d36464d629..aadb6ab9fd 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -3344,6 +3344,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 842cfb845e..915a1abd26 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -824,6 +824,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)
@@ -1675,6 +1676,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)
{
@@ -1684,6 +1703,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 a983651dda..3984ae7dd8 100644
--- a/libavcodec/qsvenc.h
+++ b/libavcodec/qsvenc.h
@@ -249,6 +249,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);
--
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] 8+ messages in thread
* [FFmpeg-devel] [PATCH v2 3/7] libavcodec/qsvenc: Add gop_size reset support to qsvenc
2022-09-06 9:22 [FFmpeg-devel] [PATCH v2 1/7] libavcodec/qsvenc: skip parameter resetting on mjpeg_qsv Wenbin Chen
2022-09-06 9:22 ` [FFmpeg-devel] [PATCH v2 2/7] libavcodec/qsvenc: Add max_frame_size reset support to qsv Wenbin Chen
@ 2022-09-06 9:22 ` Wenbin Chen
2022-09-06 9:22 ` [FFmpeg-devel] [PATCH v2 4/7] libavcodec/qsvenc: Add "slice" intra refresh type " Wenbin Chen
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Wenbin Chen @ 2022-09-06 9:22 UTC (permalink / raw)
To: ffmpeg-devel
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 --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);
--
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] 8+ messages in thread
* [FFmpeg-devel] [PATCH v2 4/7] libavcodec/qsvenc: Add "slice" intra refresh type to qsvenc
2022-09-06 9:22 [FFmpeg-devel] [PATCH v2 1/7] libavcodec/qsvenc: skip parameter resetting on mjpeg_qsv Wenbin Chen
2022-09-06 9:22 ` [FFmpeg-devel] [PATCH v2 2/7] libavcodec/qsvenc: Add max_frame_size reset support to qsv Wenbin Chen
2022-09-06 9:22 ` [FFmpeg-devel] [PATCH v2 3/7] libavcodec/qsvenc: Add gop_size reset support to qsvenc Wenbin Chen
@ 2022-09-06 9:22 ` Wenbin Chen
2022-09-06 9:22 ` [FFmpeg-devel] [PATCH v2 5/7] libavcodec/qsvenc: Add intra refresh reset support " Wenbin Chen
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Wenbin Chen @ 2022-09-06 9:22 UTC (permalink / raw)
To: ffmpeg-devel
Add "slice" intra refresh type to h264_qsv and hevc_qsv. This type means
horizontal refresh by slices without overlapping. Also update the doc.
Signed-off-by: Wenbin Chen <wenbin.chen@intel.com>
---
doc/encoders.texi | 12 ++++++++----
libavcodec/qsvenc_h264.c | 1 +
libavcodec/qsvenc_hevc.c | 1 +
3 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/doc/encoders.texi b/doc/encoders.texi
index bc1a4dae38..d5d695d39c 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -3454,8 +3454,10 @@ Specifies intra refresh type. The major goal of intra refresh is improvement of
error resilience without significant impact on encoded bitstream size caused by
I frames. The SDK encoder achieves this by encoding part of each frame in
refresh cycle using intra MBs. @var{none} means no refresh. @var{vertical} means
-vertical refresh, by column of MBs. To enable intra refresh, B frame should be
-set to 0.
+vertical refresh, by column of MBs. @var{horizontal} means horizontal refresh,
+by rows of MBs. @var{slice} means horizontal refresh by slices without
+overlapping. In case of @var{slice}, in_ref_cycle_size is ignored. To enable
+intra refresh, B frame should be set to 0.
@item @var{int_ref_cycle_size}
Specifies number of pictures within refresh cycle starting from 2. 0 and 1 are
@@ -3641,8 +3643,10 @@ Specifies intra refresh type. The major goal of intra refresh is improvement of
error resilience without significant impact on encoded bitstream size caused by
I frames. The SDK encoder achieves this by encoding part of each frame in
refresh cycle using intra MBs. @var{none} means no refresh. @var{vertical} means
-vertical refresh, by column of MBs. To enable intra refresh, B frame should be
-set to 0.
+vertical refresh, by column of MBs. @var{horizontal} means horizontal refresh,
+by rows of MBs. @var{slice} means horizontal refresh by slices without
+overlapping. In case of @var{slice}, in_ref_cycle_size is ignored. To enable
+intra refresh, B frame should be set to 0.
@item @var{int_ref_cycle_size}
Specifies number of pictures within refresh cycle starting from 2. 0 and 1 are
diff --git a/libavcodec/qsvenc_h264.c b/libavcodec/qsvenc_h264.c
index 1bbdc45203..8bc4ef95d2 100644
--- a/libavcodec/qsvenc_h264.c
+++ b/libavcodec/qsvenc_h264.c
@@ -139,6 +139,7 @@ static const AVOption options[] = {
{ "none", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 0 }, .flags = VE, "int_ref_type" },
{ "vertical", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 1 }, .flags = VE, "int_ref_type" },
{ "horizontal", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 2 }, .flags = VE, "int_ref_type" },
+ { "slice" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 3 }, .flags = VE, "int_ref_type" },
{ "int_ref_cycle_size", "Number of frames in the intra refresh cycle", OFFSET(qsv.int_ref_cycle_size), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, UINT16_MAX, VE },
{ "int_ref_qp_delta", "QP difference for the refresh MBs", OFFSET(qsv.int_ref_qp_delta), AV_OPT_TYPE_INT, { .i64 = INT16_MIN }, INT16_MIN, INT16_MAX, VE },
{ "recovery_point_sei", "Insert recovery point SEI messages", OFFSET(qsv.recovery_point_sei), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1, VE },
diff --git a/libavcodec/qsvenc_hevc.c b/libavcodec/qsvenc_hevc.c
index 5986c3f1a6..ba7cb6fba6 100644
--- a/libavcodec/qsvenc_hevc.c
+++ b/libavcodec/qsvenc_hevc.c
@@ -270,6 +270,7 @@ static const AVOption options[] = {
{ "none", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 0 }, .flags = VE, "int_ref_type" },
{ "vertical", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 1 }, .flags = VE, "int_ref_type" },
{ "horizontal", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 2 }, .flags = VE, "int_ref_type" },
+ { "slice" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 3 }, .flags = VE, "int_ref_type" },
{ "int_ref_cycle_size", "Number of frames in the intra refresh cycle", OFFSET(qsv.int_ref_cycle_size), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, UINT16_MAX, VE },
{ "int_ref_qp_delta", "QP difference for the refresh MBs", OFFSET(qsv.int_ref_qp_delta), AV_OPT_TYPE_INT, { .i64 = INT16_MIN }, INT16_MIN, INT16_MAX, VE },
{ "int_ref_cycle_dist", "Distance between the beginnings of the intra-refresh cycles in frames", OFFSET(qsv.int_ref_cycle_dist), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT16_MAX, VE },
--
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] 8+ messages in thread
* [FFmpeg-devel] [PATCH v2 5/7] libavcodec/qsvenc: Add intra refresh reset support to qsvenc
2022-09-06 9:22 [FFmpeg-devel] [PATCH v2 1/7] libavcodec/qsvenc: skip parameter resetting on mjpeg_qsv Wenbin Chen
` (2 preceding siblings ...)
2022-09-06 9:22 ` [FFmpeg-devel] [PATCH v2 4/7] libavcodec/qsvenc: Add "slice" intra refresh type " Wenbin Chen
@ 2022-09-06 9:22 ` Wenbin Chen
2022-09-06 9:22 ` [FFmpeg-devel] [PATCH v2 6/7] libavcodec/qsvenc: Add max/min qp reset support in qsvenc Wenbin Chen
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Wenbin Chen @ 2022-09-06 9:22 UTC (permalink / raw)
To: ffmpeg-devel
Signed-off-by: Wenbin Chen <wenbin.chen@intel.com>
---
doc/encoders.texi | 7 +++++++
libavcodec/qsvenc.c | 33 +++++++++++++++++++++++++++++++++
libavcodec/qsvenc.h | 5 +++++
3 files changed, 45 insertions(+)
diff --git a/doc/encoders.texi b/doc/encoders.texi
index d5d695d39c..da56159858 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -3351,6 +3351,13 @@ Change this value to reset qsv codec's MaxFrameSize configuration.
@item @var{gop_size}
Change this value to reset qsv codec's gop configuration.
+
+@item @var{int_ref_type}
+@item @var{int_ref_cycle_size}
+@item @var{int_ref_qp_delta}
+@item @var{int_ref_cycle_dist}
+Supported in h264_qsv and hevc_qsv.
+Change these value to reset qsv codec's Intra Refresh configuration.
@end table
@subsection H264 options
diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index 9a0431630a..cd0549b249 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -828,10 +828,13 @@ static int init_video_param(AVCodecContext *avctx, QSVEncContext *q)
q->old_max_frame_size = q->max_frame_size;
if (q->int_ref_type >= 0)
q->extco2.IntRefType = q->int_ref_type;
+ q->old_int_ref_type = q->int_ref_type;
if (q->int_ref_cycle_size >= 0)
q->extco2.IntRefCycleSize = q->int_ref_cycle_size;
+ q->old_int_ref_cycle_size = q->int_ref_cycle_size;
if (q->int_ref_qp_delta != INT16_MIN)
q->extco2.IntRefQPDelta = q->int_ref_qp_delta;
+ q->old_int_ref_qp_delta = q->int_ref_qp_delta;
if (q->max_slice_size >= 0)
q->extco2.MaxSliceSize = q->max_slice_size;
q->extco2.DisableDeblockingIdc = q->dblk_idc;
@@ -920,6 +923,7 @@ static int init_video_param(AVCodecContext *avctx, QSVEncContext *q)
}
if (q->int_ref_cycle_dist >= 0)
q->extco3.IntRefCycleDist = q->int_ref_cycle_dist;
+ q->old_int_ref_cycle_dist = q->int_ref_cycle_dist;
if (q->low_delay_brc >= 0)
q->extco3.LowDelayBRC = q->low_delay_brc ? MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF;
if (q->max_frame_size_i >= 0)
@@ -1709,6 +1713,34 @@ static int update_gop_size(AVCodecContext *avctx, QSVEncContext *q)
return updated;
}
+static int update_rir(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_int_ref_type, q->int_ref_type);
+ UPDATE_PARAM(q->old_int_ref_cycle_size, q->int_ref_cycle_size);
+ UPDATE_PARAM(q->old_int_ref_qp_delta, q->int_ref_qp_delta);
+ UPDATE_PARAM(q->old_int_ref_cycle_dist, q->int_ref_cycle_dist);
+ if (!updated)
+ return 0;
+
+ q->extco2.IntRefType = FFMAX(0, q->int_ref_type);
+ q->extco2.IntRefCycleSize = FFMAX(0, q->int_ref_cycle_size);
+ q->extco2.IntRefQPDelta =
+ q->int_ref_qp_delta != INT16_MIN ? q->int_ref_qp_delta : 0;
+ q->extco3.IntRefCycleDist = FFMAX(0, q->int_ref_cycle_dist);
+ av_log(avctx, AV_LOG_DEBUG,
+ "Reset IntRefType: %d; IntRefCycleSize: %d; "
+ "IntRefQPDelta: %d; IntRefCycleDist: %d\n",
+ q->extco2.IntRefType, q->extco2.IntRefCycleSize,
+ q->extco2.IntRefQPDelta, q->extco3.IntRefCycleDist);
+
+ return updated;
+}
+
static int update_parameters(AVCodecContext *avctx, QSVEncContext *q,
const AVFrame *frame)
{
@@ -1720,6 +1752,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);
+ needReset |= update_rir(avctx, q);
if (!needReset)
return 0;
diff --git a/libavcodec/qsvenc.h b/libavcodec/qsvenc.h
index 5f6955a3a7..2eada6ab26 100644
--- a/libavcodec/qsvenc.h
+++ b/libavcodec/qsvenc.h
@@ -253,6 +253,11 @@ typedef struct QSVEncContext {
int old_max_frame_size;
// This is used for gop reset
int old_gop_size;
+ // These are used for intra refresh reset
+ int old_int_ref_type;
+ int old_int_ref_cycle_size;
+ int old_int_ref_qp_delta;
+ int old_int_ref_cycle_dist;
} 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] 8+ messages in thread
* [FFmpeg-devel] [PATCH v2 6/7] libavcodec/qsvenc: Add max/min qp reset support in qsvenc
2022-09-06 9:22 [FFmpeg-devel] [PATCH v2 1/7] libavcodec/qsvenc: skip parameter resetting on mjpeg_qsv Wenbin Chen
` (3 preceding siblings ...)
2022-09-06 9:22 ` [FFmpeg-devel] [PATCH v2 5/7] libavcodec/qsvenc: Add intra refresh reset support " Wenbin Chen
@ 2022-09-06 9:22 ` Wenbin Chen
2022-09-06 9:22 ` [FFmpeg-devel] [PATCH v2 7/7] libavcodec/qsvenc: Add low_delay_brc reset support to qsvenc Wenbin Chen
2022-09-07 6:33 ` [FFmpeg-devel] [PATCH v2 1/7] libavcodec/qsvenc: skip parameter resetting on mjpeg_qsv Xiang, Haihao
6 siblings, 0 replies; 8+ messages in thread
From: Wenbin Chen @ 2022-09-06 9:22 UTC (permalink / raw)
To: ffmpeg-devel
Signed-off-by: Wenbin Chen <wenbin.chen@intel.com>
---
doc/encoders.texi | 11 +++++++
libavcodec/qsvenc.c | 78 +++++++++++++++++++++++++++++++++++++++++++++
libavcodec/qsvenc.h | 9 ++++++
3 files changed, 98 insertions(+)
diff --git a/doc/encoders.texi b/doc/encoders.texi
index da56159858..850e3c261c 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -3358,6 +3358,17 @@ Change this value to reset qsv codec's gop configuration.
@item @var{int_ref_cycle_dist}
Supported in h264_qsv and hevc_qsv.
Change these value to reset qsv codec's Intra Refresh configuration.
+
+@item @var{qmax}
+@item @var{qmin}
+@item @var{max_qp_i}
+@item @var{min_qp_i}
+@item @var{max_qp_p}
+@item @var{min_qp_p}
+@item @var{max_qp_b}
+@item @var{min_qp_b}
+Supported in h264_qsv.
+Change these value to reset qsv codec's max/min qp configuration.
@end table
@subsection H264 options
diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index cd0549b249..215e5930ef 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -858,22 +858,30 @@ static int init_video_param(AVCodecContext *avctx, QSVEncContext *q)
q->extco2.MinQPI = avctx->qmin > 51 ? 51 : avctx->qmin;
q->extco2.MinQPP = q->extco2.MinQPB = q->extco2.MinQPI;
}
+ q->old_qmin = avctx->qmin;
if (avctx->qmax >= 0) {
q->extco2.MaxQPI = avctx->qmax > 51 ? 51 : avctx->qmax;
q->extco2.MaxQPP = q->extco2.MaxQPB = q->extco2.MaxQPI;
}
+ q->old_qmax = avctx->qmax;
if (q->min_qp_i >= 0)
q->extco2.MinQPI = q->min_qp_i > 51 ? 51 : q->min_qp_i;
+ q->old_min_qp_i = q->min_qp_i;
if (q->max_qp_i >= 0)
q->extco2.MaxQPI = q->max_qp_i > 51 ? 51 : q->max_qp_i;
+ q->old_max_qp_i = q->max_qp_i;
if (q->min_qp_p >= 0)
q->extco2.MinQPP = q->min_qp_p > 51 ? 51 : q->min_qp_p;
+ q->old_min_qp_p = q->min_qp_p;
if (q->max_qp_p >= 0)
q->extco2.MaxQPP = q->max_qp_p > 51 ? 51 : q->max_qp_p;
+ q->old_max_qp_p = q->max_qp_p;
if (q->min_qp_b >= 0)
q->extco2.MinQPB = q->min_qp_b > 51 ? 51 : q->min_qp_b;
+ q->old_min_qp_b = q->min_qp_b;
if (q->max_qp_b >= 0)
q->extco2.MaxQPB = q->max_qp_b > 51 ? 51 : q->max_qp_b;
+ q->old_max_qp_b = q->max_qp_b;
if (q->mbbrc >= 0)
q->extco2.MBBRC = q->mbbrc ? MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF;
@@ -1741,6 +1749,71 @@ static int update_rir(AVCodecContext *avctx, QSVEncContext *q)
return updated;
}
+static int update_min_max_qp(AVCodecContext *avctx, QSVEncContext *q)
+{
+ int updated = 0;
+
+ if (avctx->codec_id != AV_CODEC_ID_H264)
+ return 0;
+
+ UPDATE_PARAM(q->old_qmax, avctx->qmin);
+ UPDATE_PARAM(q->old_qmax, avctx->qmin);
+ UPDATE_PARAM(q->old_min_qp_i, q->min_qp_i);
+ UPDATE_PARAM(q->old_max_qp_i, q->max_qp_i);
+ UPDATE_PARAM(q->old_min_qp_p, q->min_qp_p);
+ UPDATE_PARAM(q->old_max_qp_p, q->max_qp_p);
+ UPDATE_PARAM(q->old_min_qp_b, q->min_qp_b);
+ UPDATE_PARAM(q->old_max_qp_b, q->max_qp_b);
+ if (!updated)
+ return 0;
+
+ if ((avctx->qmin >= 0 && avctx->qmax >= 0 && avctx->qmin > avctx->qmax) ||
+ (q->max_qp_i >= 0 && q->min_qp_i >= 0 && q->min_qp_i > q->max_qp_i) ||
+ (q->max_qp_p >= 0 && q->min_qp_p >= 0 && q->min_qp_p > q->max_qp_p) ||
+ (q->max_qp_b >= 0 && q->min_qp_b >= 0 && q->min_qp_b > q->max_qp_b)) {
+ av_log(avctx, AV_LOG_ERROR,
+ "qmin and or qmax are set but invalid,"
+ " please make sure min <= max\n");
+ return AVERROR(EINVAL);
+ }
+
+ q->extco2.MinQPI = 0;
+ q->extco2.MaxQPI = 0;
+ q->extco2.MinQPP = 0;
+ q->extco2.MaxQPP = 0;
+ q->extco2.MinQPB = 0;
+ q->extco2.MaxQPB = 0;
+ if (avctx->qmin >= 0) {
+ q->extco2.MinQPI = avctx->qmin > 51 ? 51 : avctx->qmin;
+ q->extco2.MinQPB = q->extco2.MinQPP = q->extco2.MinQPI;
+ }
+ if (avctx->qmax >= 0) {
+ q->extco2.MaxQPI = avctx->qmax > 51 ? 51 : avctx->qmax;
+ q->extco2.MaxQPB = q->extco2.MaxQPP = q->extco2.MaxQPI;
+ }
+ if (q->min_qp_i >= 0)
+ q->extco2.MinQPI = q->min_qp_i > 51 ? 51 : q->min_qp_i;
+ if (q->max_qp_i >= 0)
+ q->extco2.MaxQPI = q->max_qp_i > 51 ? 51 : q->max_qp_i;
+ if (q->min_qp_p >= 0)
+ q->extco2.MinQPP = q->min_qp_p > 51 ? 51 : q->min_qp_p;
+ if (q->max_qp_p >= 0)
+ q->extco2.MaxQPP = q->max_qp_p > 51 ? 51 : q->max_qp_p;
+ if (q->min_qp_b >= 0)
+ q->extco2.MinQPB = q->min_qp_b > 51 ? 51 : q->min_qp_b;
+ if (q->max_qp_b >= 0)
+ q->extco2.MaxQPB = q->max_qp_b > 51 ? 51 : q->max_qp_b;
+
+ av_log(avctx, AV_LOG_VERBOSE, "Reset MinQPI: %d; MaxQPI: %d; "
+ "MinQPP: %d; MaxQPP: %d; "
+ "MinQPB: %d; MaxQPB: %d\n",
+ q->extco2.MinQPI, q->extco2.MaxQPI,
+ q->extco2.MinQPP, q->extco2.MaxQPP,
+ q->extco2.MinQPB, q->extco2.MaxQPB);
+
+ return updated;
+}
+
static int update_parameters(AVCodecContext *avctx, QSVEncContext *q,
const AVFrame *frame)
{
@@ -1753,6 +1826,11 @@ static int update_parameters(AVCodecContext *avctx, QSVEncContext *q,
needReset |= update_max_frame_size(avctx, q);
needReset |= update_gop_size(avctx, q);
needReset |= update_rir(avctx, q);
+
+ ret = update_min_max_qp(avctx, q);
+ if (ret < 0)
+ return ret;
+ needReset |= ret;
if (!needReset)
return 0;
diff --git a/libavcodec/qsvenc.h b/libavcodec/qsvenc.h
index 2eada6ab26..3ed20f757b 100644
--- a/libavcodec/qsvenc.h
+++ b/libavcodec/qsvenc.h
@@ -258,6 +258,15 @@ typedef struct QSVEncContext {
int old_int_ref_cycle_size;
int old_int_ref_qp_delta;
int old_int_ref_cycle_dist;
+ // These are used for max/min qp reset;
+ int old_qmax;
+ int old_qmin;
+ int old_max_qp_i;
+ int old_min_qp_i;
+ int old_max_qp_p;
+ int old_min_qp_p;
+ int old_max_qp_b;
+ int old_min_qp_b;
} 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] 8+ messages in thread
* [FFmpeg-devel] [PATCH v2 7/7] libavcodec/qsvenc: Add low_delay_brc reset support to qsvenc
2022-09-06 9:22 [FFmpeg-devel] [PATCH v2 1/7] libavcodec/qsvenc: skip parameter resetting on mjpeg_qsv Wenbin Chen
` (4 preceding siblings ...)
2022-09-06 9:22 ` [FFmpeg-devel] [PATCH v2 6/7] libavcodec/qsvenc: Add max/min qp reset support in qsvenc Wenbin Chen
@ 2022-09-06 9:22 ` Wenbin Chen
2022-09-07 6:33 ` [FFmpeg-devel] [PATCH v2 1/7] libavcodec/qsvenc: skip parameter resetting on mjpeg_qsv Xiang, Haihao
6 siblings, 0 replies; 8+ messages in thread
From: Wenbin Chen @ 2022-09-06 9:22 UTC (permalink / raw)
To: ffmpeg-devel
Signed-off-by: Wenbin Chen <wenbin.chen@intel.com>
---
doc/encoders.texi | 4 ++++
libavcodec/qsvenc.c | 23 ++++++++++++++++++++++-
libavcodec/qsvenc.h | 2 ++
3 files changed, 28 insertions(+), 1 deletion(-)
diff --git a/doc/encoders.texi b/doc/encoders.texi
index 850e3c261c..453150f3e7 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -3369,6 +3369,10 @@ Change these value to reset qsv codec's Intra Refresh configuration.
@item @var{min_qp_b}
Supported in h264_qsv.
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.
@end table
@subsection H264 options
diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index 215e5930ef..58900d56a7 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -934,6 +934,7 @@ static int init_video_param(AVCodecContext *avctx, QSVEncContext *q)
q->old_int_ref_cycle_dist = q->int_ref_cycle_dist;
if (q->low_delay_brc >= 0)
q->extco3.LowDelayBRC = q->low_delay_brc ? MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF;
+ q->old_low_delay_brc = q->low_delay_brc;
if (q->max_frame_size_i >= 0)
q->extco3.MaxFrameSizeI = q->max_frame_size_i;
if (q->max_frame_size_p >= 0)
@@ -1814,6 +1815,26 @@ static int update_min_max_qp(AVCodecContext *avctx, QSVEncContext *q)
return updated;
}
+static int update_low_delay_brc(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_low_delay_brc, q->low_delay_brc);
+ if (!updated)
+ return 0;
+
+ q->extco3.LowDelayBRC = MFX_CODINGOPTION_UNKNOWN;
+ if (q->low_delay_brc >= 0)
+ q->extco3.LowDelayBRC = q->low_delay_brc ? MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF;
+ av_log(avctx, AV_LOG_DEBUG, "Reset LowDelayBRC: %s\n",
+ print_threestate(q->extco3.LowDelayBRC));
+
+ return updated;
+}
+
static int update_parameters(AVCodecContext *avctx, QSVEncContext *q,
const AVFrame *frame)
{
@@ -1826,7 +1847,7 @@ static int update_parameters(AVCodecContext *avctx, QSVEncContext *q,
needReset |= update_max_frame_size(avctx, q);
needReset |= update_gop_size(avctx, q);
needReset |= update_rir(avctx, q);
-
+ needReset |= update_low_delay_brc(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 3ed20f757b..54e5cf89d3 100644
--- a/libavcodec/qsvenc.h
+++ b/libavcodec/qsvenc.h
@@ -267,6 +267,8 @@ typedef struct QSVEncContext {
int old_min_qp_p;
int old_max_qp_b;
int old_min_qp_b;
+ // This is used for low_delay_brc reset
+ int old_low_delay_brc;
} 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] 8+ messages in thread
* Re: [FFmpeg-devel] [PATCH v2 1/7] libavcodec/qsvenc: skip parameter resetting on mjpeg_qsv
2022-09-06 9:22 [FFmpeg-devel] [PATCH v2 1/7] libavcodec/qsvenc: skip parameter resetting on mjpeg_qsv Wenbin Chen
` (5 preceding siblings ...)
2022-09-06 9:22 ` [FFmpeg-devel] [PATCH v2 7/7] libavcodec/qsvenc: Add low_delay_brc reset support to qsvenc Wenbin Chen
@ 2022-09-07 6:33 ` Xiang, Haihao
6 siblings, 0 replies; 8+ messages in thread
From: Xiang, Haihao @ 2022-09-07 6:33 UTC (permalink / raw)
To: ffmpeg-devel
On Tue, 2022-09-06 at 17:22 +0800, Wenbin Chen wrote:
> mjpeg_qsv don't support dynamic resetting, so skip it.
>
> Signed-off-by: Wenbin Chen <wenbin.chen@intel.com>
> ---
> libavcodec/qsvenc.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
> index 7ac5390f10..842cfb845e 100644
> --- a/libavcodec/qsvenc.c
> +++ b/libavcodec/qsvenc.c
> @@ -1680,7 +1680,7 @@ static int update_parameters(AVCodecContext *avctx,
> QSVEncContext *q,
> {
> int needReset = 0, ret = 0;
>
> - if (!frame)
> + if (!frame || avctx->codec_id == AV_CODEC_ID_MJPEG)
> return 0;
>
> needReset = update_qp(avctx, 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] 8+ messages in thread
end of thread, other threads:[~2022-09-07 6:33 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-06 9:22 [FFmpeg-devel] [PATCH v2 1/7] libavcodec/qsvenc: skip parameter resetting on mjpeg_qsv Wenbin Chen
2022-09-06 9:22 ` [FFmpeg-devel] [PATCH v2 2/7] libavcodec/qsvenc: Add max_frame_size reset support to qsv Wenbin Chen
2022-09-06 9:22 ` [FFmpeg-devel] [PATCH v2 3/7] libavcodec/qsvenc: Add gop_size reset support to qsvenc Wenbin Chen
2022-09-06 9:22 ` [FFmpeg-devel] [PATCH v2 4/7] libavcodec/qsvenc: Add "slice" intra refresh type " Wenbin Chen
2022-09-06 9:22 ` [FFmpeg-devel] [PATCH v2 5/7] libavcodec/qsvenc: Add intra refresh reset support " Wenbin Chen
2022-09-06 9:22 ` [FFmpeg-devel] [PATCH v2 6/7] libavcodec/qsvenc: Add max/min qp reset support in qsvenc Wenbin Chen
2022-09-06 9:22 ` [FFmpeg-devel] [PATCH v2 7/7] libavcodec/qsvenc: Add low_delay_brc reset support to qsvenc Wenbin Chen
2022-09-07 6:33 ` [FFmpeg-devel] [PATCH v2 1/7] libavcodec/qsvenc: skip parameter resetting on mjpeg_qsv Xiang, Haihao
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