rigaya / NVEnc

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

H264 --level parameter broken in 5.09 - 5.11 #270

Closed SK-Hardwired closed 4 years ago

SK-Hardwired commented 4 years ago

Hi! When specifying any --level parameter with h264 encoder error happen:

nvenc : Failed to Initialize the encoder nvenc : .: 8 (NVENC indicates that one or more of the parameter passed to the API call is invalid.)

Check-hw log: Checking Environment Info... NVEncC (x64) 5.15 (r1658) by rigaya, Sep 12 2020 15:05:21 (VC 1916/Win/avx2) OS Version Windows 10 x64 (19041) CPU Intel Core i7-6700HQ @ 2.60GHz (4C/8T) cuInit: Success. cuvidInit: Success. InitCuda: Success. cuDeviceGetCount: Success. gpuinfo: checking for device #0. gpuinfo: cuDeviceGet(0): success gpuinfo: cuDeviceGetName(0): GeForce GTX 1060 gpuinfo: cudaDeviceGetAttribute: CUDA 6.1 gpuinfo: PCIBusId: 0000:01:00.0 gpuinfo: Got GPU Info from NVML. gpuinfo: NV Driver version: 456550. gpuinfo: CUDA Driver version: 11010. gpuinfo: using cuda schedule mode: auto. gpuinfo: cuCtxCreate: Success. gpuinfo: cuCtxPopCurrent: Success. gpuinfo: cuvidCtxLockCreate: Success. nvenc : Loaded nvEncodeAPI64.dll. nvenc : nvEncodeAPICreateInstance(APIVer=0x7002000a): Success. nvenc : Opened Encode Session (API ver 10.0) nvenc : NvEncOpenEncodeSessionEx(device_type=NV_ENC_DEVICE_TYPE_CUDA): Success. gpuinfo: createDeviceFeatureList InitDeviceList: Success.

0: GeForce GTX 1060 (1280 cores, 1670 MHz)[PCIe3x16][456.55]

Avaliable Codec(s) H.264/AVC H.265/HEVC gpuinfo: Closing device #0: GeForce GTX 1060... gpuinfo: Closing Encoder... nvenc : nvEncDestroyEncoder... nvenc : nvEncDestroyEncoder: success. gpuinfo: Closed Encoder. gpuinfo: Closed cuvid Ctx Lock... gpuinfo: Closed cuvid Ctx Lock. gpuinfo: Closed CUDA Context... gpuinfo: Closed CUDA Context. gpuinfo: Closed device #0: GeForce GTX 1060. Closed EncodeStatus. Closing perf monitor... Closing logger...

rigaya commented 4 years ago

I don't seem to have trouble here with my tests, for example,

x64\NVEncC64_5.15.exe -i sample_movie_1080p.mpg -o F:\temp\test.mp4 -d 1 --level 4.1
--------------------------------------------------------------------------------
F:\temp\test.mp4
--------------------------------------------------------------------------------
NVEncC (x64) 5.15 (r1658) by rigaya, Sep 12 2020 23:40:28 (VC 1927/Win/avx2)
OS Version     Windows 10 x64 (18363)
CPU            Intel Core i9-7980XE @ 2.60GHz [TB: 4.10GHz] (18C/36T)
GPU            #1: GeForce GTX 1060 6GB (1280 cores, 1708 MHz)[PCIe3x16][451.67]
NVENC / CUDA   NVENC API 10.0, CUDA 11.0, schedule mode: auto
Input Buffers  CUDA, 20 frames
Input Info     avcuvid: MPEG2, 1920x1080, 30000/1001 fps
Vpp Filters    copyDtoD
Output Info    H.264/AVC high @ Level 4.1
               1920x1080p 1:1 29.970fps (30000/1001fps)
               avwriter: h264 => mp4
Encoder Preset default
Rate Control   CQP  I:20  P:23  B:25
Lookahead      off
GOP length     300 frames
B frames       3 frames [ref mode: disabled]
Ref frames     3 frames
AQ             off
Others         mv:auto cabac deblock adapt-transform:auto bdirect:auto

