Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
NVEnc - please use Constant Quality / CRF instead of Constant QP #2231
Description of the problem
When NVEnc is selected as the video codec, the UI quality setting says "Constant Quality: xx QP", which sets 'rc=constqp' - a setting for the "Quantization Parameter".
However, Constant QP 'constqp' is not the same as Constant Quality / CRF.
NVEnc has an actual 'Constant Quality' mode equivalent to CRF (by setting 'rc=vbr' and 'cq' instead of 'qp' - note also, it seems to necessary to set 'qmin' and 'qmax' to the same 'cq' value otherwise the quality setting isn't properly adhered to - at least, that is the case when using ffmpeg...)
So the wording in the UI is misleading by saying 'Constant Quality' (but at least it does display QP after it - but only advanced users would understand the subtle difference!).
However, the other part of the problem is that 'constqp' unnecessarily wastes disk space and should be avoided! If interested, see also this additional explanation about why to avoid Constant QP => https://slhck.info/video/2017/03/01/rate-control.html under the section "Constant QP (CQP)".
With NVEnc, the equivalent to CRF is 'rc=vbr' with 'cq', 'qmin' and 'qmax' set, which produces an actual Constant Quality / CRF in one pass, but with a variable bit rate, and thus without the downside of wasting disk space like 'rc=constqp'.
Can you please change the implementation to use the equivalent of CRF instead of QP ?
HandBrake version (e.g., 1.0.0)
HandBrake 1.2.2 (2019022300)
Operating system and version (e.g., Ubuntu 18.04 LTS, macOS 10.14 Mojave, Windows 10 1809)
Windows 10 1903
HandBrake Activity Log (see https://handbrake.fr/docs/en/latest/help/activity-log.html)
encavcodecInit: H.265 (Nvidia NVENC)
changed the title
NVEnc is using Constant QP instead of Constant Quality / CRF
Aug 9, 2019
changed the title
NVEnc - use of Constant QP instead of Constant Quality / CRF
Aug 9, 2019
If someone wants to take a stab at this they can.
Do note, as the code is today, VBR behaves oddly in that it is severely bitrate restricted. As a result, produces much worse results than constqp. I've not looked into why this is but it'll need to be resolved at the same time. (Seems to top out around ~2100kbits)
@sr55 That reminds me... I know that when using the hevc_nvenc encoder in ffmpeg, the default (average) bitrate is set to 2000, and that does seem to override the other settings, such as 'cq'... so you have to explicitly set the bitrate to zero to unleash it. And that is why I also had to set 'qmin' and 'qmax', otherwise extremely high average bitrates get used (more than 10,000k). To be honest, I don't know what 'cq' does by itself since 'qmin' and 'qmax' (which I haven't really found documentation for) seem to actually limit it.
The ffmpeg command line I use to get the equivalent CRF behaviour with NVenc is:
(And for 10-bit, I add -profile:v main10 -pix_fmt p010le)