How to tell if faststart for video is set using ffmpeg or ffprobe
Asked Answered
S

1

10

I am having trouble figuring out how to determine if faststart is set on an MP4 video.

I understand that "moov atom" is the data that needs to be located at the beginning of the file for faststart to be enabled, instead of at the end of the file.

I specifically want to use ffmpeg or ffprobe to determine if it has been moved to the beginning or not already.

On a side note, I understand I can run the following command to move it from the end to the beginning (but I want to find out if it is already there):

ffmpeg -i infile.mp4 -map 0 -c:v copy -c:a copy -c:s copy -c:d copy -c:t copy -movflags +faststart outfile.mp4
Sowell answered 10/7, 2019 at 5:13 Comment(0)
I
23

Run

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

This will produce an output like,

[mov,mp4,m4a,3gp,3g2,mj2 @ 000000000036ca40] type:'mdat' parent:'root' sz: 62740 48 65044
[mov,mp4,m4a,3gp,3g2,mj2 @ 000000000036ca40] type:'moov' parent:'root' sz: 2264 62788 65044

Since moov appears second, it is at the end in this example.

On bash-like shells, escape the single quotes:

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

For Windows, findstr can be used,

ffmpeg -v trace -i file.mp4 2>&1 | findstr /l "type:'moov' type:'mdat'"
Intrepid answered 10/7, 2019 at 5:30 Comment(13)
I tried this on a file that I am pretty sure does not have faststart and get nothing back. I then tried on another file which I am pretty sure does have faststart (ran ffmpeg -movflags +faststart on the first file), and got nothing back as well. I am running from command line in linux.Sowell
I had to modify the GREP part of the command to get it to work: ffmpeg -v trace -i file.mp4 2>&1 | grep -e "'mdat' parent" -e "'moov' parent"Sowell
You need to escape the single quotes depending on your shellIntrepid
So this worked on one computer, but on another computer I get Invalid log level "trace". ... is this because its an older version of ffmpeg?Sowell
Says this: ffmpeg version N-63893-gc69defd Copyright (c) 2000-2014 the FFmpeg developers built on Jul 16 2014 05:38:01 with gcc 4.6 (Debian 4.6.3-1)Sowell
Unfortunately I have no ability to change the version of ffmpeg :(Sowell
Does seeks mean anything with regard to faststart? [mov,mp4,m4a,3gp,3g2,mj2 @ 0x3505640] Before avformat_find_stream_info() pos: 4003558 bytes read:3606602 seeks:2 [mov,mp4,m4a,3gp,3g2,mj2 @ 0x3505640] After avformat_find_stream_info() pos: 4029995 bytes read:3606602 seeks:2 frames:11 [AVIOContext @ 0x3504e20] Statistics: 3606602 bytes read, 2 seeksSowell
Those are I/O seeks - jumping from one position in the file to another. Can't tell you where the moov is.Intrepid
So I then assume the answer by user1133275 in the following question is wrong: #6658259Sowell
It's unqualified; in practice, it's fine, although you should use the seeks value on the line which starts with Before avformat_find_stream_info(). FFmpeg does not just locate the index, it also reads some frames and decodes them to get accurate codec configuration. It's possible to have a file with index at the front but the media payload storage man have a large interleave interval or be non-interleaved. In those cases, ffmpeg will seek to read some frames for streams not adjacent to the end of the moov.Intrepid
This does not work (anymore?). Removing the grep part, I get "At least one output file must be specified". If I add -f null - to the end, it runs for a while, but not a single line containing moov or mdat is output.Labour
@Labour Works here but I've to double quote the grep strings.Intrepid
@Labour I just had the same problem, try this ffmpeg -v trace -i file.mp4 2>&1 | grep -e type:\'mdat\' -e type:\'moov\'Raveaux

© 2022 - 2024 — McMap. All rights reserved.