23

I have a library of videos, all of which should have been adjusted for web-streaming by putting the moov atom ahead of the rest of the video. This allows playback to begin before the client has completely downloaded the video.

Is there a reliable way to check if a certain video has been adjusted by locating how many bytes in the moov atom occurs? This is for debugging purposes only.

1
  • 4
    Just for reference for others interested in placing the moov atom in the beginning to facilitate playback see the -movflags faststart option or the qt-faststart tool in ffmpeg.
    – llogan
    Mar 1 '13 at 18:59
23

FFmpeg won't show you this information, really.

You could use AtomicParsley to parse the file, e.g.:

AtomicParsley input.mp4 -T 

This will show you the location of the atoms in a tree. If the moov atom is at the beginning of the file, it'll have to come right after the ftyp atom, so you could try parsing the output, e.g. in Bash, only printing the second line and checking whether it contains moov:

AtomicParsley input.mp4 -T | sed -n 2p | grep -q "moov" && echo "yup" || echo "nope"
5
  • Haha, well… glad to help :)
    – slhck
    Mar 4 '13 at 9:29
  • Note, this will not work on YouTube DASH files. Apr 28 '14 at 7:43
  • 1
    @StevenPenny Right, DASH segments do not contain the entire Atom tree, because they're only segments, not complete ISO Base Media files.
    – slhck
    Apr 28 '14 at 8:29
  • I have two mp4 files and I'm trying to determine which to keep, but AtomicParsley crashes on both of them: too many atoms Aborted (core dumped)
    – Michael
    Apr 23 '20 at 2:44
  • 1
    @Michael Seems it's limited to 1024 atoms by default. Not sure why – but the tool has not been updated in quite some time.
    – slhck
    Apr 23 '20 at 7:16
16

Using this qtfaststart (not the same as ffmpeg's qt-faststart), qtfaststart -l input.mp4 will display the order of the top-level atoms.

$ qtfaststart -l bad.mp4
ftyp (32 bytes)
free (8 bytes)
mdat (559619 bytes)
moov (52916 bytes)
$ qtfaststart -l good.mp4
ftyp (32 bytes)
moov (52916 bytes)
mdat (559619 bytes)
$
3
  • 3
    If you have pip installed you can install qtfaststart with pip install qtfaststart
    – qff
    Apr 19 '16 at 11:48
  • You can also install with Homebrew: brew install qtfaststart Dec 28 '18 at 18:07
  • @BrandonDurham Homebrew didn't work for me, it installed a different program; presumably it was the ffmpeg version Jul 22 '20 at 21:26
4

The way to do this using ffmpeg is described in this answer to another question. Run the following Bash command:

$ ffmpeg -v trace -i file.mp4 2>&1 | grep -e type:\'mdat\' -e type:\'moov\'

The output will look something like this:

[mov,mp4,m4a,3gp,3g2,mj2 @ 0x55ea95500ac0] type:'mdat' parent:'root' sz: 52958326 32 52971704
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x55ea95500ac0] type:'moov' parent:'root' sz: 13354 52958358 52971704

In this example, since moov appears after mdat, the moov atom is not at the beginning of the file and faststart is not enabled. If moov were to appear before mdat, then the moov atom would be at the beginning of the file and faststart would be enabled.

3

You can do this with FFprobe:

ffprobe -v trace infile.mp4

Or with Bento4:

$ mp4info infile.m4a
File:
  major brand:      isom
  minor version:    200
  compatible brand: isom
  compatible brand: iso2
  compatible brand: mp41
  fast start:       no

$ mp4info outfile.m4a
File:
  major brand:      isom
  minor version:    200
  compatible brand: isom
  compatible brand: iso2
  compatible brand: mp41
  fast start:       yes
2
  • 2
    Can you please demonstrate where in the ffprobe output this information can be found? Jul 22 '20 at 19:06
  • 1
    @forresthopkinsa, here you go: ffprobe -v trace -i file.mp4 2>&1 | grep -e type:\'mdat\' -e type:\'moov\' . (ffmpeg can be substituted for ffprobe). If moov appears before mdat, then it is at the front of the file and thus fast start is enabled. Via Gyan's answer. Jan 21 at 18:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.