PR #26212 opened by Pu Cheng (GeekQAQ)
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26212
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26212.patch

avcodec_open2() initializes AVCodecInternal.skip_samples to
avctx->delay, and AV_PKT_DATA_SKIP_SAMPLES side data adds to it. The
generic flush does not reset it, so after avcodec_flush_buffers()
samples that the previous stream still had to skip are dropped from the
start of the next stream, and once the initial delay (e.g. the Opus
pre-skip) has been skipped it is not skipped again.

Restore it to avctx->delay on flush, as after opening the decoder.

Signed-off-by: Pu Cheng <[email protected]>



>From 1f700f51f3a27bfe03d80cdf1e1480ebc4ea5618 Mon Sep 17 00:00:00 2001
From: Pu Cheng <[email protected]>
Date: Fri, 20 Nov 2026 14:08:21 +0800
Subject: [PATCH] avcodec/decode: reset skip_samples in
 ff_decode_flush_buffers()

avcodec_open2() initializes AVCodecInternal.skip_samples to
avctx->delay, and AV_PKT_DATA_SKIP_SAMPLES side data adds to it. The
generic flush does not reset it, so after avcodec_flush_buffers()
samples that the previous stream still had to skip are dropped from the
start of the next stream, and once the initial delay (e.g. the Opus
pre-skip) has been skipped it is not skipped again.

Restore it to avctx->delay on flush, as after opening the decoder.

Signed-off-by: Pu Cheng <[email protected]>
---
 libavcodec/decode.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index 2696f8f916b..a410190c092 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -2426,6 +2426,9 @@ av_cold void ff_decode_flush_buffers(AVCodecContext 
*avctx)
 
     dc->nb_draining_errors = 0;
     dc->draining_started   = 0;
+
+    /* Restore the value set by avcodec_open2(). */
+    avci->skip_samples = avctx->delay;
 }
 
 av_cold AVCodecInternal *ff_decode_internal_alloc(void)
-- 
2.54.1

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to