encoded 5203 frames, 291.98 fps, 17938.50 kbps, 371.25 MB
encode time 0:00:17, CPU: 3.4%, GPU: 5.7%, VE: 92.6%, VD: 36.5%, GPUClock: 1870MHz, VEClock: 1680MHz
frame type IDR   18
frame type I     18,  avgQP  20.00,  total size    5.93 MB
frame type P   1301,  avgQP  23.00,  total size  157.34 MB
frame type B   3884,  avgQP  25.00,  total size  207.98 MB

Would you share me the exact command line option, and the resolution of the video you're trying?

SK-Hardwired commented 4 years ago

Thank you for reply. I have 456.55 ver Nvidia Driver. Rebooted. Made delete NvencC and unzip again from recent build 5.15

String:

D:\3D Tools\NvencC>NVEncC64.exe --avhw -c h264 --profile high --vbrhq 25000k --audio-copy -u P7 --strict-gop --lookahead 32 --aq --aq-temporal -i "D:\Video Projects\mp4 G5 source\[2K]126_Colorful_Umbrella.mp4" -o "D:\Video Projects\mp4 G5 source\[2K]126_Colorful_Umbrella.m2ts" --level 4.1
--------------------------------------------------------------------------------
D:\Video Projects\mp4 G5 source\[2K]126_Colorful_Umbrella.m2ts
--------------------------------------------------------------------------------
nvenc : Failed to Initialize the encoder
nvenc : .: 8 (NVENC indicates that one or more of the parameter passed to the API call is invalid.)

Tried to simplify sting to match your example:

D:\3D Tools\NvencC>NVEncC64.exe -i "D:\Video Projects\mp4 G5 source\[2K]126_Colorful_Umbrella.mp4" -o "D:\Video Projects\mp4 G5 source\[2K]126_Colorful_Umbrella.m2ts" --level 4.1
--------------------------------------------------------------------------------
D:\Video Projects\mp4 G5 source\[2K]126_Colorful_Umbrella.m2ts
--------------------------------------------------------------------------------
nvenc : Failed to Initialize the encoder
nvenc : .: 8 (NVENC indicates that one or more of the parameter passed to the API call is invalid.)

What am I doing wrong?

If not specify --level parameter, even complicated strings work fine (except of produce stream not that level I want):

D:\3D Tools\NvencC>NVEncC64.exe --avhw -c h264 --profile high --vbrhq 25000k --audio-copy -u P7 --strict-gop --lookahead 32 --aq --aq-temporal -i "D:\Video Projects\mp4 G5 source\[2K]126_Colorful_Umbrella.mp4" -o "D:\Video Projects\mp4 G5 source\[2K]126_Colorful_Umbrella.m2ts"
--------------------------------------------------------------------------------
D:\Video Projects\mp4 G5 source\[2K]126_Colorful_Umbrella.m2ts
--------------------------------------------------------------------------------
NVEncC (x64) 5.15 (r1658) by rigaya, Sep 12 2020 15:05:21 (VC 1916/Win/avx2)
OS Version     Windows 10 x64 (19041)
CPU            Intel Core i7-6700HQ @ 2.60GHz (4C/8T)
GPU            #0: GeForce GTX 1060 (1280 cores, 1670 MHz)[PCIe3x16][456.55]
NVENC / CUDA   NVENC API 10.0, CUDA 11.1, schedule mode: auto
Input Buffers  CUDA, 44 frames
Input Info     avcuvid: H.264/AVC, 1920x1080, 60000/1001 fps
Vpp Filters    copyDtoD
Output Info    H.264/AVC high @ Level auto
               1920x1080p 1:1 59.940fps (60000/1001fps)
               avwriter: h264, aac => mpegts
