Opened 4 years ago

Last modified 7 months ago

#6476 new enhancement

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 (10)

comment:1 Changed 8 months ago by hydra3333

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 8 months ago by hydra3333 (previous) (diff)

comment:2 Changed 8 months ago by hydra3333

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 8 months ago by hydra3333 (previous) (diff)

comment:3 Changed 8 months ago by cehoyos

  • Component changed from undetermined to avcodec
  • Keywords h264 level 5.2 removed
  • Priority changed from normal to wish
  • Type changed from defect to enhancement
  • Version changed from unspecified to git-master

comment:4 Changed 8 months ago by hydra3333

thank you

comment:5 Changed 8 months ago by cehoyos

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

comment:6 Changed 8 months ago by hydra3333

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 Changed 8 months ago by heleppkes

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 Changed 8 months ago by hydra3333

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 Changed 7 months ago by hydra3333

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 7 months ago by hydra3333 (previous) (diff)
Note: See TracTickets for help on using tickets.