Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH] libsvtav1: Add workaround for gop_size == 1
@ 2023-06-26 17:47 Vignesh Venkatasubramanian
  2023-06-26 22:17 ` Ronald S. Bultje
  0 siblings, 1 reply; 11+ messages in thread
From: Vignesh Venkatasubramanian @ 2023-06-26 17:47 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Vignesh Venkatasubramanian

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.
After: All frames are keyframes.

Signed-off-by: Vignesh Venkatasubramanian <vigneshv@google.com>
---
 libavcodec/libsvtav1.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/libavcodec/libsvtav1.c b/libavcodec/libsvtav1.c
index 718a04d221..f2b73361d8 100644
--- a/libavcodec/libsvtav1.c
+++ b/libavcodec/libsvtav1.c
@@ -242,9 +242,20 @@ static int config_enc_params(EbSvtAv1EncConfiguration *param,
     if (avctx->level != FF_LEVEL_UNKNOWN)
         param->level = avctx->level;
 
-    if (avctx->gop_size > 0)
+    // gop_size == 1 case is handled when encoding each frame by setting
+    // pic_type to EB_AV1_KEY_PICTURE. For gop_size > 1, set the
+    // intra_period_length. Even though setting intra_period_length to 0 should
+    // work in this case, it does not.
+    // See: https://gitlab.com/AOMediaCodec/SVT-AV1/-/issues/2076
+    if (avctx->gop_size > 1)
         param->intra_period_length  = avctx->gop_size - 1;
 
+    // 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;
+
     if (avctx->framerate.num > 0 && avctx->framerate.den > 0) {
         param->frame_rate_numerator   = avctx->framerate.num;
         param->frame_rate_denominator = avctx->framerate.den;
@@ -462,6 +473,9 @@ static int eb_send_frame(AVCodecContext *avctx, const AVFrame *frame)
         break;
     }
 
+    if (avctx->gop_size == 1)
+        headerPtr->pic_type = EB_AV1_KEY_PICTURE;
+
     svt_av1_enc_send_picture(svt_enc->svt_handle, headerPtr);
 
     return 0;
-- 
2.41.0.162.gfafddb0af9-goog

_______________________________________________
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] 11+ messages in thread

end of thread, other threads:[~2023-07-13 21:26 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-26 17:47 [FFmpeg-devel] [PATCH] libsvtav1: Add workaround for gop_size == 1 Vignesh Venkatasubramanian
2023-06-26 22:17 ` Ronald S. Bultje
2023-06-26 22:32   ` Vignesh Venkat
2023-06-26 23:53     ` James Almer
2023-06-27 17:55       ` Vignesh Venkat
2023-06-27 19:07         ` Ronald S. Bultje
2023-06-28 16:48           ` Vignesh Venkat
2023-06-28 23:25             ` Ronald S. Bultje
2023-06-28 23:27               ` James Almer
2023-07-13 21:13                 ` Vignesh Venkat
2023-07-13 21:25                   ` Ronald S. Bultje

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