avformat/demux: discard trimming samples in codecs with fixed frame size

When a demuxer reports the last packet with a duration smaller than the real coded duration,
this information is not relayed to the decoder, which will happily output all the trimming
samples anyway.
Fix that by ensuring we export a discard padding information as side data.

Signed-off-by: James Almer <jamrial@gmail.com>
This commit is contained in:
James Almer
2026-06-10 18:19:09 -03:00
parent 47b4be8865
commit 68b53a8dbf

View File

@@ -1536,7 +1536,7 @@ static int read_frame_internal(AVFormatContext *s, AVPacket *pkt)
if (sti->first_discard_sample && pkt->pts != AV_NOPTS_VALUE) {
int64_t pts = pkt->pts - (is_relative(pkt->pts) ? RELATIVE_TS_BASE : 0);
int64_t sample = ts_to_samples(st, pts);
int64_t duration = ts_to_samples(st, pkt->duration);
int64_t duration = FFMAX(st->codecpar->frame_size, ts_to_samples(st, pkt->duration));
int64_t end_sample = sample + duration;
if (duration > 0 && end_sample >= sti->first_discard_sample &&
sample < sti->last_discard_sample)