[PR] avformat/mov: don't assume a sample to be the last in fragmented input (PR #23533)

James Almer via ffmpeg-devel <[email protected]>
Newsgroups gmane.comp.video.ffmpeg.devel
Message-ID <178180130405.63.10451528897986068760@29965ddac10e>
PR #23533 opened by James Almer (jamrial)
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/23533
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/23533.patch

Both the seek index and the stream duration are constantly being updated as trun boxes are read.

Fixes mpv issue 18149.


>From 62731e05ab6f8b1aaefc33f3400952e88ada04fe Mon Sep 17 00:00:00 2001
From: James Almer <[email protected]>
Date: Thu, 18 Jun 2026 13:46:52 -0300
Subject: [PATCH] avformat/mov: don't assume a sample to be the last in
 fragmented input

Both the seek index and the stream duration are constantly being updated as
trun boxes are read.

Fixes mpv issue 18149.

Signed-off-by: James Almer <[email protected]>
---
 libavformat/mov.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index 7513b3ccc1..0915b35a7f 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -11626,6 +11626,7 @@ static int get_eia608_packet(AVIOContext *pb, AVPacket *pkt, int src_size)
 static int mov_finalize_packet(AVFormatContext *s, AVStream *st, AVIndexEntry *sample,
                                 int64_t current_index, AVPacket *pkt)
 {
+    MOVContext *mov = s->priv_data;
     MOVStreamContext *sc = st->priv_data;
 
     pkt->stream_index = sc->ffindex;
@@ -11647,7 +11648,7 @@ static int mov_finalize_packet(AVFormatContext *s, AVStream *st, AVIndexEntry *s
         pkt->pts = pkt->dts;
     }
 
-    if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO &&
+    if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && !mov->fragment.found_tfhd &&
         sc->current_sample >= ffstream(st)->nb_index_entries) {
         int64_t pts   = av_rescale_q(pkt->pts,     st->time_base, (AVRational){ 1, st->codecpar->sample_rate });
         int64_t total = av_rescale_q(st->duration, st->time_base, (AVRational){ 1, st->codecpar->sample_rate });
-- 
2.52.0

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.