PR #20385 opened by Zhao Zhili (quink)
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20385
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20385.patch

In hybrid_fragmented mode, the first moov at start should contain
mvex tag, since it's fmp4. When writing the moov at the second time,
it's not fmp4 any more, so mvex should be skipped.


>From 701399cecfe5e3d80406745ae466fc654dfc22a4 Mon Sep 17 00:00:00 2001
From: Zhao Zhili <zhiliz...@tencent.com>
Date: Mon, 1 Sep 2025 14:55:44 +0800
Subject: [PATCH] avformat/movenc: remove mvex from final mp4 in
 hybrid_fragmented mode

In hybrid_fragmented mode, the first moov at start should contain
mvex tag, since it's fmp4. When writing the moov at the second time,
it's not fmp4 any more, so mvex should be skipped.
---
 libavformat/movenc.c           | 6 +++++-
 tests/fate/mov.mak             | 2 +-
 tests/ref/lavf/mov_hybrid_frag | 4 ++--
 3 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index efd6329d70..e67a14a7d6 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -5183,7 +5183,11 @@ static int mov_write_moov_tag(AVIOContext *pb, 
MOVMuxContext *mov,
                 return ret;
         }
     }
-    if (mov->flags & FF_MOV_FLAG_FRAGMENT)
+    /* Don't write mvex for hybrid_fragmented during mov_write_trailer
+     * (mov->moov_written != 0)
+     */
+    if (mov->flags & FF_MOV_FLAG_FRAGMENT &&
+        !(mov->flags & FF_MOV_FLAG_HYBRID_FRAGMENTED && mov->moov_written))
         mov_write_mvex_tag(pb, mov); /* QuickTime requires trak to precede 
this */
 
     if (mov->mode == MODE_PSP)
diff --git a/tests/fate/mov.mak b/tests/fate/mov.mak
index 421845969b..8e0988000d 100644
--- a/tests/fate/mov.mak
+++ b/tests/fate/mov.mak
@@ -92,7 +92,7 @@ fate-mov-frag-overlap: CMD = framemd5 -i 
$(TARGET_SAMPLES)/mov/frag_overlap.mp4
 
 fate-mov-mp4-frag-flush: CMD = md5 -f lavfi -i 
color=blue,format=rgb24,trim=duration=0.04 -f lavfi -i 
anullsrc,aformat=s16,atrim=duration=2 -c:v png -c:a pcm_s16le -movflags 
+empty_moov+hybrid_fragmented -frag_duration 1000000 -frag_interleave 1 
-bitexact -f mp4
 fate-mov-mp4-frag-flush: CMP = oneline
-fate-mov-mp4-frag-flush: REF = c9d0236bde4a0b24a01f6a032fd72e04
+fate-mov-mp4-frag-flush: REF = a1ac687d15552505f3c01a43285f32d0
 FATE_MOV_FFMPEG-$(call ALLYES, LAVFI_INDEV COLOR_FILTER FORMAT_FILTER 
TRIM_FILTER \
                                ANULLSRC_FILTER AFORMAT_FILTER ATRIM_FILTER     
   \
                                WRAPPED_AVFRAME_DECODER PCM_S16LE_DECODER 
PCM_S16BE_DECODER \
diff --git a/tests/ref/lavf/mov_hybrid_frag b/tests/ref/lavf/mov_hybrid_frag
index cd449712b9..64f4e9085e 100644
--- a/tests/ref/lavf/mov_hybrid_frag
+++ b/tests/ref/lavf/mov_hybrid_frag
@@ -1,3 +1,3 @@
-4871796f41234350f1b050317d0288a3 *tests/data/lavf/lavf.mov_hybrid_frag
-358508 tests/data/lavf/lavf.mov_hybrid_frag
+7f79311fa73287c093aa029f58b71476 *tests/data/lavf/lavf.mov_hybrid_frag
+358436 tests/data/lavf/lavf.mov_hybrid_frag
 tests/data/lavf/lavf.mov_hybrid_frag CRC=0xbb2b949b
-- 
2.49.1

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

Reply via email to