It happens to me quite often that an MP4 file does not stream correctly from my Raspberry PI to my tablet. It looks like it is an MP4 issue rather than an hardware issue.
My initial thought was that the streaming was chunky (or was failing entirely) due to the Hard Drive being connected to the RPi. So, I’ve started overclocking it and trying different WiFi adapters but still no luck: the streaming from XBMC was not working.
Frustrated, I have connected the Hard Disk to my Mac and I have installed Serviio to finally stream those videos to my tablets. However, with my great wonder, nether my computer was able to stream smoothly (without transcoding). Even by changing tablet and apps (iOS default one, VLC, MXPlayer, etc…) some files were not playing at all.
There were only two variables left: the router and the video file itself. My Talk Talk router is not an high performance WiFi router, but the bitrate of the video file was quite low (~500kB/s).
So, I have started reading some documentation about the MP4 format. And here is the gotcha: if the meta information is not at the beginning of the file the streaming will fail.
How to fix that?
Obviously I don’t want to re-transcode the entire file, because that will cause quality loss. Hopefully, there are some programs that can do that without transcoding.
First one is Quicktime/MP4 Fast Start, which enable streaming and pseudo-streaming of Quicktime and MP4 files by moving metadata and offset information to the front of the file.
The second one is MP4Box, which is part of the Osmo4 suite and it is able to enable HTTP playback while downloading the file. Not only MP4Box moves the meta information at the beginning of the file but it is also able to add additional data to improve streaming.
In order to use it, you have to download the entire suite and then use the MP4Box tool from the command line:
This command will prepare the file for HTTP download and it will interleave file data by chunks of 500 milliseconds, enabling the HTTP FastStart. Then, after waiting few seconds, all your streaming issues will be gone.