History

libsvtav1: Add workaround for gop_size == 1

In some versions of libsvtav1, setting intra_period_length to 0 does not produce the intended result (i.e.) all frames produced are not keyframes. Instead handle the gop_size == 1 as a special case by setting the pic_type to EB_AV1_KEY_PICTURE when encoding each frame so that all the output frames are keyframes. SVT-AV1 Bug: https://gitlab.com/AOMediaCodec/SVT-AV1/-/issues/2076 Example command: ffmpeg -f lavfi -i testsrc=duration=1:size=64x64:rate=30 -c:v libsvtav1 -g 1 -y test.webm Before: Only first frame is keyframe, rest are intraonly. After: All frames are keyframes.

Vignesh Venkatasubramanian committed 3 years ago

Commit 7bcc1b41 parent a7b3c021 file · +15 −1Browse files

Unified · Split

libavcodec/libsvtav1.c+15−1
@@ -242,9 +242,20 @@ static int config_enc_params(EbSvtAv1EncConfiguration *param, · 241 unmodified lines
242242 if (avctx->level != FF_LEVEL_UNKNOWN)
243243 param->level = avctx->level;
244244
245− if (avctx->gop_size > 0)
245+ // gop_size == 1 case is handled when encoding each frame by setting
246+ // pic_type to EB_AV1_KEY_PICTURE. For gop_size > 1, set the
247+ // intra_period_length. Even though setting intra_period_length to 0 should
248+ // work in this case, it does not.
249+ // See: https://gitlab.com/AOMediaCodec/SVT-AV1/-/issues/2076
250+ if (avctx->gop_size > 1)
246251 param->intra_period_length = avctx->gop_size - 1;
247252
253+ // In order for SVT-AV1 to force keyframes by setting pic_type to
254+ // EB_AV1_KEY_PICTURE on any frame, force_key_frames has to be set. Note
255+ // that this does not force all frames to be keyframes (it only forces a
256+ // keyframe with pic_type is set to EB_AV1_KEY_PICTURE).
257+ param->force_key_frames = 1;
258+
248259 if (avctx->framerate.num > 0 && avctx->framerate.den > 0) {
249260 param->frame_rate_numerator = avctx->framerate.num;
250261 param->frame_rate_denominator = avctx->framerate.den;
@@ -462,6 +473,9 @@ static int eb_send_frame(AVCodecContext *avctx, const AVFrame *frame) · 211 unmodified lines
462473 break;
463474 }
464475
476+ if (avctx->gop_size == 1)
477+ headerPtr->pic_type = EB_AV1_KEY_PICTURE;
478+
465479 svt_av1_enc_send_picture(svt_enc->svt_handle, headerPtr);
466480
467481 return 0;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t