Ch. 18 · Encoding Recipes and How to Decide

한국어日本語
8 min

How to Decide: Run a Short Test on Your Own Video

Rather than trusting someone else's CRF, run a short section of your own video at 2–3 CRF steps, look at the size and VMAF (mean, low, min), and choose. The four recipes are summarized in one table.

What the earlier lessons had in common is that 'the numbers differ by video'. The same CRF and the same preset gave different results. So instead of giving you values, the last lesson of this chapter covers a procedure for checking for yourself.

A 5-step procedure

  1. 1Pick a representative section. If you choose only easy scenes, the result is optimistic; if you choose only high-motion sections, it is pessimistic. If possible, include both the hardest section and an ordinary one. The clips measured on this site are 10 seconds.
  2. 2Run CRF at 2–3 steps. As crf-by-content showed, the CRF needed for the same target differed by nearly 11 between clips, so it is safer to run a wide range with spacing of about 4.
  3. 3Extract the bottom 5% and the minimum along with the mean VMAF. If you produce per-frame scores with libvmaf, all of them can be computed from the same result. For the method, see the libvmaf hands-on lesson and measurement pitfalls (if resolution, frame alignment, or color range are off, the score becomes meaningless).
  4. 4Compare size against your target and choose. Decide first whether 'the target is the mean or the minimum', not just the mean. In the saturated range (VMAF 99 or above), a lower CRF only increases the size.
  5. 5Check with your eyes too. VMAF does not fully replace human judgment. Look directly at the frames with low scores and at the hardest scenes.
Example of test-encoding a short section (10 s) at three CRF steps (Linux and macOS)
# Cut a section and test-encode at CRF 22, 26, 30 (10 s starting 5 s into the input)
for q in 22 26 30; do
  ffmpeg -ss 5 -t 10 -i input.mp4 -c:v libx264 -preset medium -crf $q -an test_$q.mkv
done

# Compare each result with the same section of the original and measure VMAF (see the Chapter 11 hands-on lesson for details)
ffmpeg -i test_26.mkv -ss 5 -t 10 -i input.mp4 -lavfi libvmaf=log_fmt=json:log_path=vmaf_26.json -f null -
Check alignment and order

In libvmaf, input order matters. In general, the first input is the one being evaluated (the encoded result) and the second is the reference (the original). The example above is meant to show the concept, so check resolution and frame-rate alignment and the input order against the command in the libvmaf hands-on lesson.

The four recipes at a glance

UseConstraintRate controlPresetWatch out especially for
ArchiveMay be reworked laterCRF (low side)Slow sideLowest frame; avoid re-encoding the original
Platform uploadPlatform re-encodesCRF (with headroom)Slow side to mediumPlatform's official guidelines; color tags if HDR
Web embedCan't control the viewing deviceCRFAround mediumH.264+AAC+yuv420p, faststart, fallback
Messenger sharingSize limit2-pass (fixed bitrate)Around mediumBitrate calculation; adjust resolution and duration

The preset column is a general direction based on your time budget. x265 is the only codec for which this site has measured the size and time ratios between presets.

This chapter in one line

The destination decides the codec, whether there is a limit decides the rate control, your time budget decides the preset, and the final numbers are decided by your own video.

The evidence used in this chapter, and its limits

  • All numbers come from this site's measurements (crf-sweep, crf-by-content, preset-speed, vmaf-worst-frames). Each article states its measurement conditions, clip sources, and limitations.
  • The measurements use 4 clips of 10 seconds, 8-bit, software encoders, and a single PC. Animation, screen recordings, dark video, and HDR are missing, and neither 2-pass nor hardware encoders were measured.
  • 'Interpolated values' are estimates, not measurements. The CRF values in this chapter (18, 20, 23, and so on) are starting-point examples and are not guaranteed as recommended values.

When you actually pick values, we recommend this flow: get candidates with the CRF recommender, build the command with the FFmpeg command builder, then gauge the time with the encode time estimator.

SaturationQuality saturation

The range where lowering CRF barely raises VMAF and only increases the size. It shows up at low CRF on easy videos.

Worst-frame checkWorst-frame check

A procedure that looks at the bottom 5% and minimum VMAF along with the mean VMAF, to confirm that some frames haven't collapsed badly.

Check yourself

What is the most reliable procedure for finding the right CRF for your video?

Check yourself

Which of the following is the most suitable recipe for a messenger-sharing video with a size limit?