Convert video to MP4, WebM and Ogg (VP8) for HTML 5 video tag

Here is a small script, which converts videos to all three HTML5 video formats that can be used in the <video> element. Either avconf or FFmpeg can be used as converters. I’m using both, because avconf does not have builtin support for the Fraunhofer FDK AAC codec in Ubuntu 14.04 (you would need to compile it from source) and the FFmpeg Ubuntu package ( no support for Theora. For more information see:

if [ "$1" == "" ]; then
    echo Please specify a file name.
    exit 1;

# Choose between ffmpeg and avconv:

# 720p:

# 1080p:

#ffmpeg Wiki:

# Parameters:
# -acodec libvorbis: Set aduo codec to Ogg Vorbis. Should be default, but just in case.
# -aq 5: Audio quality between -1 and 10 (good starting point is 5).
# -ac 2: Audio channels: Stereo
# -vcodec libvpx: Should be default
# -qmin: Video quality minimum: Seems to make no difference
# -qmax: Maximum video quality between 0 and 63: Higher value means lower quality (good starting point is 25).
# -b:v 2M: Bitrate of 2MB/s
# -vf scale=$HORIZONTAL_RESOLUTION:-1: Apply scale filter and reduce resolution to 720p (keeping vertical resolution).
rm -f $1.webm
$CONVERTER_WEBM -i $1 -acodec libvorbis -aq 7 -ac 2 -vcodec libvpx -b:v 2M -qmax 16 -vf scale=$HORIZONTAL_RESOLUTION:-1 -threads 4 $1.webm
# Parameters:
# -acodec libfdk_aac: Fraunhofer FDK AAC codec library: Highest AAC encoder available
# -cutoff 18000: By default high frequencies are cut off, so increase cut off level
# -vcodec libx264
# -qmax: Range is 0 to 51 here.
rm -f $1.mp4
$CONVERTER_MP4 -i $1 -acodec libfdk_aac -cutoff 18000 -vcodec libx264 -b:v 2M -qmax 16 -vf scale=$HORIZONTAL_RESOLUTION:-1 -threads 4 $1.mp4

# Parameters:
# -qscale:a 7: Audio quality (range 0 to 10)
# -qscale:v 7: Video quality (range 0 to 10)
rm -f $1.ogv
$CONVERTER_OGG -i $1 -acodec libvorbis -qscale:a 7 -vcodec libtheora -qscale:v 9 -vf scale=$HORIZONTAL_RESOLUTION:-1 -threads 4 $1.ogv