There are various FFmpeg encoders that support variable bit rate / constant quality encoding (learn more about rate control modes here). This gives you a much better overall quality when file size or average bit rate are not constrained (e.g. in a streaming scenario). Variable bit rate is usually achieved by setting -q:v (or -q:a for audio) instead of -b:v (or -b:a), which just sets a target bit rate.

The problem is that every encoder uses a different range of values to set the quality—and they’re hard to memorize. This is an attempt to summarize the most important ones.

Notes for reading this table:

  • Qmin stands for the setting to be used for achieving lowest quality and Qmax for highest. These are not just lowest and highest values.
  • Qdef is the default value chosen if no other is specified. This means that (most?) encoders will use one or the other VBR mode by default, e.g. libx264. I wasn’t able to research whether this applies to all encoders.
  • Some encoders use private options instead of the regular -q. Read the second column Param for the correct option to use.
  • Rows highlighted with green refer to encoders that allow you to use VBR. Rows in yellow aren’t really VBR or I simply couldn’t find out whether they support it. Rows in red mean: No VBR support.
Video
Encoder Param Qmin Qmax Qdef Recommended Notes
libx264 -crf 51 0 23 18–28 Values of ±6 result in double/half avg. bitrate. 0 is lossless.
Specifying -profile:v lets you adjust coding efficiency. See H.264 Encoding Guide.
libx265 -crf 51 0 28 24–34 Values of ±6 result in double/half avg. bitrate. 0 is lossless.
Specifying -profile:v lets you adjust coding efficiency. See H.265 Encoding Guide and x265 docs.
libvpx -qmin
-qmax
-crf
-b:v
63 0 10 -qmin: 0–4
-qmax: 50–63
-crf: 30
-b:v sets target bitrate, or maximum bitrate when -crf is set (enables CQ mode). See also VP9 Encoding Guide. Setting -maxrate and -bufsize is also possible.
libxvid -q:v 31 1 n/a 3–5 2 is visually lossless. Doubling the value results in half the bitrate. Don't use 1, as it wastes space.
No VBR by default—it uses -b:v 200K unless specified otherwise.
libtheora -q:v 0 10 n/a 7 No VBR by default—it uses -b:v 200K unless specified otherwise.
mpeg1, mpeg2, mpeg4, flv, h263, h263+, msmpeg+ -q:v 31 1 ? 3–5 2 is visually lossless. Doubling the value results in half the bitrate.
-q:v works for mpeg4, but haven't tested others.
prores -profile:v 0 3 2 Depends Not VBR. Corresponds to the profiles Proxy, LT, Std, HQ.
ProRes might support -q:v?
Target bitrates are in the ProRes Whitepaper.
Audio
Encoder Param Qmin Qmax Qdef Recommended Notes
libfdk_aac -vbr 1 5 ? 4 (~128kbps) Currently the highest quality encoder.
libopus -b:a 6–8K (mono) 96K (for stereo) -vbr on is default, -b:a just sets the target, see FFmpeg documentation.
libvorbis -q:a 0 10 3 4 (~128kbps) Make sure not to use vorbis, which is the (bad) internal encoder.
libmp3lame -q:a 9 0 4 2 (~190kbps) Corresponds to lame -V. See FFmpeg Wiki.
aac -q:a 0.1 2 ? 1.3 (~128kbps) Is "experimental and [likely gives] worse results than CBR" according to FFmpeg Wiki. Ranges from 18 to 190kbps.