Reputation: 1088
When running "qt-faststart" on an MP4, you're essentially taking the meta data from the back and placing it at the front of the file. In my case, so Flash can properly start playing the video before it's fully done loading.
I have a large number of videos that I'm running through a shell script to encode overnight. When I upload, however, I won't necessarily know in my final folder of videos (on the server) have "qt-faststart" run on it.
My goal is to find the straggler videos and run qt-faststart on them manually, but I'll need a way to compile a list. Is there any way to check for this meta data information with PHP or something? Wondering how I can tell if a video has already had qt-faststart run on it or not.
Upvotes: 13
Views: 12640
Reputation: 1813
Here is a small c# helper function.
This is a very basic solution and may not work with all video files but does work for my simple case where videos were encoded with a recent version of ffmpeg.
private bool IsVideoFastStartEnabled(string fullFilePath)
{
/////////////////////////////////////////////////////////////////////////////////
// Fast start is enabled if "moov" is before "mdat" in first 4096 bytes fo file
// https://trac.ffmpeg.org/wiki/HowToCheckIfFaststartIsEnabledForPlayback
/////////////////////////////////////////////////////////////////////////////////
byte[] buffer = new byte[4096];
using (FileStream fs = new FileStream(fullFilePath, FileMode.Open, FileAccess.Read))
{
fs.Read(buffer, 0, buffer.Length);
fs.Close();
}
var byteSpan = buffer.AsSpan();
var moovPattern = new byte[] { 0x6d, 0x6f, 0x6f, 0x76, 0x00 }.AsSpan();
var moovIndex = byteSpan.IndexOf(moovPattern);
var mdatPattern = new byte[] { 0x6d, 0x64, 0x61, 0x74, 0x00 }.AsSpan();
var mdatIndex = byteSpan.IndexOf(mdatPattern);
if (moovIndex > 0 && (mdatIndex == -1 || moovIndex < mdatIndex))
{
// Fast start is enabled
return true;
}
return false;
}
Upvotes: 0
Reputation: 2735
mediainfo -f file.mp4 | grep IsStreamable
or
ffprobe -v debug file.mp4 2>&1 | grep seeks
and
0 seeks
means "faststart" has been applied.
Upvotes: 18
Reputation: 2012
It shouldn't do any harm to run qt-faststart more than once, it will be a no-op the second time. So the easiest solution is to always run qt-faststart.
For more precise control, I would use the Python translation of qt-faststart: https://github.com/danielgtaylor/qtfaststart
It has functions that examine the atoms in an MP4 file, it shouldn't be too hard to use them to determine whether they need to be reordered.
Upvotes: 8