Opened 4 months ago

Closed 4 months ago

Last modified 4 months ago

#6989 closed defect (invalid)

Hwaccel cuvid fails with “Error creating a NVDEC decoder: 1”

Reported by: tkalliom Owned by:
Priority: normal Component: avcodec
Version: git-master Keywords: hwaccel cuda cuvid NVDEC
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no


Summary of the bug:

When trying to use an nVidia GPU for decoding video, it fails with the following output (a full trace attached):

[h264 @ 0x558d24633900] NVDEC capabilities:
[h264 @ 0x558d24633900] format supported: yes, max_mb_count: 65536
[h264 @ 0x558d24633900] min_width: 48, max_width: 4096
[h264 @ 0x558d24633900] min_height: 16, max_height: 4096
[h264 @ 0x558d24633900] Error creating a NVDEC decoder: 1
[h264 @ 0x558d24633900] Failed setup for format cuda: hwaccel initialisation returned error.
[h264 @ 0x558d24633900] Format cuda not usable, retrying get_format() without it.

The trace attached is for an AVC video, but the same occurs for HEVC.

The system has two GTX 1080 Tis (1b06 rev a1), and the driver version is 384.111. I have managed to run CUDA programs without problems.

How to reproduce:

% ffmpeg -loglevel trace -hwaccel cuvid -i small.mp4 small2.mp4
ffmpeg version 3.4.git-1
built on gcc 7 (Debian 7.2.0-19)

Attachments (1)

err.txt (205.2 KB) - added by tkalliom 4 months ago.
A trace of a failing run

Download all attachments as: .zip

Change History (7)

Changed 4 months ago by tkalliom

A trace of a failing run

comment:1 Changed 4 months ago by philipl

  • Resolution set to invalid
  • Status changed from new to closed

That command line cannot work, so your results are not surprising.

You either want to use the new nvdec hwaccel, or the old cuvid decoder. In either case, you need different arguments.

To use the old style cuvid decoder:

$ ffmpeg -hwaccel cuvid -c:v h264_cuvid small.mp4 small2.mp4

To use the new style nvdec hwaccel:

$ ffmpeg -hwaccel nvdec small.mp4 small2.mp4

Also note, that neither command line construction will result in the use of nvenc on the encode side. For that, you need:

$ ffmpeg -hwaccel cuvid -c:v h264_cuvid small.mp4 -c:v h264_nvenc small2.mp4


$ ffmpeg -hwaccel nvdec -hwaccel_output_format cuda small.mp4 -c:v h264_nvenc small2.mp4

and then various encoder options to make it realistic.

comment:2 Changed 4 months ago by tkalliom

The option -hwaccel nvdec works without errors. However, something is off, as decoding (e.g. throwing rawvideo to /dev/null) is actually ~15% _slower_ than on CPU...

Also, the documentation seems to be lacking. ffmpeg -hwaccels gives cuvid but no nvdec, the manpage mentions only vdpau, and hwaccel_output_format is only mentioned on wikipages regarding VAAPI.

comment:3 Changed 4 months ago by philipl

I don't know what command line you're attempting, but usually, you'd expect nvdec to be faster than software even after accounting for read-back penalty (remember that for video playback or full hardware transcoding with nvenc you never read decoded frames back to system memory).

nvdec doesn't appear on the -hwaccels list because it's an alias for 'cuda', which is the official option name.

Documentation can always be improved.

comment:4 Changed 4 months ago by tkalliom

My real use case is turning a video to a bunch of bitmaps on a file system for analysis, so there is actually also some color space conversion involved. I tried to focus on decoding and present the simplest possible command line to exhibit the unexpected behavior, but I guess if you simplify too much the examples become inane...

With regards to the performance differences in decoding: I now compared CPU and NVDEC performance using the 3840x2160 HEVC sample at

$ ffmpeg -i fitness-trailer-8000.mkv -f image2pipe -vcodec rawvideo - >/dev/null
Avg. 132FPS on CPU for just decoding and throwing frames away.

$ ffmpeg -hwaccel cuda -i fitness-trailer-8000.mkv -f image2pipe -vcodec rawvideo - >/dev/null
Avg. 107FPS on GPU – 19% slower on just decoding.

$ ffmpeg -i fitness-trailer-8000.mkv -f image2pipe -vcodec rawvideo - > /tmp/frames.dat
Avg. 100FPS on CPU for piping to tmpfs.

ffmpeg -hwaccel cuda -i fitness-trailer-8000.mkv -f image2pipe -vcodec rawvideo - >frames.dat
Avg. 62FPS on GPU – 37% slower.

So, nvdec is decoding slower than software...

comment:5 Changed 4 months ago by oromit

hwaccels do not claim to be way faster than CPUs. They claim to not use any CPU while doing their thing, while still being fast enough for realtime playback.

comment:6 Changed 4 months ago by philipl

I have a 1080 (non Ti) here and I get 219fps with nvdec and 82fps without. You're building ffmpeg from latest source?

Note: See TracTickets for help on using tickets.