What's the difference with crf and qp in ffmpeg?

16,776

Solution 1

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.

Solution 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.

Solution 3

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

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

Share:
16,776
Nova
Author by

Nova

Updated on June 21, 2022

Comments

  • Nova
    Nova about 2 years

    After browsing around Google, I've came across this page about h264 encoding and discovered about qp. https://trac.ffmpeg.org/wiki/Encode/H.264

    My questions are: What are the differences with crf and qp? Is it better to use qp over crf overall, or is it only if for using qp 0 for best lossless? 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. Lastly, would changing either of them cause incompatibility with non-ffmpeg players or just qp?

    I'm converting from webm to mp4 by the way.

    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.

  • Nova
    Nova over 7 years
    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.
  • llogan
    llogan over 7 years
    @Nova Make it easy for yourself and forget -qp even exists: it is basically useless for general users. Use -crf.
  • Ronald S. Bultje
    Ronald S. Bultje over 7 years
    @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.
  • Mitch McMabers
    Mitch McMabers almost 3 years
    Thanks, I didn't know that crf was ignored by CUDA/NVENC! That is super useful knowledge. Thanks for sharing!
  • Валерий Заподовников
    Валерий Заподовников over 2 years
    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. trac.ffmpeg.org/ticket/9573#comment:11