I'm trying to encode my movies into WebM:
ffmpeg -i input.MOV -codec:v libvpx -quality good -cpu-used 0 -b:v 10k
-qmin 10 -qmax 42 -maxrate 10k -bufsize 20k -threads 8 -vf scale=-1:1080
-codec:a libvorbis -b:a 192k
output.webm
I want to encode at a couple of different bit rates (video and audio combined):
The problem is that no matter which bit rates I enter, I always get a file with a bit rate higher than 1900 kbps. (1914 kbps with the code example above.)
What am I doing wrong?
libvpx
is a little complicated with regard to rate control and quality settings. Please refer to the vpx Encoding Guide and the VP8 Encode Parameter Guide for more info. It took me an hour of digging through the source code to understand it.
If you want to set constant bitrate, you will have to set b:v
, maxrate
and minrate
to the same values, for example like so (note that I left out the audio options here for brevity):
ffmpeg -i input.mov -c:v libvpx -b:v 1900K -maxrate 1900K -minrate 1900K output.webm
If instead you want to use variable quality and just specify the upper bound for the bitrate, then you need to set both b:v
and crf
. If you leave out crf
, the specified bitrate will just be taken as an average. Only with crf
, the encoder changes the meaning of b:v
to the maximum allowed rate.
ffmpeg -i input.mov -c:v libvpx -b:v 1900K -crf 10 output.webm
A value of 10 for the CRF is a good starting point, but libvpx
may change the quality per frame within the bounds of qmin ≤ q ≤ qmax
, which you can also specify if you want. Setting a lower bound of 10 for qmin
seems a little high to me, but in essence you'll have to do some trial and error anyway, since if the maximum bitrate is too low, you'll constantly saturate it.