How to encode videos once to support all devices

For video on demand publishers it is important to choose the right format to encode their videos to especially if they have big volume of video assets because with all the different devices and browsers supporting different video formats it can be quite costly to have multiple versions of the same file for the purpose of delivery to a particular client. The costs comprise of encoding and storage as well as lower caching efficiency.

Fortunately all more or less modern devices support a single format being H264 video codec and AAC audio codec in mp4 container. Flash players and rtmp servers support this format meaning you can stream your videos or alternatively use progressive download with an http server or try the new http streaming plugin for flash that allows for seek to a point functionality out of the box with any http byte-range capable server with no installations required.

Html5 video players (recent desktop browsers and mobile devices like iPhone, iPad, Android etc) support mp4 H264 video too and they take advantage of byte-range requests by default allowing to seek to the end of the video without the need to wait till it is completely loaded. You should be aware though that to be able to seek to a point your video needs to be encoded with key-frames every few seconds (5 or 10).

Keyframes are points in a video file that are not dependent on any other part of the file hence your video player can start downloading video from that point, if you don't have them at all however the video will have to be downloaded from the very start or if they are very sparsely inserted your visitors might see delays after seeking on the timeline.

H264 video codec has a notion of profile which is a set of options for encoding algorithms, there are different levels of this profile with the higher levels having greater compression to allows better quality on lower bitrates, however they are more demanding on CPU resources and are not supported by all devices like older Androids. If you would like to support these older devices at the price of lower quality you should use baseline profile when encoding your videos, here is an ffmpeg example of video encoding to H264 baseline AAC mp4 that works on pretty much any device through flash or html5 video player:

ffmpeg -i input.mp4 -y -vcodec libx264 -s 640x360 -acodec libfaac -ab 64k -ac 2 -b 300K -threads 4 -flags +loop -cmp +chroma -partitions 0 -me_method epzs -subq 1 -trellis 0 -refs 1 -coder 0 -me_range 16 -g 300 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -maxrate 10M -bufsize 10M -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -level 30 output.mp4

Encode your video to H264 mp4 once and delivery to any device.


Please wait...