[FFmpeg-devel] qt-faststart update

Frank Barchard fbarchard
Wed Jun 24 04:39:55 CEST 2009


Patch to allow qt-faststart to work on output of mp4box and quicktime, as
well as ffmpeg muxer, to reduce seeks and startup time when playing back
with ffmpeg based tools.
I'm new to this group, so I hope you'll be gentle as I try to submit my
first change to the handy tools/qt-faststart.c

Why?
When decoding mp4 files with ffmpeg, a seek to end of file slows down
startup latency.
qt-faststart moves the 'moov' header atom to the beginning of the file.
 Which works great if you use ffmpeg to mux, but if you use quicktime or
mp4box to mux, ffmpeg demux will still seek to end of file?
Unless you use url_is_streamed, the open will scan thru all the atoms, and
if anything follows mdat, a far seek will occur.
In practice, 'free' atoms are being added by to the end of file.   The atoms
are not required and removing them solves the seek.

How?
The old code would move the 'moov' header after 'ftyp', adjust stco offsets,
and output the rest of the file.
It would fail if the last atom was not 'moov'.
The new code ignores 'free' when figuring out the rest of file to copy.
If the 'moov' is not at end of file, but 'free' is, the file is copied as
is, but truncating the 'free' atom.

Details
The tool was also ported to Visual C 2005 and tested with 64 bit files, as
well as mingw gcc.  Allows debugging with Visual Studio.  To compile cl /Ox
qt-faststart.c
A printf was a useful diagnostic, and I left it in to show where all the
atoms are.  Typically 3 or 4 additional lines of text.
It can be slow, so I bumped the block size from 1k to 32k.  On a 470MB file,
cached performance went from 25.5 seconds to 22.0 seconds.
There were ways to crash the old tool, so I made it more robust with common
cleanup code.
In practice, the tool optimizes for output of 3 tools:
1. ffmpeg mux puts 'moov' at end of file which needs to be moved
2. mp4box mux puts 'free' at end of file which needs to be truncated
3. quicktime pro mac camera capture puts 'free' followed by 'moov' at end of
file, requiring moving and truncation.

Future work
Instead of moving the 'moov' to the beginning, it would be better to move
the 'mdat' to the end.  This would stop other atoms, such as 'uuid' from
causing seeks to the end.
It would also allow 'free' atoms to be maintained, incase some tools are
using them for meta information.
But that would be a bigger change with more risk.

Attached is the diff, and full .c file.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: qt-faststart.diff
Type: application/octet-stream
Size: 15863 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090623/3bf64786/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: qt-faststart.c
Type: application/octet-stream
Size: 11975 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090623/3bf64786/attachment-0001.obj>



More information about the ffmpeg-devel mailing list