PR #21363 opened by toots
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21363
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21363.patch


>From 7ec826f46ffba3a0ad8952642a0d995b9d8e2e49 Mon Sep 17 00:00:00 2001
From: Romain Beauxis <[email protected]>
Date: Fri, 2 Jan 2026 14:09:54 -0600
Subject: [PATCH] libavformat/mov.c: Fix seek in fragmented mp4 files where the
 audio and video streams are written to seperate fragments

---
 libavformat/mov.c                    | 13 +++++++++++++
 tests/fate/mpeg4.mak                 |  6 ++++++
 tests/ref/fate/mpeg4-fragmented-seek |  6 ++++++
 3 files changed, 25 insertions(+)
 create mode 100644 tests/ref/fate/mpeg4-fragmented-seek

diff --git a/libavformat/mov.c b/libavformat/mov.c
index 009ddfec80..71ecb2f19d 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -1728,6 +1728,19 @@ static int64_t get_frag_time(AVFormatContext *s, 
AVStream *dst_st,
         return frag_stream_info->sidx_pts;
     }
 
+    // Check if the requested stream is present in the fragment with valid 
timing
+    int stream_present = 0;
+    for (i = 0; i < frag_index->item[index].nb_stream_info; i++) {
+        if (dst_st->id != frag_index->item[index].stream_info[i].id)
+            continue;
+        if (get_stream_info_time(&frag_index->item[index].stream_info[i]) != 
AV_NOPTS_VALUE) {
+            stream_present = 1;
+            break;
+        }
+    }
+    if (!stream_present)
+        return AV_NOPTS_VALUE;
+
     for (i = 0; i < frag_index->item[index].nb_stream_info; i++) {
         AVStream *frag_stream = NULL;
         frag_stream_info = &frag_index->item[index].stream_info[i];
diff --git a/tests/fate/mpeg4.mak b/tests/fate/mpeg4.mak
index d6cce97a70..c914f61731 100644
--- a/tests/fate/mpeg4.mak
+++ b/tests/fate/mpeg4.mak
@@ -21,5 +21,11 @@ fate-m4v:     CMD = framecrc -flags +bitexact -idct simple 
-i $(TARGET_SAMPLES)/
 FATE_MPEG4-$(call FRAMECRC, M4V, MPEG4, MPEG4VIDEO_PARSER FPS_FILTER) += 
fate-m4v-cfr
 fate-m4v-cfr: CMD = framecrc -flags +bitexact -idct simple -i 
$(TARGET_SAMPLES)/mpeg4/demo.m4v -vf fps=5
 
+# Test seeking in fragmented MP4 with separate audio/video fragments
+# Seeks to 1.04s and extracts 1 frame - should land on I-frame at 1.0s with 
fix,
+# lands at start (0s) without fix due to get_frag_time() bug
+FATE_MPEG4-$(call FRAMECRC, MOV, H264, AAC_DECODER) += 
fate-mpeg4-fragmented-seek
+fate-mpeg4-fragmented-seek: CMD = framecrc -use_mfra_for pts -ss 1.04 -copyts 
-noaccurate_seek -i $(TARGET_SAMPLES)/mpeg4/fragmented.mp4 -frames:v 1 -an
+
 FATE_SAMPLES_AVCONV += $(FATE_MPEG4-yes)
 fate-mpeg4: $(FATE_MPEG4-yes)
diff --git a/tests/ref/fate/mpeg4-fragmented-seek 
b/tests/ref/fate/mpeg4-fragmented-seek
new file mode 100644
index 0000000000..5204e169aa
--- /dev/null
+++ b/tests/ref/fate/mpeg4-fragmented-seek
@@ -0,0 +1,6 @@
+#tb 0: 1/25
+#media_type 0: video
+#codec_id 0: rawvideo
+#dimensions 0: 320x240
+#sar 0: 1/1
+0,         25,         25,        1,   115200, 0x19fdc3e8
-- 
2.49.1

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

Reply via email to