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?= <[email protected]> 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?= <[email protected]> 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 -- [email protected] To unsubscribe send an email to [email protected]
