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/movenc: Output ftyp atom with hybrid_fragmented+delay_moov (PR #20749)
@ 2025-10-25  9:19 anthonybajoua via ffmpeg-devel
  0 siblings, 0 replies; only message in thread
From: anthonybajoua via ffmpeg-devel @ 2025-10-25  9:19 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: anthonybajoua

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

# Problem
* With `hybrid_fragmented` set, when `delay_moov` writes the `ftyp` atom, this is already after the `free` atom. 
    * This is the location where the `mdat` is overwritten during the soft remux.

# Solution
* Write the `ftyp` before the free atom in the hybrid mp4 codepath, deactivating the overwritten one when `hybrid_fragmented` is set


# Test Plan:
```
❯ ./ffmpeg -loglevel error -i bbb.mp4 -c copy -movflags hybrid_fragmented+delay_moov out.mp4
❯ mp4dump out.mp4 | grep "ftyp"
❯ git diff
❯ make
CC	libavformat/movenc.o
AR	libavformat/libavformat.a
LD	ffmpeg_g
STRIP	ffmpeg
LD	ffplay_g
STRIP	ffplay
LD	ffprobe_g
STRIP	ffprobe
❯ git --no-pager diff
diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index eabc1b95ca..91ad954acb 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -6536,7 +6536,8 @@ static int mov_flush_fragment(AVFormatContext *s, int force)
             mov->tracks[i].data_offset = pos + moov_size + 8;

         avio_write_marker(s->pb, AV_NOPTS_VALUE, AVIO_DATA_MARKER_HEADER);
-        if (mov->flags & FF_MOV_FLAG_DELAY_MOOV)
+        if (mov->flags & FF_MOV_FLAG_DELAY_MOOV
+            && !(mov->flags & FF_MOV_FLAG_HYBRID_FRAGMENTED))
             mov_write_identification(s->pb, s);
         if ((ret = mov_write_moov_tag(s->pb, mov, s)) < 0)
             return ret;
@@ -8432,6 +8433,9 @@ static int mov_write_header(AVFormatContext *s)
             !mov->max_fragment_duration && !mov->max_fragment_size)
             mov->flags |= FF_MOV_FLAG_FRAG_KEYFRAME;
         if (mov->flags & FF_MOV_FLAG_HYBRID_FRAGMENTED) {
+            if (mov->flags & FF_MOV_FLAG_DELAY_MOOV) {
+                mov_write_identification(pb, s);
+            }
             avio_wb32(pb, 8); // placeholder for extended size field (64 bit)
             ffio_wfourcc(pb, mov->mode == MODE_MOV ? "wide" : "free");
             mov->mdat_pos = avio_tell(pb);
❯ ./ffmpeg -loglevel error -i bbb.mp4 -c copy -movflags hybrid_fragmented+delay_moov out.mp4
File 'out.mp4' already exists. Overwrite? [y/N] y
❯ mp4dump out.mp4 | grep "ftyp"
[ftyp] size=8+28
```



From 7c2b4ec21acb6c8a4c82b4e51210d219773b2161 Mon Sep 17 00:00:00 2001
From: Anthony Bajoua <anthonybajoua@meta.com>
Date: Sat, 25 Oct 2025 02:10:06 -0700
Subject: [PATCH] Output ftyp atom with hybrid_fragmented+delay_moov

---
 libavformat/movenc.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index eabc1b95ca..91ad954acb 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -6536,7 +6536,8 @@ static int mov_flush_fragment(AVFormatContext *s, int force)
             mov->tracks[i].data_offset = pos + moov_size + 8;
 
         avio_write_marker(s->pb, AV_NOPTS_VALUE, AVIO_DATA_MARKER_HEADER);
-        if (mov->flags & FF_MOV_FLAG_DELAY_MOOV)
+        if (mov->flags & FF_MOV_FLAG_DELAY_MOOV
+            && !(mov->flags & FF_MOV_FLAG_HYBRID_FRAGMENTED))
             mov_write_identification(s->pb, s);
         if ((ret = mov_write_moov_tag(s->pb, mov, s)) < 0)
             return ret;
@@ -8432,6 +8433,9 @@ static int mov_write_header(AVFormatContext *s)
             !mov->max_fragment_duration && !mov->max_fragment_size)
             mov->flags |= FF_MOV_FLAG_FRAG_KEYFRAME;
         if (mov->flags & FF_MOV_FLAG_HYBRID_FRAGMENTED) {
+            if (mov->flags & FF_MOV_FLAG_DELAY_MOOV) {
+                mov_write_identification(pb, s);
+            }
             avio_wb32(pb, 8); // placeholder for extended size field (64 bit)
             ffio_wfourcc(pb, mov->mode == MODE_MOV ? "wide" : "free");
             mov->mdat_pos = avio_tell(pb);
-- 
2.49.1

_______________________________________________
ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org
To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2025-10-25  9:19 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-10-25  9:19 [FFmpeg-devel] [PATCH] libavformat/movenc: Output ftyp atom with hybrid_fragmented+delay_moov (PR #20749) anthonybajoua via ffmpeg-devel

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