What is WebM and why should you use it?
To better understand what WebM is you can watch this short video explanation: What is WebM?. The good news is that as of 2018, most browsers support VP9. Read more here. So what is the advantage of the WebM (vp9) codec over MP4 H.264? Basically, libvpx-vp9 can save about 20–50% bitrate compared to libx264.
Simple WebM encoding with FFmpeg
It is really easy to encode video to WebM with FFmpeg.
ffmpeg -i input.mp4 -c:v libvpx-vp9 -crf 45 -b:v 0 output.webm
-crf 45
is the video quality. Lower is better. 0 is lossless. 63 is the worst possible quality. The file size will depend on this.
For better quality, we set the -b:v
to 0
which enables “constant quality” (CQ) mode that will ensure that every frame gets the number of bits it deserves to achieve a certain (perceptual) quality level, rather than forcing the stream to have an average bit rate.
Better quality with two-pass encoding
Two-pass encoding means that FFMpeg will run the encoding process twice. The first time it will analyze the input file and make a log file. In the second pass, FFmpeg will use the log file to encode the video. This method takes longer but will create more efficient encodes when a particular target bitrate should be reached.
ffmpeg -y -i original.mkv -c:v libvpx-vp9 -crf 40 -b:v 0 -pass 1 -an -f null NUL && ^
ffmpeg -y -i original.mkv -c:v libvpx-vp9 -crf 40 -b:v 0 -pass 2 crf40.webm
Note that the NUL && ^
is for Windows only. On Linux you can use /dev/null && \
Video examples
Here are some image and video comparisons in case you are wondering which CRF
to use.
Original video (14,8 MB)
Two-pass CRF 25 (4,98 MB)
Two-pass CRF 55 (726 kb)
Any good WEBM GUI alternatives?
If you do not like using the command line to convert video there are a bunch of alternatives. I really like webm for retards. It’s a lightweight software that, in addition, to doing the same as above, allows you to set a target file size for the output file.
Although I prefer the command line, it is really nice to avoid the calculation of the bitrate to achieve a specific size. Also, WebMCam is super great for just simple screen capturing to WEBM.
Sources:
FFmpeg wiki: FFmpeg and VP9 Encoding Guide Werner Robitza: CRF Guide (Constant Rate Factor in x264 and x265)