Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: "Martin Storsjö via ffmpeg-devel" <ffmpeg-devel@ffmpeg.org>
To: ffmpeg-devel@ffmpeg.org
Cc: "Martin Storsjö" <code@ffmpeg.org>
Subject: [FFmpeg-devel] [PATCH] movenc: Fix two interactions between delay_moov and hybrid_fragmented (PR #20704)
Date: Tue, 14 Oct 2025 11:07:36 -0000
Message-ID: <176044005700.25.5984535584535208957@bf907ddaa564> (raw)

PR #20704 opened by Martin Storsjö (mstorsjo)
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20704
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20704.patch


From 3a1d1ef1caa1c23a21471c1c985fb12e4b9debc9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Martin=20Storsj=C3=B6?= <martin@martin.st>
Date: Tue, 14 Oct 2025 13:47:03 +0300
Subject: [PATCH 1/2] movenc: Fix sample clustering for
 hybrid_fragmented+delay_moov

If samples were available when the moov was written, chunking
for those samples has been done already, which has to be reset
here.

This is the case when not using empty_moov, when the moov box
describes the first fragment - this case was accounted for already.
But if using the delay_moov flag, then those samples also were
available when writing the moov, so chunking for them has already
been done in this case as well.

Therefore, always reset chunking here (it should be harmless to
always do it), and update the comment to clarify the cases
involved here.
---
 libavformat/movenc.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index 067d38b14b..43aa51cb87 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -6394,8 +6394,10 @@ static int mov_finish_fragment(MOVMuxContext *mov, MOVTrack *track,
     if (mov->flags & FF_MOV_FLAG_HYBRID_FRAGMENTED) {
         for (i = 0; i < track->entry; i++)
             track->cluster[i].pos += ref_pos + track->data_offset;
-        if (track->cluster_written == 0 && !(mov->flags & FF_MOV_FLAG_EMPTY_MOOV)) {
-            // First flush. If this was a case of not using empty moov, reset chunking.
+        if (track->cluster_written == 0) {
+            // First flush. Chunking for this fragment may already have been
+            // done, either if we didn't use empty_moov, or if we did use
+            // delay_moov. In either case, reset chunking here.
             for (i = 0; i < track->entry; i++) {
                 track->cluster[i].chunkNum = 0;
                 track->cluster[i].samples_in_chunk = track->cluster[i].entries;
-- 
2.49.1


From 5fb1e2cd78bebc10f96f30b6c0479de33780c4a3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Martin=20Storsj=C3=B6?= <martin@martin.st>
Date: Tue, 14 Oct 2025 13:49:04 +0300
Subject: [PATCH 2/2] movenc: Make sure to flush the delayed moov atom for
 hybrid fragmented

If using the delay_moov flag in combination with hybrid_fragment
(which is a potentially problematic combination otherwise - the
ftyp box does end up hidden in the end), then we need to flush
twice to get both the moov box and the first fragment, if the
file is finished before the first fragment is completed.
---
 libavformat/movenc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index 43aa51cb87..aa132b1c45 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -8592,7 +8592,7 @@ static int mov_write_trailer(AVFormatContext *s)
     if (!(mov->flags & FF_MOV_FLAG_FRAGMENT) ||
         mov->flags & FF_MOV_FLAG_HYBRID_FRAGMENTED) {
         if (mov->flags & FF_MOV_FLAG_HYBRID_FRAGMENTED) {
-            mov_flush_fragment(s, 1);
+            mov_auto_flush_fragment(s, 1);
             mov->mdat_size = avio_tell(pb) - mov->mdat_pos - 8;
             for (i = 0; i < mov->nb_tracks; i++) {
                 MOVTrack *track = &mov->tracks[i];
-- 
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:[~2025-10-14 11:08 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=176044005700.25.5984535584535208957@bf907ddaa564 \
    --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