History

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.

Zhao Zhili committed 1 year ago

Commit 56cf1c01 parent 3d9b2842 files · +7 −2Browse files

Showing the changes to libavformat (1 of 2 files). Show all

Unified · Split

libavformat/movenc.c+2−2
@@ -6509,9 +6509,9 @@ static int mov_flush_fragment(AVFormatContext *s, int force) · 6508 unmodified lines
65096509 int buf_size, write_moof = 1, moof_tracks = -1;
65106510 uint8_t *buf;
65116511
6512+ if (!track->entry)
6513+ continue;
65126514 if (mov->flags & FF_MOV_FLAG_SEPARATE_MOOF) {
6513− if (!track->entry)
6514− continue;
65156515 mdat_size = avio_tell(track->mdat_buf);
65166516 moof_tracks = i;
65176517 } else {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t