| Version 2 (modified by , 5 years ago) ( diff ) |
|---|
(page under construction)
How to know if a H.264/MP4 file is ready for fast start playback
Normally, a MP4 file has all the metadata about all packets stored at the end of the file, unless it has been created by adding "faststart" to the -movflags option. In this latter case, an atom named "moov" is moved at the beginning of the MP4 file during the ffmpeg second pass.
This "faststart" allows to start the playback of the movie faster in some cases : the player does not need to read the full file before starting playback.
Therefore, the position of the "moov" atom in an existing MP4 file (begining or end) helps to know if fast start is operative or not for this file.
Prerequisites
This page is intended for Windows 10 users but can be used by Unix users with only small changes.
Prior to using the next *.BAT files, Windows users should download grep.exe and head.exe from an Internet site.
First approach
The first approach is to fully scan the H.264/MP4 files to look for mdat and moov atoms.
@echo off
for /F "delims=µ" %%i in ('dir /b /on *.mp4') do (
echo %%i
ffmpeg -v trace -i "%%i" NUL 2>&1 | grep -m 1 -o -e "type:'mdat'" -e "type:'moov'"
)
pause
exit
This batch file searches only the first occurence of either mdat atom or moov atom. When a MP4 file is ready for fast start playback, the moov atom appears first. When not, the mdat atom appears first.
The drawback of this batch file is that it can take a while to run when scanning hundreds of MP4 files.
Alternate method
An alternate method is to truncate the MP4 files before scanning. If the moov atom is not in the first 4K bytes, the file is not fast start ready.
@echo off
echo 1>NUL 2>OUTPUT.txt
for /F "delims=µ" %%i in ('dir /b /on *.mp4') do (
echo %%i
head -c 4096 "%%i" >temp.mp4
ffmpeg -v trace -i temp.mp4 NUL 2>"%%i.txt"
grep -L -m 1 -e "type:'moov'" "%%i.txt" >>OUTPUT.txt
del "%%i.txt"
)
del temp.mp4
pause
exit
The OUTPUT.txt file contains the list of MP4 files that are NOT fast start ready.


