Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a downside to putting the MOOV atom at the beginning of an MP4 file?

Tags:

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?

like image 893
Coderer Avatar asked Mar 27 '13 12:03

Coderer


People also ask

What is MOOV atom in MP4?

The moov atom, aka movie atom, defines the timescale, duration, and display characteristics of the movie, as well as sub-atoms containing information for each track in the movie. The optimal location of the moov atom depends on the selected delivery method.

How do you test MOOV atoms?

If you want to check the location of the moov atom you can use a simple hex editor and open your video files. Once you have the file open simply search for "moov" and you should be able to tell the location based upon the line it is located on within the file.

What is MOOV video?

Moov (stylized as MOOV) is a subscription-based music, podcast and video streaming service that combines lossless audio and high-definition music videos with exclusive content and special features on music.

What is Ffmpeg Faststart?

If the file is created by adding the -movflags faststart option to the ffmpeg command line, the "moov" atom is moved at the beginning of the MP4 file during the ffmpeg second pass. By using this option, the "moov" atom is located before the "mdat" atom.


2 Answers

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.

like image 158
SirDarius Avatar answered Oct 16 '22 04:10

SirDarius


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.

like image 20
Roman R. Avatar answered Oct 16 '22 04:10

Roman R.