[FFmpeg-user] kmsgrab on non primary card, libva/hwmap advice?

Mark Thompson sw at jkqxz.net
Sat Feb 1 23:13:17 EET 2020

On 30/01/2020 11:00, test wrote:
> Hi All. Thanks in advance for any assistance provided.
> I've been trying to get kmsgrab to work on my second rx570.
> Aim is to record multiple framebuffers on both cards. Both cards are
> maxed in terms of CRTC's, so switching all to one card isn't an
> option. x11grab has not been performant enough.
> I have three "cards":
> /dev/dri/card0 -> intel iGPU
> /dev/dri/card1 -> rx 570
> /dev/dri/card2 -> rx 570
> I have card1 working fine, it's the primary card. I haven't tried card0.
> /home/test/.local/bin/ffmpeg  -framerate 60 -device /dev/dri/card1  -f
> kmsgrab  -i - -vf 'hwmap=derive_device=vaapi,hwdownload,format=bgr0'
> /home/test/card1.mp4
> Whilst trying for card2 and a similar command I get errors.
> I've tried advice under https://trac.ffmpeg.org/wiki/Hardware/VAAPI
> regarding device selection.
> The error doesn't change?
libva has some weird issues with KMS devices which aren't master, and the behaviour might well change between cards in one session depending on which one it decided was the main one.

I think you're on the right track with this:

> ./ffmpeg -init_hw_device
> vaapi=foo:/dev/dri/by-path/pci-0000\:02\:00.0-render
> -filter_hw_device foo -framerate 60 -device /dev/dri/card2  -f kmsgrab
>  -i - -vf 'hwmap=
> derive_device=vaapi,hwdownload,format=bgr0' /home/test/card2.mp4
but it isn't quite there.  The derive_device option asks it to make a new VAAPI device from the KMS/DRM device you have on input rather than using the one on the render device which you created first.

So, try removing the derive_device option from hwmap:

./ffmpeg -init_hw_device vaapi=foo:/dev/dri/by-path/pci-0000\:02\:00.0-render -filter_hw_device foo -framerate 60 -device /dev/dri/card2 -f kmsgrab -i - -vf 'hwmap,hwdownload,format=bgr0' /home/test/card2.mp4

which will then map to your already-created VAAPI render device.

(I assume you've checked carefully that that PCI path matches the right card; it certainly looks plausible to me.)

- Mark

More information about the ffmpeg-user mailing list