ffmpeg -f kmsgrab is failing: Failed to open DRM device.

Hi’m exploring game/desktop capturing via ffmpeg.
Unfortunately i noticed that when the gpu use is high and i capture the desktop via x11grab, the whole thing starts to stutter a lot, so i wanted to try kmsgrab instead.
Unfortunately, it is not working, see:

koko@slimer# sudo cat /sys/module/nvidia_drm/parameters/modeset

koko@slimer# sudo setcap cap_sys_admin+ep /usr/bin/ffmpeg 

koko@slimer# ffmpeg  -device /dev/dri/card0 -f kmsgrab -i  - -f image2pipe -
ffmpeg version n4.2.1 Copyright (c) 2000-2019 the FFmpeg developers
  built with gcc 9.2.0 (GCC)
  configuration: --prefix=/usr --disable-debug --disable-static --disable-stripping --enable-fontconfig --enable-gmp --enable-gnutls --enable-gpl --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libdav1d --enable-libdrm --enable-libfreetype --enable-libfribidi --enable-libgsm --enable-libiec61883 --enable-libjack --enable-libmodplug --enable-libmp3lame --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libv4l2 --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxcb --enable-libxml2 --enable-libxvid --enable-nvdec --enable-nvenc --enable-omx --enable-shared --enable-version3
  libavutil      56. 31.100 / 56. 31.100
  libavcodec     58. 54.100 / 58. 54.100
  libavformat    58. 29.100 / 58. 29.100
  libavdevice    58.  8.100 / 58.  8.100
  libavfilter     7. 57.100 /  7. 57.100
  libswscale      5.  5.100 /  5.  5.100
  libswresample   3.  5.100 /  3.  5.100
  libpostproc    55.  5.100 / 55.  5.100
[kmsgrab @ 0x56355affb7c0] Failed to open DRM device.
pipe:: Invalid argument

Is that expected?

Could, please, a developer jump in and tell me if i can stop to try to make it work as it is supposed to not?

i modified my system configuration to disable nvidia modeset:

koko@slimer# sudo cat /sys/module/nvidia_drm/parameters/modeset

Now ffmpeg is failing in another way:

[kmsgrab @ 0x5580a46c64c0] Failed to set universal planes capability: primary planes will not be usable.
[kmsgrab @ 0x5580a46c64c0] Failed to get plane resources: Operation not supported.

…similar results with:

#sudo ./kmsfbshot
Unable to retrieve DRM resources (95).

Snippet of the code producing the error:

res = drmModeGetResources(fd);
    if (!res)
        fprintf(stderr, "Unable to retrieve DRM resources (%d).\n", errno);
        return -errno;

I have exactly the same Issue with the libdrm API. Is there something special missing or is this just not supported?

Unfortunately i never solved this issue.
Then i finally switched to amd :)

1 Like

I was afraid that this was the answer. Does it work with the AMD gpu?

Yes, it does even with intel.

Doing some poking at the device files, I get the impression that as soon as X starts with the Nvidia DDX, the drm device /dev/dri/cardX becomes an inacessible dummy and everything gets re-routed to the /dev/nvidia* device files.

  • from console, the drm node is accessible but due to the lack of a drm console, not much to do there.

Likely working, to be tested, though probably not useful:

  • using the modesetting DDX
  • running Wayland

Edit: tested with the modesetting DDX, kmsfbshot works. Though performance wasn’t actually usable, took ~2sec. So in general, it’s supported but the nvidia DDX disables it.

Thanks for your replies.

@kokoko3k Yeah intel always had the best kernel support for a while, but they cannot compete performance wise.


I get the impression that as soon as X starts with the Nvidia DDX, the drm device /dev/dri/cardX becomes an inacessible dummy and everything gets re-routed to the /dev/nvidia* device files.

Yup, that’s my impression as well. This might be the reason why Wayland is not supported yet. The nvidia driver seems to be pretty borked. The server side solutions for Visual computing aren’t really better. This is frustrating especially from the industry leader. :-(

Before ditching nvidia, i started to use it as a mere graphic accelerator via prime render offload.
Yes, you loose 5% of performance (the same of running a compositor), but i’ve got lower power consumption and a snappier desktop (and kmsgrab working , of course).
Unfortunately, other things like the horrible memory managment made me switch to amd.

Generix is right – the NVIDIA X driver predates drm and doesn’t use drm-kms for modesetting.

If you want to capture the contents of the display in an efficient way, your best bet is probably to use the NVIDIA Capture SDK.

I had the impression the capture APIs were limited to Quadro/Tesla? At least that’s one reason e.g. OBS doesn’t use it.

Well that’s a starting point. Thanks.


It is not that other hardware is not capable of, it is just that the driver explicitely denies to use other hardware to do the task.
Indees, binary patching the driver makes nv capture api work on all other nvidia gpus too (or bypass the maximum number of concurrent encodes), but i don’t know if it is legal.

It is honestly weird, since nv capture api is deprecated on windows in favour of windows system api.

… but i don’t know if it is legal.

No other GPUs are not permitted by the EULA. This is because nVidia is earning from licensing technologies for Datacenters and this would bypass it. Not a strategy that I endorse, but it seems to be the way atm.

I’ll check out the capture SDK anyways, as well. The readme states “An NVIDIA GPU board with a Kepler or later GPU.” as requirement. Before releasing or using a software that is using the SDK, you have to contact nVidia anyways with specific information.

AFAIK, only NvFBC is deprecated and removed in current drivers, NvIFR still working. Since it’s limited to ‘professional graphics’ it’s naught anyway.

Might be interesting if it’s possible to write a minimal drm mirror driver using prime to get the capture in a performant way.

Wouldn’t that require a Prime chipset?

Prime is a software method, not a hardware feature.

1 Like

Intel+kmsgrab+nvidia (with prime render offload) does work indeed and the grabbing itself does not impact the discrete graphic performance.
(prime itself “steals” about 5% of performance on my previous 1060 card)

1 Like