diff options
author | Zhao Zhili <zhilizhao@tencent.com> | 2025-05-22 17:37:05 +0800 |
---|---|---|
committer | Zhao Zhili <zhilizhao@tencent.com> | 2025-06-01 16:36:54 +0800 |
commit | 56cf1c084d50e1b8bb2e667bb9c0aaecb4ae48fc (patch) | |
tree | 8383f96667ba4a09313a5928607544c931f21aa0 /libavformat/movenc.c | |
parent | 3d9b284ad148ac4ccad21773f7ae44ab80a3da6d (diff) | |
download | ffmpeg-56cf1c084d50e1b8bb2e667bb9c0aaecb4ae48fc.tar.gz |
avformat/movenc: Fix flush fragment
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.
Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
Diffstat (limited to 'libavformat/movenc.c')
-rw-r--r-- | libavformat/movenc.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/libavformat/movenc.c b/libavformat/movenc.c index f11633525e..246fc2912c 100644 --- a/libavformat/movenc.c +++ b/libavformat/movenc.c @@ -6509,9 +6509,9 @@ static int mov_flush_fragment(AVFormatContext *s, int force) int buf_size, write_moof = 1, moof_tracks = -1; uint8_t *buf; + if (!track->entry) + continue; if (mov->flags & FF_MOV_FLAG_SEPARATE_MOOF) { - if (!track->entry) - continue; mdat_size = avio_tell(track->mdat_buf); moof_tracks = i; } else { |