[FFmpeg-devel] [PATCH] avformat/movenc: Fix flush fragment

Zhao Zhili quinkblack at foxmail.com
Wed May 28 15:56:54 EEST 2025



> On May 22, 2025, at 17:37, Zhao Zhili <quinkblack at foxmail.com> wrote:
> 
> From: Zhao Zhili <zhilizhao at tencent.com>
> 
> The follow cmd output corrupted file before the patch:
> 
> ffmpeg -f lavfi -i color=blue,trim=duration=0.04 \
> 	-f lavfi -i anullsrc,atrim=duration=2 \
> 	-movflags +empty_moov+hybrid_fragmented \
> 	-frag_duration 1000000 \
> 	-frag_interleave 1 \
> 	output.mp4
> 
> 1. first_track is the first track with track->entry != 0. As in the
> command above, video track (track index 0) has a single frame. When
> flush the second fragment, first_track is 1, the audio track.
> 
> 2. write_moof = i == first_track, so write_moof is false for i = 0.
> 
> 3. When mov->frag_interleave != 0, mov->mdat_buf != NULL, because
> it contains audio data. So avio_write is called before write_moof,
> that is, the data write before moof, and mov_finish_fragment
> executed with wrong mdat_start.
> 
> 4. With normal fmp4 output, the error isn't obvious. With
> hybrid_fragmented, ffplay output.mp4 shows a lot of error messages.
> ---
> 

Will apply soon.



More information about the ffmpeg-devel mailing list