rigaya / NVEnc

NVENCによる高速エンコードの性能実験
https://rigaya34589.blog.fc2.com/blog-category-17.html
Other
1.1k stars 114 forks source link

Bitrate is too low out of the blue? #599

Closed VisionHDR closed 3 months ago

VisionHDR commented 5 months ago

Hello, the bitrate is too low now out of the blue, i haven't changed any command.

I even tried -vbr super high (like 100000) with a video buffer of 200000, a 4K ProRes 4444XQ input file using software encoder goes at around 20mbps?

I try to use preset quality, worse. I try to set qvbr to 1 or even 0 (auto) same low bitrate.

Can you provide the highest quality command to use for a 4K ProRes and 8K sources (HDR and SDR intermediates)

Thank you!

rigaya commented 5 months ago

I think you can simply use --cqp 0 instead of vbr.

L4cache commented 4 months ago

You'd better not use lossy codec for intermediates. Including prores. Of course, storage is a big concern, at least avoid converting them multiple times.

VisionHDR commented 4 months ago

You'd better not use lossy codec for intermediates. Including prores. Of course, storage is a big concern, at least avoid converting them multiple times.

Hello, this is for HDR and ProRes 4444XQ is meant to be used exactly for it. HDR video in full range doesn't require much more than ProRes 4444XQ and it also delivers 12-bits. You can of course, use other codecs such avid's though the real-world difference isn't as much as you believe. For most use cases, this works well and is also faster/more tweakable than Avid's or other solutions.

I think you can simply use --cqp 0 instead of vbr.

Using --cqp 0 gives: Error occurred: "Non-zero return code from the encoding process", i don't even know the reason, it just gives this error.

Trying --qvbr 1, it also produces really low bitrates. I even tried along with: --vbv-bufsize 550000 --max-bitrate 475000 and with and without: --b 4 --tf-level 4 --lookahead-level 3. Resulting with same low bitrate encoding.

I think this is a bug, because it does this symptom random with ProRes 4444XQ HDR files (full range). The ffmpeg's hevc_nvenc does work with "lossless" encoding approach, by setting: -cq 1, -qmin 1 -qmax 1. But your nvencc does not have those options.

I believe you should add something similar that works the same way, since as today i can't use your application as it always brings out low bitrates without any reason. Maybe, the issue is your application isn't supporting well the HDR ProRes 4444XQ full range files?

L4cache commented 4 months ago

What are you even talking about... FFmpeg now uses -tune lossless (assuming you have a slightly recent version of it) NVEncC has --lossless. Discussing lossless encoding and intermedias may be off topic, my bad.

And the input file format shouldn't matter really, the encoder receives raw decoded YUV data whatsoever. There's this problem which was patched in release 7.54 https://github.com/rigaya/NVEnc/issues/590, did you upgraded your driver, what version of NvEncC are you using?

rigaya commented 4 months ago

Maybe, the issue is your application isn't supporting well the HDR ProRes 4444XQ full range files

Although I don't have ProRes files to test, I find it hard to imagine that the codec of the input file would affect this issue. Furthermore, I don't have any trouble getting low bitrate, like the sample below trying with 4K HDR input file.

x64\NVEncC64.exe -i 4K_Sample.MP4 -o F:\temp\test.mp4 -c hevc --output-depth 10 --cqp 0
--------------------------------------------------------------------------------
F:\temp\test.mp4
--------------------------------------------------------------------------------
NVEncC (x64) 7.56 (r2922) by rigaya, Jun 29 2024 20:56:05 (VC 1940/Win)
OS Version     Windows 11 x64 (22631) [UTF-8]
CPU            12th Gen Intel Core i9-12900K [5.00GHz] (8P+8E,16C/24T)
GPU            #0: NVIDIA GeForce RTX 4080 (9728 cores, 2505 MHz)[PCIe4x16][556.12]
NVENC / CUDA   NVENC API 12.2, CUDA 12.5, schedule mode: auto
Input Buffers  CUDA, 16 frames
Input Info     avcuvid: H.265/HEVC, 3840x2160, 25/1 fps
Vpp Filters    copyDtoD
Output Info    H.265/HEVC main10 @ Level auto
               3840x2160p 1:1 25.000fps (25/1fps)
               avwriter: hevc => mp4
Encoder Preset default
Rate Control   CQP  I:0  P:0  B:0
ChromaQPOffset cb:0  cr:0
Split Enc Mode auto
Lookahead      off
GOP length     250 frames
B frames       3 frames [ref mode: disabled]
Ref frames     3 frames, MultiRef L0:auto L1:auto
AQ             off
CU max / min   auto / auto
Others         mv:auto

encoded 1044 frames, 114.51 fps, 229658.14 kbps, 1143.28 MB
encode time 0:00:09, CPU: 0.4%, GPU: 71.6%, VE: 40.0%, VD: 24.3%, GPUClock: 2721MHz, VEClock: 2130MHz
frame type IDR   5
frame type I     5,  total size    7.05 MB
frame type P   263,  total size  317.52 MB
frame type B   776,  total size  818.70 MB

As @L4cache mentions, --lossless will be better if you are using for intermediate files. (avgQP log seems corrupt, but the encoded result and bitrate are fine)

x64\NVEncC64.exe -i 4K_HLG_Sample.MP4 -o F:\temp\test.mp4 -c hevc --output-depth 10 --lossless
--------------------------------------------------------------------------------
F:\temp\test.mp4
--------------------------------------------------------------------------------
NVEncC (x64) 7.56 (r2922) by rigaya, Jun 29 2024 20:56:05 (VC 1940/Win)
OS Version     Windows 11 x64 (22631) [UTF-8]
CPU            12th Gen Intel Core i9-12900K [5.00GHz] (8P+8E,16C/24T)
GPU            #0: NVIDIA GeForce RTX 4080 (9728 cores, 2505 MHz)[PCIe4x16][556.12]
NVENC / CUDA   NVENC API 12.2, CUDA 12.5, schedule mode: auto
Input Buffers  CUDA, 16 frames
Input Info     avcuvid: H.265/HEVC, 3840x2160, 25/1 fps
Vpp Filters    copyDtoD
Output Info    H.265/HEVC main10 @ Level auto
               3840x2160p 1:1 25.000fps (25/1fps)
               avwriter: hevc => mp4
Encoder Preset default
Rate Control   CQP  I:0  P:0  B:0 (lossless)
ChromaQPOffset cb:0  cr:0
Split Enc Mode auto
Lookahead      off
GOP length     250 frames
B frames       3 frames [ref mode: disabled]
Ref frames     3 frames, MultiRef L0:auto L1:auto
AQ             off
CU max / min   auto / auto
Others         mv:auto

encoded 1044 frames, 53.45 fps, 847418.63 kbps, 4218.60 MB
encode time 0:00:19, CPU: 1.3%, GPU: 74.2%, VE: 48.4%, VD: 14.6%, GPUClock: 2762MHz, VEClock: 2155MHz
frame type IDR   5
frame type I     5,  avgQP  858993447.20,  total size    21.72 MB
frame type P   263,  avgQP  16330662.13,  total size  1161.15 MB
frame type B   776,  avgQP  5534739.67,  total size  3035.73 MB
rigaya commented 3 months ago

I'll close this issue, as NVEnc 7.54 should have fixed this issue.

If you have any more issues, please provide the full log and the actual input file.