Skip to content

Encoding files to .webm (VP8) and .mp4 (h.264) using ffmpeg

justlaputa edited this page · 2 revisions


Here you can find great articles about VP8 and h.264 encoding:

and here about details about HTML5 video

FFmpeg installation

FFmpeg supports multiple OS and Linux distributions.

In case you have Ubuntu, use this detailed compilation guide:

It seems, that libvo_aacenc as AAC encoder has better quality than libfaac (less noisy). So if you want to use libvo_aacenc, during preparation step run

sudo apt-get install libvo-aacenc-dev

Later, during configuring FFmpeg add --enable-libvo-aacenc argument

After installing ffmpeg, install tool qt-faststart . This tool relocates some data in h.264 video and allow you to playback from begin before the file is completely downloaded.

WebM(VP8) encoding

Recommended is 2 pass encoding. You gain better quality. For high-quality 480p output try these settings:


ffmpeg -i "/home/user/input_video.mpg" -codec:v libvpx -quality good -cpu-used 0 -b:v 600k -qmin 10 -qmax 42 -maxrate 500k -bufsize 1000k -threads 2 -vf scale=-1:480 -an -pass 1 -f webm /dev/null


ffmpeg -i "/home/user/input_video.mpg" -codec:v libvpx -quality good -cpu-used 0 -b:v 600k -qmin 10 -qmax 42 -maxrate 500k -bufsize 1000k -threads 2 -vf scale=-1:480 -codec:a libvorbis -b:a 128k -pass 2 -f webm output.webm

With 2-core Intel CPU encoding speed is approximately 10 frames per second. Yes, libvpx is too slow compared to libx264. From experience 2-3 times.

Mp4(H.264) encoding


ffmpeg -i "concat:/home/user/Video/VTS_01_1.VOB|/home/user/Video/VTS_01_2.VOB" -vcodec libx264 -vprofile high -preset slow -b:v 500k -maxrate 500k -bufsize 1000k -vf scale=-1:480 -threads 0 -pass 1 -an -f mp4 /dev/null


ffmpeg -i "concat:/home/user/Video/VTS_01_1.VOB|/home/user/Video/VTS_01_2.VOB" -vcodec libx264 -vprofile high -preset slow -b:v 500k -maxrate 500k -bufsize 1000k -vf scale=-1:480 -threads 0 -pass 2 -acodec libvo_aacenc -b:a 128k -f mp4 output_file.mp4

Now use qt-faststart to relocate meta data in file

qt-faststart output_file.mp4 output_file_with_relocated_metadata.mp4

Concating files

As you can see above, you can concat multiple input files into one output.

Creating thumbnails

If you need to create thumbnail from video, use command:

ffmpeg -itsoffset -4 -i "$INFILE" -vcodec png -vframes 1 -an -f rawvideo -s 120x90 -y "$OUTFILE"

Change number 4 to generate img in different time.


With these settings you achieve high-quality video output in rational file size. Please take into account, that WebM now is not fully supported by all browsers (IE, Safari). For full compatibility you must render both WebM and mp4 file.

Thanks Matho for this page

Something went wrong with that request. Please try again.