Opened 7 years ago

Closed 3 years ago

Last modified 3 years ago

#6476 closed enhancement (fixed)

NVENC: "InitializeEncoder failed" error occurs when level 5.2 is specified

Reported by: alexpigment Owned by:
Priority: wish Component: avcodec
Version: git-master Keywords: nvenc
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no


Summary of the bug:

When using h264_nvenc, if -level 5.2 is specified in the command line parameters, the following error is given:

[h264_nvenc @ 0546f2c0] InitializeEncoder failed: invalid param (8)
Error initializing output stream 0:0 -- Error while opening encoder for output s
tream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height
Conversion failed!

While NVENC via FFMPEG will similarly fail if trying to specify a level that is not valid for the current set of parameters, this case is different because it will fail even when the parameters are valid. Leaving off -level 5.2 in this scenario will produce a file that is Level 5.2.

How to reproduce:

% ffmpeg -f lavfi -i smptebars -c:v h264_nvenc -s 3840x2160 -aspect 16:9 -profile:v high -r 59.94 -level 5.2 -t 5 output.mp4

Confirm that the above code fails. Now do the same encode without specifying -level 5.2:

% ffmpeg -f lavfi -i smptebars -c:v h264_nvenc -s 3840x2160 -aspect 16:9 -profile:v high -r 59.94 -t 5 output.mp4

Notice that this works, and produces a video that is Level 5.2 according to MediaInfo.

ffmpeg version N-86330-gbd1179e
built on 2017-06-01

Change History (12)

comment:1 by hydra3333, 4 years ago

according to ffmpeg help, the levels only go up to 5.1 :(

and that's with the git as of two days ago (2020.06.12)

Last edited 4 years ago by hydra3333 (previous) (diff)

comment:2 by hydra3333, 4 years ago

I needed to used level 5.2 or 6 for 4k, and ffmpeg bailed on me.

I had to leave -level off the commandline and hope for the best.

Last edited 4 years ago by hydra3333 (previous) (diff)

comment:3 by Carl Eugen Hoyos, 4 years ago

Component: undeterminedavcodec
Keywords: h264 level 5.2 removed
Priority: normalwish
Type: defectenhancement
Version: unspecifiedgit-master

comment:4 by hydra3333, 4 years ago

thank you

comment:5 by Carl Eugen Hoyos, 4 years ago

Are you sure that the user option level (as far as it currently works) does what you want it to do?

comment:6 by hydra3333, 4 years ago

Sadly, no I am not sure. I do want to encode 4k using an nvidia 2060 Super which I gather goes beyond level 5.1 and I have to leave off -level.

The h.264 spec says it goes to level 6.2,

and the constants in specify up to 5.2 (it may be greater now with newer cards/drivers),

however here (at least) it specifies only to level 5.1,

Thus there seems to be some inconsistency at present.

I'm unsure if the code otherwise checks and constrains it to what a driver may report (not sure where to look for that).

comment:7 by Hendrik, 4 years ago

specifying level only adds constraints, it does not lift them. So if you don't specify a level, it'll use the highest required for your content.

That means that if you want to encode 5.2, there is no need to specify a level, since it'll automatically pick one.

The only reason to specify a level is if you want to constraint yourself to a specific level and not accidentally go over it.

The lack of th 5.2 level in nvenc_h264 should still be fixed, but its not necessarily required to specify it.

comment:8 by hydra3333, 4 years ago

Yes. OK.

As you mention, it would be good to fix, as the omissions remove capacity to specify a valid level lower than the prevailing "upper limit" level.

I wonder if the code checks a specified/calculated level against what the installed hardware/driver allow as an upper limit ?

comment:10 by hydra3333, 4 years ago

I tried it and am happily transcoding videos with this combination of BRAND NEW ffmpeg options

-preset p7 -multipass fullres -rc:v vbr -cq:v 24 -qmin 16 -qmax 48 
-b:v 3746899 -minrate:v 749379 -maxrate:v 7493798 -bufsize 7493798 
-profile:v high -level 5.2 
-movflags +faststart+write_colr

which seems to work (the bitrate selection is auto per-video via a script).

-preset p7 -multipass fullres -rc:v vbr
is the apparently new highest quality (slowest) setting.

No idea if it's a valid combination of options, but something comes out the other end :)

So, -level 5.2 works now.

Last edited 4 years ago by hydra3333 (previous) (diff)

comment:11 by Balling, 3 years ago

Resolution: fixed
Status: newclosed

-level 5.2 works now.

Even the original command works now, LOL and is bitperfect without -level 5.2. Also please note that your command is wrong:

-r 60/1.001 should have been used.

Last edited 3 years ago by Balling (previous) (diff)

comment:12 by Balling, 3 years ago

This is VERY wrong that when you do ffmpeg -f lavfi -i smptebars -c:v h264_nvenc -s 3840x2160 -aspect 16:9 -profile:v high -r 60/1.001 -level 6.2 -t 5 output.mp4

only 2 bytes are changed that say what level it is!! WTF. It should write correct profile which is 5.2 in this case.

Last edited 3 years ago by Balling (previous) (diff)
Note: See TracTickets for help on using tickets.