Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NVEnc - please use Constant Quality / CRF instead of Constant QP #2231

Closed
channeladam opened this issue Aug 9, 2019 · 3 comments

Comments

@channeladam
Copy link

commented Aug 9, 2019

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 ?
Or at least provide the option to change it, or allow the extra options to override that rc setting which we can't right now.

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)
encavcodec: encoding at rc=constqp QP 25.00

@channeladam channeladam changed the title NVEnc is using constant QP instead of constant quality NVEnc is using Constant QP instead of Constant Quality / CRF Aug 9, 2019

@channeladam channeladam changed the title NVEnc is using Constant QP instead of Constant Quality / CRF NVEnc - use of Constant QP instead of Constant Quality / CRF Aug 9, 2019

@channeladam channeladam changed the title NVEnc - use of Constant QP instead of Constant Quality / CRF NVEnc - please use Constant Quality / CRF instead of Constant QP Aug 9, 2019

@sr55

This comment has been minimized.

Copy link
Contributor

commented 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)

@channeladam

This comment has been minimized.

Copy link
Author

commented Aug 10, 2019

@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:
-c:v hevc_nvenc -rc vbr -cq 27 -qmin 27 -qmax 27 -b:v 0

(And for 10-bit, I add -profile:v main10 -pix_fmt p010le)

sr55 added a commit that referenced this issue Aug 12, 2019

@sr55

This comment has been minimized.

Copy link
Contributor

commented Aug 12, 2019

When the next nightly is published, give it a go see what the results are like.

@sr55 sr55 removed the Patch Welcome label Aug 12, 2019

@sr55 sr55 added this to the 1.3.0 milestone Aug 12, 2019

@sr55 sr55 self-assigned this Aug 12, 2019

@sr55 sr55 closed this Aug 17, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
2 participants
You can’t perform that action at this time.