Ch. 18 · Encoding Recipes and How to Decide

한국어日本語
7 min

Recipe 1: Archive and Upload Files, Meant to Be Reworked

Archive copies and platform uploads are 'files that may be encoded or edited again later'. Look at the worst frames, not just the mean VMAF, and leave headroom rather than squeezing the size.

The two uses have something in common: in both, this file is not the final version that people watch. An archive copy may be edited or re-encoded later, and a platform upload is re-encoded by the platform to its own specs (upload notes). For files like these, quality headroom comes before saving size.

Principles

  • If you already have the original, not re-encoding is the safest. Applying lossy compression again cuts the quality once more. If only the container needs to change, remux with -c copy.
  • Rate control: CRF. With no size limit, fixing the quality is the right choice.
  • Go toward a low CRF and a slow preset. The lowest x264 CRF this site measured was 18, and on blue_sky CRF 18–26 all saturated at VMAF 99.9 or above (crf-by-content). On an easy video, lowering CRF too far may only increase the size.
  • Look at the lowest frame, not just the mean. This is explained further below.
  • Preset: the slow side. It is a file you make once and use for a long time, so time matters less. With x265, slow was 13–27% smaller than medium at the same VMAF 90 (preset-speed). Note, however, that this measurement covers x265 only.

Even with a high mean, the worst frame can be low

We recheck what we saw in The trap of averages with this site's numbers. In the vmaf-worst-frames measurement, looking at the 12 points whose mean VMAF is closest to 90, the gap between mean and minimum was 2.275–16.717. For riverbed at x264 CRF 26, the mean is 95.238 but the lowest frame is 78.521.

Goalriverbed x264riverbed x265riverbed SVT-AV1 (preset 6)
CRF that reaches mean VMAF 9526.124.838.0
CRF that reaches min VMAF 9019.120.828.7
Size ratio (min 90 ÷ mean 95)2.291.581.88

Source: vmaf-worst-frames-v1. Estimates interpolated between two adjacent measured points. The size ratio is the ratio of log-interpolated sizes.

In 9 of the 12 combinations, keeping 'min 90 or above' required a lower CRF than 'mean 95 or above'. On the other hand, for rush_hour with x264 and x265, once the mean hit 95 the minimum was already above 90. In other words, for some videos the mean is enough, and for others it isn't, and you can only tell which by measuring. The original's limitations section also notes that, because the minimum is decided by a single frame, it may be affected by the starting frame or scene changes.

Example recipes

Archive starting points. Adjust the codec and CRF after verifying on your own video
# When you need wide compatibility with H.264
ffmpeg -i input.mov -c:v libx264 -preset slow -crf 18 -pix_fmt yuv420p -c:a copy archive.mkv

# When you want a smaller size and the playback device supports HEVC
ffmpeg -i input.mov -c:v libx265 -preset slow -crf 20 -pix_fmt yuv420p10le -c:a copy archive_hevc.mkv
The CRF values above are not 'verified answers'

CRF 18 and 20 are only starting points taken from the low end of the range this site measured (x264 18–46, x265 20–48), not recommended values per type of video. In the same article, riverbed at x264 CRF 22 has a mean VMAF of 99.945 but a minimum of 86.33. For video you plan to archive, get a rough position with the CRF recommender, then check your own video using the method in Lesson 6.

Make files for platform upload close to the archive recipe above, but follow the platform's official upload guidelines for container, codec, frame rate, and resolution. This site does not list recommended bitrates for individual platforms, because the values change often. To check the codec and container, the video file info inspector is useful.

How far an archive CRF is worth lowering differed from video to video. In the high-quality CRF measurement, the highest x264 CRF at which even the bottom 5% of frames reach VMAF 99 or more was 25 or above for blue_sky (saturated to the end of the measured range), 22 for riverbed, 13 for pedestrian_area and 10 for rush_hour; going lower than that barely raised VMAF while the file size grew.

Generation lossGeneration loss

The effect where each time lossy-compressed video is lossy-compressed again, the quality is cut one more time.

MezzanineIntermediate master

A high-quality intermediate file uploaded on the assumption that a platform will re-encode it. It is not meant for final viewing.

Check yourself

In the vmaf-worst-frames measurement, riverbed x264 had CRF 26.1 to reach mean 95 and CRF 19.1 to reach min 90. What does this comparison suggest?

Check yourself

Which best describes the nature of a video file you upload to a platform?