How do i record screen in wayland from terminal?

I want to start a screen recording from a script, so I’m looking for a way to record screen via terminal.

I found the following command on r/kde

sudo ffmpeg -device /dev/dri/card0 -f kmsgrab -i - -filter:v 'hwmap=derive_device=vaapi,scale_vaapi=w=1920:h=1080:format=nv12' -codec:v h264_vaapi recording.mkv

But It gives the following error

sudo ffmpeg -device /dev/dri/card0 -f kmsgrab -i - -filter:v 'hwmap=derive_device=vaapi,scale_vaapi=w=1920:h=1080:format=nv12' -codec:v h264_vaapi recording.mkv

The whole output of the command is

ffmpeg version n6.0 Copyright (c) 2000-2023 the FFmpeg developers
  built with gcc 12.2.1 (GCC) 20230201
  configuration: --prefix=/usr --disable-debug --disable-static --disable-stripping --enable-amf --enable-avisynth --enable-cuda-llvm --enable-lto --enable-fontconfig --enable-gmp --enable-gnutls --enable-gpl --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libdav1d --enable-libdrm --enable-libfreetype --enable-libfribidi --enable-libgsm --enable-libiec61883 --enable-libjack --enable-libjxl --enable-libmfx --enable-libmodplug --enable-libmp3lame --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librav1e --enable-librsvg --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libssh --enable-libsvtav1 --enable-libtheora --enable-libv4l2 --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxcb --enable-libxml2 --enable-libxvid --enable-libzimg --enable-nvdec --enable-nvenc --enable-opencl --enable-opengl --enable-shared --enable-version3 --enable-vulkan
  libavutil      58.  2.100 / 58.  2.100
  libavcodec     60.  3.100 / 60.  3.100
  libavformat    60.  3.100 / 60.  3.100
  libavdevice    60.  1.100 / 60.  1.100
  libavfilter     9.  3.100 /  9.  3.100
  libswscale      7.  1.100 /  7.  1.100
  libswresample   4. 10.100 /  4. 10.100
  libpostproc    57.  1.100 / 57.  1.100
[kmsgrab @ 0x560c331e6f40] Using plane 31 to locate framebuffers.
[kmsgrab @ 0x560c331e6f40] Template framebuffer is 359: 1920x1080 format 30335241 modifier 100000000000002 flags 2.
[kmsgrab @ 0x560c331e6f40] Framebuffer pixel format 30335241 is not a known supported format.
fd:: Invalid argument

Are you using a Intel, AMD or Nvidia graphics card?
If you are using Nvida try h264_nvenc instead of h264_vaapi

Wayland or X11?


  Info: quad core model: 11th Gen Intel Core i5-1135G7 bits: 64 type: MT MCP
    cache: L2: 5 MiB
  Speed (MHz): avg: 1828 min/max: 400/4200 cores: 1: 1709 2: 1181 3: 1617
    4: 2593 5: 1970 6: 1598 7: 2400 8: 1558
  Device-1: Intel TigerLake-LP GT2 [Iris Xe Graphics] driver: i915 v: kernel
  Device-2: Cheng Uei Precision Industry (Foxlink) HP Wide Vision HD Camera
    type: USB driver: uvcvideo
  Display: wayland server: v: with: Xwayland v: 23.1.1
    compositor: kwin_wayland driver: X: loaded: intel dri: i965 gpu: i915
    resolution: 1536x864
  API: OpenGL v: 4.6 Mesa 23.0.2 renderer: Mesa Intel Xe Graphics (TGL GT2)

As the title says Wayland

Sorry, I missed that.

The command you posted didn’t work for me in Plasma(Wayland) or Sway(Wayland).

I found a different command that worked in Sway(Wayland. Arch, AMD) but not in Plasma(Wayland, Arch, AMD)

sudo ffmpeg -f kmsgrab -i - -filter_complex 'hwmap=derive_device=vaapi,hwdownload,format=bgr0' out.mkv
Error in Plasma
Framebuffer pixel format 30335241 is not a known supported format.
fd:: Invalid argument

If I remember, I’ll try on my Tumbleweed/Intel machine (doubt it will be different).

I’m not sure if this is a bug in ffmpeg or intended behavior (security).
This framebuffer stuff is a little bit to difficult for me :frowning_face:

If you have any other Ideas let me know.

1 Like

I decided to use obs-cli to start screen recording from the script I was working on. Anyway thanks for the help