18

I read https://trac.ffmpeg.org/wiki/Encode/H.264 about h264 encoding and discovered qp.

Q1: What are the differences with crf and qp?
Q2: Is it better to use qp over crf overall, or is it only if for using qp 0 for best lossless?
Q3: Does qp have a known sensible setting if it's preferred? So far, I know crf has the default value of 23 while 18 is a sensible preferred increase in quality, although I don't understand why 18 wouldn't be default if better sensible lossless.
Q4: Would changing either of them cause incompatibility with non-ffmpeg players or just qp?

I'm converting from webm to mp4.

I was going to test crf 23 and 18 and pick which is best but I can't seem to find any concrete information on this comparison or about qp.

Rob Bednark
  • 25,981
  • 23
  • 80
  • 125
Nova
  • 2,000
  • 3
  • 14
  • 24

3 Answers3

23

When you set the quantization parameter QP directly it remains constant throughout the encoding and each frame will be compressed based on the set value.

Constant rate factor CRF allows the QP to go up for frames with a lot of motion or down for still frames resulting in a consistent perceived quality while keeping the compression efficient.

This article explains it very well.

The CRF default is just a default, you need to pick a value adapted for your type of video. FFmpeg has filters like PSNR and SSIM which allow you to compare the results.

aergistal
  • 29,947
  • 5
  • 70
  • 92
  • Does using 1 or either effect player compatibility? Your information and link has been most helpful, I just don't know about compatibility that was mentioned on my link. – Nova Nov 18 '16 at 18:03
  • 4
    @Nova Make it easy for yourself and forget `-qp` even exists: it is basically useless for general users. Use `-crf`. – llogan Nov 18 '16 at 18:31
  • 3
    @Nova no, all players in existence support files generated with either -qp or -crf. There are other options that affect playability on very restricted use cases e.g. bluray, but you shouldn't worry about that unless you specifically put the file on a bluray disk. Hardware players in mobile devices and graphics cards have pretty consistent H.264 support nowadays so you don't need to worry about this very much anymore. – Ronald S. Bultje Nov 19 '16 at 12:28
2

Constant QP mode is useful in limited circumstances.

I have some video game recordings from Subnautica. When I travel through a gate the wormhole effects are very messy and CRF mode will reduce the quality. Unfortunately this causes the HUD elements to become fuzzy. In order to preserve the crispness of the HUD I switched from CRF to constant QP mode. I guess a future version of the H.264 encoder could be improved to keep the QP crisp in blocks where there are unchanging pixels, but that does not exist today.

Constant QP would probably be a good choice for intermediate encodings (like converting screen captures from variable frame rate to constant frame rate, because blender is not architected to properly handle variable frame rate content) where you want to preserve quality and can afford the extra disk space.

In most footage CRF will save you some disk space or bandwidth. But in a few cases like mine I prefer constant QP.

Mutant Bob
  • 3,121
  • 2
  • 27
  • 52
2

Just for the record, -qp is supported by both livx264 and h264_nvenc codecs (a CUDA-backed codec).

CUDA ignores -crf, which took me forever to notice.

Michał Leon
  • 2,108
  • 1
  • 15
  • 15
  • 1
    Thanks, I didn't know that crf was ignored by CUDA/NVENC! That is super useful knowledge. Thanks for sharing! – Mitch McMabers Sep 23 '21 at 13:25
  • 1
    In x264 for 10 bit crf of minus 12 (-12) is lossless and has a range from -12 to 51 while in ffmpeg it is 0 to 63. That way 0 should be lossless but in some cases it is not if it somehow selects profile (like high 10 or high 422) that does not support lossless. Only high444 supports lossless. https://trac.ffmpeg.org/ticket/9573#comment:11 – Валерий Заподовников Dec 31 '21 at 00:44
  • 1
    the same for h264_vaapi. ignores crf but accepts qp. – kallaballa Sep 21 '22 at 17:27