libvpx-vp9 is the VP9 video encoder for WebM, an open, royalty-free media file format. This guide is an attempt to summarize the most important options for creating video with libvpx-vp9.
To install FFmpeg with support for libvpx-vp9, look at the Compilation Guides and compile FFmpeg with the --enable-libvpx option.
Note that in the below examples, the libvorbis audio encoder is used. Make sure your FFmpeg version also includes libvorbis (check with ffmpeg -codecs), as the native Vorbis encoder from FFmpeg does not provide comparable quality.
libvpx-vp9 offers a variable bitrate mode by default. In this mode, it will simply try to reach the specified bit rate on average, e.g. 1 MBit/s. This is the "target bitrate".
ffmpeg -i input.mp4 -c:v libvpx-vp9 -b:v 1M -c:a libvorbis output.webm
Choose a higher bit rate if you want better quality. Note that you shouldn't leave out the -b:v option as the default settings will produce mediocre quality output.
In addition to the "default" VBR mode, there's a constant quality mode (like in the x264 encoder) 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. This results in better overall quality and should be your method of choice when you encode video with libvpx-vp9. To trigger this mode, you must use a combination of -crf and -b:v 0. -b:v MUST be 0.
ffmpeg -i input.mp4 -c:v libvpx-vp9 -crf 10 -b:v 0 -c:a libvorbis output.webm
The CRF value can be from 0–63. Lower values mean better quality.
libvpx-vp9 also has a constrained quality mode that will ensure that a constant (perceptual) quality is reached while keeping the bitrate below a specified upper bound. Useful for bulk encoding videos in a generally consistent fashion.
ffmpeg -i input.mp4 -c:v libvpx-vp9 -crf 10 -b:v 1000k -c:a libvorbis output.webm
The quality is determined by the -crf, and the bitrate limit by the -b:v where the bitrate MUST be non-zero. Note: for videos that are "easy" to encode this mode behaves exactly like the Constant Quality mode and actual bitrate may be lower than specified bitrate while for videos that are "hard" to encode the quality will be bounded by the maximum bitrate and will behave like the Variable Bitrate mode.
Like most other encoders, libvpx offers a constant bitrate encoding mode as well, which tries to encode the video in such a way that an average bitrate is reached. This doesn't mean that every frame is encoded with the same amount of bits (since it would harm quality), but the bitrate will be very constrained. You should use constant bitrate encoding if you need your video files to have a certain size, or if you're streaming the videos over a channel that only allows a certain bit rate.
The syntax for setting a constant bit rate is:
ffmpeg -i input.mp4 -c:v libvpx-vp9 -minrate 1M -maxrate 1M -b:v 1M -c:a libvorbis output.webm
Here, you can choose different values for the bitrate other than 1M, e.g. 500K, but you must set all options (i.e., minrate, maxrate and b:v) to the same value.
libvpx-vp9 has a lossless encoding mode that can be activated using -lossless 1.