MattMcManis / Axiom

An FFmpeg GUI for Windows
https://axiomui.github.io
GNU General Public License v3.0
1.44k stars 114 forks source link

[BUG]Default -crf flag is not suitable for h264_nvenc #82

Open nkh0472 opened 3 years ago

nkh0472 commented 3 years ago

In Video-Encoding section, when change Quality option from "Auto" to any other option such like "Ultra", the default bitrate control method is "CRF", whether or not the nvenc encoder is enabled. However, h264_nvenc is not support --crf flag according to ffmpeg --help encoder=nvenc. Thus when hit Convert button, the ffmpeg will give an error as below and exit.

Codec AVOption crf (Select the quality for constant quality mode) specified for output file #0 (X:\output.mp4) has not been used for any stream. The most likely reason is either wrong type (e.g. a video option with no video streams) or that it is a private option of some encoder which was not actually used for any stream.
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (h264_nvenc))
Press [q] to stop, [?] for help
[h264_nvenc @ 000001ea39c007c0] Specified rc mode is deprecated.
[h264_nvenc @ 000001ea39c007c0] Use -rc constqp/cbr/vbr, -tune and -multipass instead.
[h264_nvenc @ 000001ea39c007c0] InitializeEncoder failed: invalid param (8): Presets P1 to P7 are not supported with older 2 Pass RC Modes(CBR_HQ, VBR_HQ) and cbr lowdelay.
Enable NV_ENC_RC_PARAMS::multiPass flag for two pass encoding a
Error initializing output stream 0:0 -- Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height
Conversion failed!

Instead, we can use -cq:v number to replace -crf number when h264_nvenc is enabled. -cq <float> E..V....... Set target quality level (0 to 51, 0 means automatic) for constant quality mode in VBR rate control (from 0 to 51) (default 0) And use optional flags -maxrate:v number -bufsize number to constrain bitrate.


However there is another bug: In Video-Encoding section, when set Quality to Custom, set Pass to 1 Pass or 2 Pass, the Bit Rate values disappear in script. That means even I input numbers in Bit Rate Min Rate and other 2 blanks, the script will still looks like:

......
-c:v h264_nvenc 
-preset slow 
-pix_fmt yuv420p 
-vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" 
-map 0:v:0?
......

Only when using default quality options like High, the script works correctly:

......
-c:v h264_nvenc 
-preset slow -q:v 2500K 
-pix_fmt yuv420p 
-vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" 
-map 0:v:0? 
......