[FFmpeg-devel] [PATCH] avcodec/svt-av1: Set pic_type only when gop_size == 1
Vignesh Venkatasubramanian
vigneshv at google.com
Thu Sep 28 01:13:58 EEST 2023
SVT-AV1 does not support requesting keyframes at arbitrary points
by setting pic_type to EB_AV1_KEY_PICTURE.
This patch changes the following:
* Set pic_type to EB_AV1_KEY_PICTURE only when gop_size == 1. This
only has an effect in this case (combined with force_key_frames).
In all other cases, setting this has no effect.
* Set force_key_frames to 1 only when gop_size == 1, this is
needed for pic_type request above to work.
Please see the comments in
https://gitlab.com/AOMediaCodec/SVT-AV1/-/issues/2076 for a bit more
details.
Signed-off-by: Vignesh Venkatasubramanian <vigneshv at google.com>
---
libavcodec/libsvtav1.c | 22 +++++++---------------
1 file changed, 7 insertions(+), 15 deletions(-)
diff --git a/libavcodec/libsvtav1.c b/libavcodec/libsvtav1.c
index 5015169244..3247c30f60 100644
--- a/libavcodec/libsvtav1.c
+++ b/libavcodec/libsvtav1.c
@@ -253,8 +253,11 @@ static int config_enc_params(EbSvtAv1EncConfiguration *param,
// In order for SVT-AV1 to force keyframes by setting pic_type to
// EB_AV1_KEY_PICTURE on any frame, force_key_frames has to be set. Note
// that this does not force all frames to be keyframes (it only forces a
- // keyframe with pic_type is set to EB_AV1_KEY_PICTURE).
- param->force_key_frames = 1;
+ // keyframe with pic_type is set to EB_AV1_KEY_PICTURE). As of now, SVT-AV1
+ // does not support arbitrary keyframe requests by setting pic_type to
+ // EB_AV1_KEY_PICTURE, so it is done only when gop_size == 1.
+ if (avctx->gop_size == 1)
+ param->force_key_frames = 1;
if (avctx->framerate.num > 0 && avctx->framerate.den > 0) {
param->frame_rate_numerator = avctx->framerate.num;
@@ -462,19 +465,8 @@ static int eb_send_frame(AVCodecContext *avctx, const AVFrame *frame)
headerPtr->flags = 0;
headerPtr->p_app_private = NULL;
headerPtr->pts = frame->pts;
-
- switch (frame->pict_type) {
- case AV_PICTURE_TYPE_I:
- headerPtr->pic_type = EB_AV1_KEY_PICTURE;
- break;
- default:
- // Actually means auto, or default.
- headerPtr->pic_type = EB_AV1_INVALID_PICTURE;
- break;
- }
-
- if (avctx->gop_size == 1)
- headerPtr->pic_type = EB_AV1_KEY_PICTURE;
+ // EB_AV1_INVALID_PICTURE means auto, or default.
+ headerPtr->pic_type = (avctx->gop_size == 1) ? EB_AV1_KEY_PICTURE : EB_AV1_INVALID_PICTURE;
svt_av1_enc_send_picture(svt_enc->svt_handle, headerPtr);
--
2.42.0.515.g380fc7ccd1-goog
More information about the ffmpeg-devel
mailing list