|Version 4 (modified by slhck, 4 months ago) (diff)|
libvpx is the VP8 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.
To install FFmpeg with support for libvpx, 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 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 -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 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. In this case, the target bitrate becomes the maximum allowed bitrate. You enable the constant quality mode with the CRF parameter:
ffmpeg -i input.mp4 -c:v libvpx -crf 10 -b:v 1M -c:a libvorbis output.webm
By default the CRF value can be from 4–63, and 10 is a good starting point. Lower values mean better quality.
Important: If neither -b:v nor -crf are set, the encoder will use a low default bitrate and your result will probably look very bad. Always supply one of these options—ideally both.
If you want to tweak the quality even further, you can set two more parameters:
- -qmin – the minimum quantizer (default 4, range 0–63)
- -qmax – the maximum quantizer (default 63, range qmin–63)
These Q values are quantization parameters, and lower generally means "better quality". If you set the bounds from 0 to 63, this means the encoder has free choice of how to assign the quality. For a better overall quality, you can try to set -qmin to 0 and -qmax to 50 or lower. For example:
ffmpeg -i input.mp4 -c:v libvpx -qmin 0 -qmax 50 -crf 5 -b:v 1M -c:a libvorbis output.webm
Needless to say that this requires a bit of tweaking. If in CRF mode you set the maximum bit rate too low, or the quality too high (i.e., low qmin, qmax or crf), libvpx will "saturate" the bitrate and you'll end up with constant bit rate encoding again, which is not ideal. To quote the VP8 reference: "In practice this means that easy clips may undershoot the target maximum bitrate, because they are constrained by the CQ level, but harder clips will be bounded by the target maximum data rate and will increasingly revert to standard VBR behavior."
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 -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.