Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH] libavformat/mov.c: fix seek issues for fragmented mp4 files
@ 2025-01-28  1:20 Srikanth Kiran Kotagiri
  2025-01-28 17:29 ` Srikanth Kotagiri
  0 siblings, 1 reply; 3+ messages in thread
From: Srikanth Kiran Kotagiri @ 2025-01-28  1:20 UTC (permalink / raw)
  To: ffmpeg-devel

For Fragmented MP4 files where the audio and video streams are written to seperate fragments, the -ss option will cause the file pointer to be set to the first available fragment. This is due to an interaction in search_frag_timestamp() function and get_frag_time() functions.

With this change, we first verify that the fragment does not actually contain the requested fragment before just sending AV_NOPTS_VALUE.
---
 libavformat/mov.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index c016ce8e41..f3e4f4deff 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -87,6 +87,7 @@ typedef struct MOVParseTableEntry {
 static int mov_read_default(MOVContext *c, AVIOContext *pb, MOVAtom atom);
 static int mov_read_mfra(MOVContext *c, AVIOContext *f);
 static void mov_free_stream_context(AVFormatContext *s, AVStream *st);
+static int mov_switch_root(AVFormatContext *s, int64_t target, int index);
 
 static int mov_metadata_track_or_disc_number(MOVContext *c, AVIOContext *pb,
                                              unsigned len, const char *key)
@@ -1680,6 +1681,27 @@ 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
+    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) {
+            exists = 1;
+            break;
+        }
+        if ( mov_switch_root(s,-1,index) < 0)
+            return AV_NOPTS_VALUE;
+        if ( get_stream_info_time(&frag_index->item[index].stream_info[i]) != AV_NOPTS_VALUE) {
+            exists = 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];
-- 
2.39.5 (Apple Git-154)

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 3+ messages in thread
* [FFmpeg-devel] [PATCH] libavformat/mov.c: fix seek issues for fragmented mp4 files
@ 2025-01-28 17:32 Srikanth Kiran Kotagiri
  0 siblings, 0 replies; 3+ messages in thread
From: Srikanth Kiran Kotagiri @ 2025-01-28 17:32 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Srikanth Kiran Kotagiri

From: Srikanth Kiran Kotagiri <srikanth@descript.com>

For Fragmented MP4 files where the audio and video streams are written to seperate fragments, the -ss option will cause the file pointer to be set to the first available fragment. This is due to an interaction in search_frag_timestamp() function and get_frag_time() functions.

With this change, we first verify that the fragment does not actually contain the requested fragment before just sending AV_NOPTS_VALUE.
---
 libavformat/mov.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index c016ce8e41..c50e6ee35b 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -87,6 +87,7 @@ typedef struct MOVParseTableEntry {
 static int mov_read_default(MOVContext *c, AVIOContext *pb, MOVAtom atom);
 static int mov_read_mfra(MOVContext *c, AVIOContext *f);
 static void mov_free_stream_context(AVFormatContext *s, AVStream *st);
+static int mov_switch_root(AVFormatContext *s, int64_t target, int index);
 
 static int mov_metadata_track_or_disc_number(MOVContext *c, AVIOContext *pb,
                                              unsigned len, const char *key)
@@ -1666,6 +1667,7 @@ static int64_t get_frag_time(AVFormatContext *s, AVStream *dst_st,
     MOVStreamContext *sc = dst_st->priv_data;
     int64_t timestamp;
     int i, j;
+    int stream_present;
 
     // If the stream is referenced by any sidx, limit the search
     // to fragments that referenced this stream in the sidx
@@ -1680,6 +1682,27 @@ 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
+    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 ( mov_switch_root(s,-1,index) < 0)
+            return AV_NOPTS_VALUE;
+        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];
-- 
2.39.5 (Apple Git-154)

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-01-28 17:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-01-28  1:20 [FFmpeg-devel] [PATCH] libavformat/mov.c: fix seek issues for fragmented mp4 files Srikanth Kiran Kotagiri
2025-01-28 17:29 ` Srikanth Kotagiri
2025-01-28 17:32 Srikanth Kiran Kotagiri

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