VP9
Table of contents
VP9 is an open-source and royalty free codec developed by Google, and maintained as part of the WebM Project. Its successor, AV1, is developed by the Alliance for Open Media (AOMedia). It can be 20-50% higher efficiency than H.264.
General FFmpeg info on VP9 is here, and on the encoder in general https://developers.google.com/media/vp9/hdr-encoding.
VP9 has browser support in:
- Chrome - works on all configurations.
- Edge - works on all configurations.
- Firefox - works for 8-bit and 10-bit but fails with 12-bit.
- Opera - works on all configurations.
- Safari - works for 8-bit and 10-bit but fails on 10-bit 444 and 12-bit RGB.
VP9 is supported by mp4 and webm containers, no support exists for mov. VP9 does support an alpha channel (via the yuva420p pixfmt).
Outside of the web browser, VP9 support is pretty much limited to Davinci Resolve (Mac R/W, windows Read-only), Houdini, Blender, FFmpeg and VLC.
The encoder we cover is libvpx-vp9.
libvpx-vp9
libvpx-vp9 has a wide range of pixel formats: yuv420p yuva420p yuv422p yuv440p yuv444p yuv420p10le yuv422p10le yuv440p10le yuv444p10le yuv420p12le yuv422p12le yuv440p12le yuv444p12le gbrp gbrp10le gbrp12le
Example encoding:
ffmpeg -r 24 -start_number 1 -i inputfile.%04d.png -frames:v 200 -c:v libvpx-vp9 \
-pix_fmt yuv420p10le -crf 22 -cpu-used 2 -row-mt 1 -quality good -b:v 0 \
-vf "zscale=matrix=709:range=limited:filter=lanczos,setparams=color_primaries=bt709:color_trc=iec61966-2-1" \
-color_range tv -colorspace bt709 -color_primaries bt709 -color_trc iec61966-2-1 \
-y outputfile.mp4
Recommended Flags
-crf 22 -quality good -b:v 0 -cpu-used 2 -row-mt 1
| Flag | Description |
|---|---|
| -crf 22 | This is the constant quality rate factor, controlling the default quality, similar to H.264. The range is a little different to H.264, so you may need to test. |
| -quality good | May require additional testing, but so far switching to -quality best increased the duration, but didn’t increase the VMAF score (which is already pretty high with these values of crf). |
| -b:v 0 | Unlike with H.264, you can set a constant quality rate factor unless it exceeds a specified bit-rate, if the bit-rate is set to 0, it ignores the bit-rate as a factor. |
| -cpu-used 2 | It sets how efficient the compression will be. The default is 1 (FFmpeg 9.0), changing this will increase encoding speed at the expense of having some impact on quality and rate control accuracy. (See below). |
| -row-mt 1 | This enables row based multi-threading (see here) which is not enabled by default. |
It’s possible you might want to change the GOP values (changed with the -g flag): by default libvpx puts a keyframe every 128 frames (FFmpeg 6.1.6 and 9.0.2). Unlike H.264 and H.265 VP9 does behave strangely with GOP values less than 10, the closer you get to 1, the longer the encoding takes and the larger the file (which is not true for other codecs).
CRF Comparison
Below is a comparison of different CRF rates, with -b:v 0 and -quality good
If you are trying to map crf values from H.264, VS_Fan came up with the following remapping formula:
vp9_crf (x264_crf) = 1.98 * x264_crf − 14.46
This is showing CRF values against encoding time. |
This is showing CRF values against file size. |
This is showing CRF values against VMAF harmonic mean |
This is showing CRF values against psnr y harmonic mean |
Speed Comparison
Below is a comparison of different speed rates, with and without the -row-mt 1 flag, with -crf 22, -b:v 0 and -quality good.
This shows that the -row-mt flag creates an almost identical result, but can be up to twice as quick (for -cpu-used 0). Also at least with this crf value, even with speed 4, the quality is still pretty good.
This is showing speed against encoding time. |
This is showing speed values against file size. |
This is showing speed values against VMAF harmonic mean |
This is showing speed values against psnr y harmonic mean |
This is showing CRF values against encoding time.
This is showing CRF values against file size.
This is showing CRF values against VMAF harmonic mean
This is showing CRF values against psnr y harmonic mean
This is showing speed against encoding time.
This is showing speed values against file size.
This is showing speed values against VMAF harmonic mean
This is showing speed values against psnr y harmonic mean