Here’s a tip people has asked me about quite a few time concerning playback of H.264 videos using progressive download:
Why do I have to download the whole video file before I can start playback or skip in the video file?
Well, when you serve videos on a site using plain HTTP – known as progressive download – the position of the header becomes very important.
Either the header is placed in the beginning of the file or it’s places in the end of the file. In case of the latter, you’ll have to download the whole thing before you can begin playback – because without the header, the player can’t start decoding.
When you transcode H.264 files in a MP4 container using FFmpeg, the header will be placed in the end and needs to be moved.
So, how do we move the header from the end of the file to the beginning of the file?
Well, I always transcode the video part with FFmpeg and the audio part with NeroAAC and mux the two parts together using Mp4Box. Mp4Box places the header in the beginning of the file – and all is good. If you have files that needs the header moved, you can use the small tool Qt-faststart. You can find Qt-faststart for Windows here.
Recent developement in FFmpeg makes it possible to have FFmpeg move the header to the front of the file using the -movflags faststart option, but it can be a rather slow choice. Here’s how you would do it:
ffmpeg -i input.mp4 -c:a copy -c:v copy -movflags +faststart output.mp4
For further reading, including how to check if your header is placed correctly in regards to progressive download – you can read this article from Adobe.
If you stream using a streaming server or using HTTP Live Streaming (HLS), the position of the header shouldn’t matter. There might be a performance boost in having the header in the front of the file – but this I haven’t tested, but if any of you readers has further info, please don’t be shy – let us know by leaving a comment…