Ch. 18 · Encoding Recipes and How to Decide

한국어日本語
8 min

CRF vs. 2-pass vs. CQ: What Do You Fix?

CRF fixes the quality target and leaves the size open; 2-pass fixes the size and leaves the quality open. CQ is a quality mode on hardware encoders and only sounds similar. Using this site's measurements, we see why CRF produces different sizes for different videos.

In the quantization lesson you learned CQP, CRF, and ABR as concepts. Here we sort out which to pick and when, alongside the numbers this site measured.

MethodWhat is fixedWhat is left openIn ffmpeg
CRFQuality target (the CRF value)File size, which varies with how hard the video is-crf value (one run)
2-pass (average bitrate)Target bitrate → roughly the file sizeQuality, which drops if the video is hard-b:v value -pass 1/2 (two runs)
CQ (hardware encoder)A quality value set by the encoderSizee.g. NVENC's -cq. See Chapter 13

Option names and support for 2-pass differ by encoder. Before using it, check with ffmpeg -h encoder=encoder_name.

CRF: the default when you don't need to know the size

If there is no strict limit on file size, it is simpler to finish with a single CRF run. It spends fewer bits on easy scenes and more on hard ones by itself. But even the same CRF gives different results for different videos. In the Why the same CRF gives different results measurement on this site, the VMAF at x264 CRF 30 was as follows.

Clip (1080p25, 10 s)VMAF at x264 CRF 30
blue_sky98.22
pedestrian_area84.21
riverbed81.34
rush_hour80.57

Source: the crf-by-content-v1 measurement article. There are only four clips, so these are not representative of all kinds of video.

  • The CRF that reaches a target quality differs by video. In the same article, the x264 CRF that reaches VMAF 95 was about 20.5 for rush_hour and about 31.5 for blue_sky (interpolated estimates). This means a CRF found on one video, used as-is on another, may fall short of the target or be needlessly large.
  • Size also differs a lot by video. In the same article, the x264 size at VMAF 90 was 1.51 MB for blue_sky and 15.36 MB for riverbed, a difference of about 10.2× (interpolated estimates).
  • Lowering CRF is not always a win. On blue_sky, x264 CRF 18–26 all saturated at VMAF 99.9 or above, yet the size differed by about 4.1×, from 17,217,871 B down to 4,152,541 B.

2-pass: when the size (or bitrate) is decided first

With a limit like 'this file has to fit in 10 MB', CRF is hard to use, because you only learn the output size after encoding finishes. In that case you use 2-pass: you set a target bitrate, the first pass analyzes how hard the whole video is, and the second pass distributes bits using that information. It is known as a method used to hit an average bitrate more accurately.

x264 2-pass example (Linux and macOS. On Windows, use NUL instead of /dev/null)
# Pass 1: analyze only and discard the output (no audio)
ffmpeg -y -i input.mp4 -c:v libx264 -preset medium -b:v 2400k -pass 1 -an -f null /dev/null

# Pass 2: the actual encode using the analysis
ffmpeg -i input.mp4 -c:v libx264 -preset medium -b:v 2400k -pass 2 -c:a aac output.mp4

You can get the bitrate value by entering the duration and target size into the video size and bitrate calculator. Just remember that fixing the size leaves the quality open. In the crf-sweep measurement, the bitrate at x264 CRF 28 was 2,490 kbps for blue_sky and 11,623 kbps for riverbed, a gap of about 4.7× (1080p25, 10 s clips). If both had to fit in 2.5 Mbps, that would be plenty for blue_sky but far too little for riverbed.

This site did not measure 2-pass directly

All of the measurement articles were run in CRF mode (this is also noted in the limitations of the preset-speed article). There are no numbers on this site for how much better 2-pass is than CRF at the same size, and we don't claim any here.

CQ: a different number with a similar name

The -cq of a hardware encoder such as NVENC plays a role similar to CRF in that it is a mode that fixes quality, but the same number does not mean the same quality. You can't carry a software CRF value over to a hardware CQ as-is, and this site's measurements are for software encoders, so we can't estimate hardware results (why this site can't use hardware encoders).

In practice: the rule of thumb in one line

No limit: CRF. With a limit: 2-pass (or try lowering CRF step by step within the limit). If you use a hardware encoder, the only way is to check the result on the same video yourself.

How much the size shrinks as you raise CRF is measured in the CRF step size measurement. On four 10-second clips, x264 and x265 shrank to 40–47% of the original size per CRF +6, so 'CRF +6 halves the size' held roughly true as an average over the whole range, but individual steps varied from 26% to 58%. SVT-AV1 and VP9, which use a 0–63 scale, kept about 57–67% for the same +6.

CRFConstant Rate Factor

A mode that fixes the quality target and lets the size follow. The same value can give very different sizes depending on how hard the video is.

2-passTwo-pass encoding

A method that analyzes the video in the first pass and uses that information in the second pass to distribute bits and hit a target bitrate.

CQConstant quality (hardware)

The fixed-quality mode of a hardware encoder. Its numbers are not compatible with software CRF.

RF (HandBrake)HandBrake's RF

HandBrake's Constant Quality value (Rate Factor). For x264 and x265 it is known to be passed straight through as the encoder's CRF. To find the equal-VMAF value for another codec, use the tool 'HandBrake RF to FFmpeg CRF Conversion Chart'.

Check yourself

With the condition 'the output file must not exceed 10 MB', which rate control should you consider first?

Check yourself

In the crf-by-content measurement, the VMAF at the same x264 CRF 30 differed by clip, from 80.57 to 98.22. What conclusion can you draw?