Skip to content

Instantly share code, notes, and snippets.

@edrex
Last active April 23, 2024 18:23
Show Gist options
  • Save edrex/82f307c1b35368952849c01a52366769 to your computer and use it in GitHub Desktop.
Save edrex/82f307c1b35368952849c01a52366769 to your computer and use it in GitHub Desktop.
Streaming screen capture under Wayland

Recipes

kmsgrab capture with ffmpeg

sudo LIBVA_DRIVER_NAME=iHD ffmpeg -crtc_id 69  -framerate 60 -f kmsgrab -i - -vaapi_device /dev/dri/renderD128 -filter:v hwmap,scale_vaapi=w=1920:h=1200:format=nv12 -c:v h264_vaapi -profile:v constrained_baseline -level:v 3.1 -b:v 20000k test.mp4

LIBVA_DRIVER_NAME=iHD ffmpeg -device /dev/dri/card0 -f kmsgrab -i - -vf 'hwmap=derive_device=vaapi,scale_vaapi=w=1920:h=1080:format=nv12' -c:v h264_vaapi -vstats output.mp4

Allow kmsgrab capture as non-root user

Unsafe but needed

sudo setcap cap_sys_admin+ep $(which ffmpeg)

Src: https://ffmpeg.org/pipermail/ffmpeg-user/2018-June/040338.html

Wishlist

kms capture to OBS (is there a plugin somewhere?)

Resources

OBS

@ribosomerocker
Copy link

@edrex
Copy link
Author

edrex commented Jan 2, 2022

@MonAaraj the difference is wf-recorder receives the video frames via the wlr-screencopy wayland protocol, while this uses dmabufs to avoid copying, see ammen99/wf-recorder#45

https://hg.sr.ht/~scoopta/wlrobs supports wlr-export-dmabuf for zero-copy capture.

@ribosomerocker
Copy link

Ah, I see! Thank you very much! The reason I commented that was because I was looking for screen recorders other than OBS for Wayland and I found it difficult - I only found wf-recorder and it got the job done, so I thought I might put it here for people who get it from Google like me. Nevertheless, wlrobs seems interesting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment