Commit 9dbc65bd60 for ffmpeg
commit 9dbc65bd601ecddf35a6ec46c11d4572bcf3764a
Author: Romain Beauxis <romain.beauxis@gmail.com>
Date: Fri Oct 16 03:45:07 2026 +0200
avcodec/decode: discard the padding when it overlaps the skipped samples
AV_PKT_DATA_SKIP_SAMPLES gives the samples to skip at the start of a
frame and the padding to discard at its end. When both apply to the same
frame and overlap, the padding was compared with what was left after the
skip, found too large, and ignored, so the padding was output.
Check the padding against the whole frame, then discard what is left of
it after the skip.
The overlapping case of the api-skip-samples test now outputs nothing
instead of the padding.
diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index b378715932..e4922cefcd 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -324,6 +324,7 @@ static int discard_samples(AVCodecContext *avctx, AVFrame *frame, int64_t *disca
AVCodecInternal *avci = avctx->internal;
AVFrameSideData *side;
uint32_t discard_padding = 0;
+ int nb_samples = frame->nb_samples;
uint8_t skip_reason = 0;
uint8_t discard_reason = 0;
@@ -399,7 +400,9 @@ static int discard_samples(AVCodecContext *avctx, AVFrame *frame, int64_t *disca
}
}
- if (discard_padding > 0 && discard_padding <= frame->nb_samples) {
+ if (discard_padding > 0 && discard_padding <= nb_samples) {
+ // The padding may overlap the samples skipped at the start.
+ discard_padding = FFMIN(discard_padding, frame->nb_samples);
if (discard_padding == frame->nb_samples) {
av_log(avctx, AV_LOG_DEBUG, "discard whole frame\n");
*discarded_samples += frame->nb_samples;
diff --git a/tests/ref/fate/api-skip-samples b/tests/ref/fate/api-skip-samples
index b182d5dcdf..49734c185a 100644
--- a/tests/ref/fate/api-skip-samples
+++ b/tests/ref/fate/api-skip-samples
@@ -3,5 +3,5 @@ frame 1000 skip 300 discard 0: 700 samples
frame 1000 skip 0 discard 400: 600 samples
frame 1000 skip 300 discard 400: 300 samples
frame 1000 skip 300 discard 700: 0 samples
-frame 1000 skip 300 discard 800: 700 samples
+frame 1000 skip 300 discard 800: 0 samples
frame 1000 skip 300 discard 1100: 700 samples