24
votes

I see tons of questions about relocating the moov atom from the end of a MP4 video container to the beginning, to make the video "web optimized" or easier to stream. It seems like most tools require an explicit option to do this when first encoding the video, if it's available at all.

If placing the atom at the beginning makes streaming work better, and it's costly to do it after-the-fact, why would I ever want to encode video with the atom at the end? What's the benefit?

2

2 Answers

23
votes

Encoding the MOOV at the end of the file is usually a default operation for video encoders because they tend to operate by writing the output file in one-pass, and the exact contents and size of the MOOV atom can only be known after having written audio and video data entirely, because it contains absolute file sizes.

FFmpeg allows you to do a second pass and move the atom to the beginning with -movflags +faststart.

Having the MOOV atom at the end has no special benefit, it is just not as inconvenient in local playback situations where seeking at end-of-file before playback is not as costly as in progressive download delivery.

6
votes

You will always want to put the index information at the beginning of the file, there is no hidden cost for this layout except the only one: while doing capture/transcoding you might be unable to tell in advance how much space you need for that MOOV atom at the beginning, and its data is not yet well available as well. So you normally write the payload directly into file and they complete the write by adding MOOV and updating the rest of the file.