PR #21628 opened by James Almer (jamrial)
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21628
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21628.patch

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


>From e4cc536f99d0fce8b962361c6d7878c076d62823 Mon Sep 17 00:00:00 2001
From: James Almer <[email protected]>
Date: Mon, 2 Feb 2026 13:38:07 -0300
Subject: [PATCH] avformat/demux: don't overwrite already set packet durations
 with parser ones

Following up on b613eebe78de, 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 <[email protected]>
---
 libavformat/demux.c                          | 2 +-
 tests/ref/fate/matroska-encoding-delay       | 2 +-
 tests/ref/fate/matroska-flac-channel-mapping | 8 ++++----
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/libavformat/demux.c b/libavformat/demux.c
index c68334e1ab..db8f14ad0d 100644
--- a/libavformat/demux.c
+++ b/libavformat/demux.c
@@ -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 
},
diff --git a/tests/ref/fate/matroska-encoding-delay 
b/tests/ref/fate/matroska-encoding-delay
index cfa1675b94..31d00882a4 100644
--- a/tests/ref/fate/matroska-encoding-delay
+++ b/tests/ref/fate/matroska-encoding-delay
@@ -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
diff --git a/tests/ref/fate/matroska-flac-channel-mapping 
b/tests/ref/fate/matroska-flac-channel-mapping
index 25627d6570..91a778853f 100644
--- a/tests/ref/fate/matroska-flac-channel-mapping
+++ b/tests/ref/fate/matroska-flac-channel-mapping
@@ -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
-- 
2.52.0

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

Reply via email to