avformat/demux: don't overwrite already set packet durations with parser ones

Following up on b613eebe78, if a demuxer that exports complete frames sets a
duration, don't overwrite it from the output of the parser.

Signed-off-by: James Almer <jamrial@gmail.com>
This commit is contained in:
James Almer
2026-02-02 13:38:07 -03:00
parent 8f57b04fe5
commit 1dd8547193
3 changed files with 6 additions and 6 deletions

View File

@@ -1265,7 +1265,7 @@ static int parse_packet(AVFormatContext *s, AVPacket *pkt,
/* set the duration */
out_pkt->duration = (sti->parser->flags & PARSER_FLAG_COMPLETE_FRAMES) ? pkt->duration : 0;
if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
if (sti->avctx->sample_rate > 0 && sti->parser->duration > 0) {
if (sti->avctx->sample_rate > 0 && !out_pkt->duration && sti->parser->duration > 0) {
out_pkt->duration =
av_rescale_q_rnd(sti->parser->duration,
(AVRational) { 1, sti->avctx->sample_rate },

View File

@@ -21,7 +21,7 @@ ece637ed28526724c88f5c69b8bf7d6f *tests/data/fate/matroska-encoding-delay.matros
1, 86, 86, 24, 1152, 0xc9e85398
1, 110, 110, 24, 1152, 0xda1287d3
0, 120, 120, 40, 238290, 0xbe18b18f
1, 134, 134, 24, 1152, 0x1c9a6102
1, 134, 134, 16, 1152, 0x1c9a6102
[PACKET]
codec_type=audio
stream_index=1

View File

@@ -16,16 +16,16 @@
1, 4096, 4096, 4096, 26, 0x50d30416
0, 8192, 8192, 4096, 26, 0x51ee046f
1, 8192, 8192, 4096, 26, 0x51ee046f
0, 12288, 12288, 4096, 26, 0x521d0458
1, 12288, 12288, 4096, 26, 0x521d0458
0, 12288, 12288, 4097, 26, 0x521d0458
1, 12288, 12288, 4097, 26, 0x521d0458
0, 16385, 16385, 4096, 26, 0x531c043d
1, 16385, 16385, 4096, 26, 0x531c043d
0, 20481, 20481, 4096, 26, 0x53cf0442
1, 20481, 20481, 4096, 26, 0x53cf0442
0, 24577, 24577, 4096, 26, 0x536a0473
1, 24577, 24577, 4096, 26, 0x536a0473
0, 28673, 28673, 4096, 26, 0x5321046c
1, 28673, 28673, 4096, 26, 0x5321046c
0, 28673, 28673, 4097, 26, 0x5321046c
1, 28673, 28673, 4097, 26, 0x5321046c
0, 32770, 32770, 4096, 26, 0x51b00449
1, 32770, 32770, 4096, 26, 0x51b00449
0, 36866, 36866, 4096, 26, 0x518b042e