MP4 video prebuffering with qt-faststart

I worked on a website that hosted a lot of videos uploaded directly by the users, home recorded videos with different formats, coding and resolutions so I came up with a solution to transcode them with FFMPEG to h264 after being uploaded.
That worked great, quality was good enough and the final video files were lighter to download than the original ones. However I noticed that in WindowsXP or when using non HTML5 enabled browsers, the video was completeley downloaded before the streaming actually started.

The reason behind has to do with the metadata (“atoms”) information of the MP4 video files. In order to get the video streamed back to the user’s browser as soon as the play button is hit, the moov atom of the file has to be located in the front of the file (seriously don’t ask what are MP4 atoms it’s geek).

To achieve this, there’s a tool that comes with the FFMPEG source code called “qt-faststart” which basically rearranges a MP4/Quicktime files such that the moov atoms in front of the data, thus facilitating network streaming. Follow the following steps to compile it:

ffmpeg-src# make tools/qt-faststart
CC      tools/qt-faststart.o
LD      tools/qt-faststart
ffmpeg-src# cp tools/qt-faststart /usr/local/bin

Use it from the command line or add this step to your web application transcoding logic.

# /usr/local/bin/qt-faststart /path/to/src_vid.mp4 /path/to/output.mp4

You will now notice that the video starts playing when you hit the play button while it keeps buffering at the same time.


One thought on “MP4 video prebuffering with qt-faststart

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s