Encoder Preset quality
Rate Control   VBR
Multipass      2pass-full
Bitrate        25000 kbps (Max: 60000 kbps)
Target Quality auto
Initial QP     I:20  P:23  B:25
VBV buf size   auto
Lookahead      on, 32 frames, Adaptive I, B Insert
GOP length     600 frames
B frames       3 frames [ref mode: disabled]
Ref frames     3 frames
AQ             on(spatial, temporal, strength auto)
Others         mv:auto cabac deblock adapt-transform:auto bdirect:auto

encoded 5280 frames, 190.15 fps, 24732.24 kbps, 259.71 MB
encode time 0:00:27, CPU: 10.3%, GPU: 5.0%, VE: 94.6%, VD: 30.7%, GPUClock: 1863MHz, VEClock: 1675MHz
frame type IDR   20
frame type I     20,  avgQP  12.15,  total size    9.72 MB
frame type P   1322,  avgQP  13.74,  total size  202.59 MB
frame type B   3938,  avgQP  19.56,  total size   47.39 MB

After all I guess that this may be due to changes in recent Nvidia drivers versions. Sorry, can't roll back to 451.xx version, this will be complicated.

wwaag76 commented 4 years ago

Note this in you command line. --aq --aq-temporal The double --aq is likely your problem.

rigaya commented 4 years ago

Would you please try --level 4.2? 1080p 60fps requires H.264 level 4.2, and is not supported by H.264 level 4.1. https://en.wikipedia.org/wiki/Advanced_Video_Coding#Levels

With 1080p 60fps, H.264 level 4.1 will crush (this is expected).

x64\NVEncC64.exe -i Cat-1920x1080@60fpsRef4.m2ts -o F:\temp\test.mp4 --level 4.1
--------------------------------------------------------------------------------
F:\temp\test.mp4
--------------------------------------------------------------------------------
nvenc : Failed to Initialize the encoder
nvenc : .: 8 (NVENC indicates that one or more of the parameter passed to the API call is invalid.)

But with H.264 level 4.2, it shall be fine.

x64\NVEncC64.exe -i Cat-1920x1080@60fpsRef4.m2ts -o F:\temp\test.mp4 --level 4.2
--------------------------------------------------------------------------------
F:\temp\test.mp4
--------------------------------------------------------------------------------
NVEncC (x64) 5.16 (r1664) by rigaya, Sep 15 2020 20:23:29 (VC 1927/Win/avx2)
OS Version     Windows 10 x64 (18363)
CPU            Intel Core i9-7980XE @ 2.60GHz [TB: 4.10GHz] (18C/36T)
GPU            #1: GeForce GTX 1060 6GB (1280 cores, 1708 MHz)[PCIe3x16][451.67]
NVENC / CUDA   NVENC API 10.0, CUDA 11.0, schedule mode: auto
Input Buffers  CUDA, 20 frames
Input Info     avcuvid: H.264/AVC, 1920x1080, 60000/1001 fps
Vpp Filters    copyDtoD
Output Info    H.264/AVC high @ Level 4.2
               1920x1080p 1:1 59.940fps (60000/1001fps)
               avwriter: h264 => mp4
Encoder Preset default
Rate Control   CQP  I:20  P:23  B:25
Lookahead      off
GOP length     600 frames
B frames       3 frames [ref mode: disabled]
Ref frames     3 frames
AQ             off
Others         mv:auto cabac deblock adapt-transform:auto bdirect:auto

encoded 3060 frames, 303.84 fps, 28079.48 kbps, 170.88 MB
encode time 0:00:10, CPU: 3.2%, GPU: 5.8%, VE: 91.1%, VD: 41.1%, GPUClock: 1886MHz, VEClock: 1695MHz
frame type IDR    6
frame type I      6,  avgQP  20.00,  total size   1.95 MB
frame type P    765,  avgQP  23.00,  total size  81.72 MB
frame type B   2289,  avgQP  25.00,  total size  87.22 MB
SK-Hardwired commented 4 years ago

Dear @rigaya ,

So simple! I forgot about these different levels' restrictions. :( My bad. --level 4.2 and higher work fine.

Interesting, nor NvencC nor ffmpeg display any simple to understand warning/explanation why some level settings can fail on some files. That's confusing.

Now it's clear