Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: toots via ffmpeg-devel <ffmpeg-devel@ffmpeg.org>
To: ffmpeg-devel@ffmpeg.org
Cc: toots <code@ffmpeg.org>
Subject: [FFmpeg-devel] [PR] libavformat/mov.c: Fix seek in fragmented mp4 files where the audio and video streams are written to seperate fragments (PR #21363)
Date: Fri, 02 Jan 2026 20:11:29 -0000
Message-ID: <176738468950.25.2180570751360007369@4457048688e7> (raw)

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 <romain.beauxis@gmail.com>
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 -- ffmpeg-devel@ffmpeg.org
To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org

                 reply	other threads:[~2026-01-02 20:12 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=176738468950.25.2180570751360007369@4457048688e7 \
    --to=ffmpeg-devel@ffmpeg.org \
    --cc=code@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git