"Zero-copy" Linux screen capture plugin for OBS that uses libdrm and dmabuf

Related tags

Audio obs-kmsgrab
Overview

linux-kmsgrab plugin for OBS

Introduction

This plugin is a proof-of-concept libdrm-based screen capture for OBS. It uses DMA-BUF to import CRTC framebuffer directly into EGL texture in OBS as a source. This bypasses expensive double GPU->RAM RAM->GPU framebuffer copy that is invoked by anything X11-XSHM-based.

It is Linux-Only, as DMA-BUF is a Linux-only thing. Other platforms might have similar functionality, but I'm totally not an expert.

It is almost completely agnostic of any windowing system you might have: it works reasonably well with both X11 and Wayland, and theoretically could work even with bare KMS terminals.

However, on Wayland I'd recommend using something like https://hg.sr.ht/~scoopta/wlrobs instead -- it also uses DMA-BUF, but supposedly does this in a less hacky way.

Building

It requires latest master OBS, as EGL support is very fresh and has not yet been released. You'll need to compile and install master OBS yourself. Make sure that installation prefix is fed into cmake invocation too, as it needs access to latest OBS headers from master and won't work with any older released version.

Generally it works like this:

# Clone and cd
mkdir build && cd build
export CMAKE_PREFIX_PATH=<master-obs-prefix>
cmake .. -GNinja -DCMAKE_INSTALL_PREFIX="$CMAKE_PREFIX_PATH"
ninja
ninja install

By default this plugin will use Polkit's pkexec to run the linux-kmsgrab-send helper utility with elevated privileges (i.e. as root). This is required in order to be able to grab screens using kms/libdrm API, as we completely sidestep X11/Wayland management of current drm context. When OBS starts you'll be presented with polkit screen asking for root password, and then you'll be asked again when configuring the capture module.

If you don't have Polkit set up, you need to compile this plugin with -DENABLE_POLKIT=NO cmake flag and entitle the linux-kmsgrab-send binary with CAP_SYS_ADMIN capability flag manually, like this:

sudo setcap cap_sys_admin+ep "$CMAKE_PREFIX_PATH/lib64/obs-plugins/linux-kmsgrab-send"

Note that this has serious system-wide security implications: just having this linux-kmsgrab-send binary lying around with caps set will make it possible for anyone having local user on your machine to grab any of your screens. Decide for yourself whether that's a concerning threat model for your situation.

Known issues

  • there's no way to specify grabbing device (in cause you have more than one GPU), it will just use the first available
  • no sync whatsoever, known to rarily cause weird capture glitches (dirty regions missing for a few seconds)
  • no resolution/framebuffer following -- may break if output resolution changes
  • may conflict with some x11 compositors and wayland impls
Comments
  • Installation troubles

    Installation troubles

    Having built/installed both obs-studio and this plugin no new source appears in obs. What is the exact place the files should be placed to? because it doesnt look like installing places them correctly.

    opened by SolitudeSF 12
  • ninja command fails

    ninja command fails

    den2:[den2]:~/Downloads/obs-kmsgrab/build$ ninja [8/9] Building C object CMakeFiles/linux-kmsgrab.dir/src/dmabuf.c.o FAILED: CMakeFiles/linux-kmsgrab.dir/src/dmabuf.c.o /usr/bin/cc -DHAVE_OBSCONFIG_H -DQT_CORE_LIB -DQT_GUI_LIB -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DUSE_PKEXEC -Dlinux_kmsgrab_EXPORTS -I/home/den2/Downloads/obs-kmsgrab/build -I/home/den2/Downloads/obs-kmsgrab -I/home/den2/Downloads/obs-kmsgrab/build/linux-kmsgrab_autogen/include -I/home/den2/Downloads/obs-kmsgrab/src -I/../UI/obs-frontend-api -isystem /usr/include/obs -isystem /usr/include/qt -isystem /usr/include/qt/QtCore -isystem /usr/lib/qt/mkspecs/linux-g++ -isystem /usr/include/qt/QtWidgets -isystem /usr/include/qt/QtGui -fPIC -mmmx -msse -msse2 -fPIC -MD -MT CMakeFiles/linux-kmsgrab.dir/src/dmabuf.c.o -MF CMakeFiles/linux-kmsgrab.dir/src/dmabuf.c.o.d -o CMakeFiles/linux-kmsgrab.dir/src/dmabuf.c.o -c /home/den2/Downloads/obs-kmsgrab/src/dmabuf.c /home/den2/Downloads/obs-kmsgrab/src/dmabuf.c: In function ‘dmabuf_source_open’: /home/den2/Downloads/obs-kmsgrab/src/dmabuf.c:353:41: warning: passing argument 5 of ‘gs_texture_create_from_dmabuf’ makes integer from pointer without a cast [-Wint-conversion] 353 | ctx->fbs.fb_fds + index, | ~~~~~~~~~~~~~~~~^~~~~~~ | | | int * In file included from /usr/include/obs/obs.h:24, from /home/den2/Downloads/obs-kmsgrab/src/xcursor-xcb.h:20, from /home/den2/Downloads/obs-kmsgrab/src/dmabuf.c:2: /usr/include/obs/graphics/graphics.h:973:53: note: expected ‘uint32_t’ {aka ‘unsigned int’} but argument is of type ‘int *’ 973 | enum gs_color_format color_format, uint32_t n_planes, const int *fds, | ~~~~~~~~~^~~~~~~~ /home/den2/Downloads/obs-kmsgrab/src/dmabuf.c:350:24: error: too few arguments to function ‘gs_texture_create_from_dmabuf’ 350 | ctx->texture = gs_texture_create_from_dmabuf(fb->width, fb->height, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/obs/graphics/graphics.h:971:22: note: declared here 971 | EXPORT gs_texture_t *gs_texture_create_from_dmabuf( | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ninja: build stopped: subcommand failed.

    opened by laqyx 0
  • Fixes for OBS 27

    Fixes for OBS 27

    This includes:

    • [x] updated signature for gs_texture_create_from_dmabuf
    • [x] multiple planes with drmGetModeFb2

    This should include:

    • [ ] original drmGetModeFb path for a single-plane query (not all configs support Fb2)

    This does not include:

    • fixes for recent sway/wlroots/... breaking passing dma-buf fds with EGL texture creation returning ENOMEM. This is being investigated
    opened by w23 1
  • Cannot create EGLImage: Arguments are inconsistent

    Cannot create EGLImage: Arguments are inconsistent

    Hi! OBS Studio 27 now require fourcc in gs_texture_create_from_dmabuf function. I edited code and added fourcc, but it doesn't work. I also tried to set fourcc manually, based on this OBS-Studio deleted code, but i get similar error.

    Code:

    ctx->texture = gs_texture_create_from_dmabuf(fb->width, fb->height,
    	GS_BGRA, // FIXME handle fourcc?
    	fb->fourcc,  // i added fourcc there
    	1, // FIXME handle planes
    	ctx->fbs.fb_fds + index,
    	&stride,
    	&offset,
    	NULL // FIXME what are modifiers? we just don't know
    

    Error:

    error: Cannot create EGLImage: Arguments are inconsistent (for example, a valid context requires buffers not supplied by a valid surface).```
    bug help wanted 
    opened by scaledteam 17
  • Proper synchronization

    Proper synchronization

    Figure out whether libdrm provides any APIs for synchronization, and use them to make sure that we're uploading/using the DMA-BUF-backed texture at the right moment.

    opened by w23 0
Owner
Ivan Avdeev
Eclectic Engineer
Ivan Avdeev
OBS Plugin to capture CS:GO with Trusted Mode enabled

OBS Plugin to capture CS:GO with Trusted Mode enabled Ever since Valve introduced Trusted Mode you could no longer capture Counter-Strike: Global Offe

Gregor Steiner 105 Nov 17, 2022
An OBS plugin for removing background in portrait images (video), making it easy to replace the background when screen recording.

OBS Plugin: Background Removal Introduction Building MacOSX Linux / Ubuntu Windows Download Check out the latest releases for downloads and install in

Roy Shilkrot 1.4k Jan 8, 2023
An OBS plugin for Zoom/Meet-like virtual background feature.

OBS Virtual background plugin English / Japanese OBS Virtual background plugin is a plugin for OBS. This plugin allows you to crop the background area

KOUNOIKE Yuusuke 186 Dec 25, 2022
OBS Plugin with image that reacts to sound source.

OBS Image Reaction Plugin Image that reacts to sound source. Installing binaries Download binaries from Releases. For Windows, Move the contents of pl

null 39 Jan 4, 2023
audio monitor filter for OBS Studio

Audio Monitor dock and filter for OBS Studio Plugin for OBS Studio to add Audio Monitor dock and filter. It allows you to put the audio of a OBS sourc

Exeldro 222 Dec 18, 2022
Linux client for Archo Music written in C++, uses Qt Framework.

ArchoMusicLinux Linux client for Archo Music written in C++, uses Qt Framework. For the original client, visit Archo Music Compiling Setting up the li

GianXD 2 Nov 13, 2021
Single file audio playback and capture library written in C.

A single file library for audio playback and capture. Example - Documentation - Supported Platforms - Backends - Major Features - Building - Unofficia

David Reid 2.6k Jan 8, 2023
Capture audio from a microphone on your Raspberry Pi Pico or any RP2040 based board. 🎤

Capture audio from a microphone on your Raspberry Pi Pico or any RP2040 based board. ??

Arm Developer Ecosystem 133 Jan 9, 2023
HamMessenger is a portable device that uses a ham radio and the APRS protocol as a medium to send and receive text messages.

HamMessenger is a portable, battery powered device that runs on a microcontroller and interfaces with an inexpensive ham radio to send and receive text messages and provide position updates using the APRS protocol. Messages and position updates sent via HamMessenger can be viewed on sites such as aprs.fi. HamMessenger messages are NOT encrypted!

null 210 Dec 13, 2022
RetroWave is a hardware sound board series that uses vintage sound chips and works with modern hardware.

RetroWave Authentic sounds from vintage sound chips, on modern hardware! Introduction RetroWave is a hardware sound board series that uses vintage sou

SudoMaker 58 Jan 2, 2023
A weird distortion and lowpass plugin

Delta Limiter Building ./waf clean configure build Documentation pandoc -s user_manual.md -o user_manual.html pandoc -s user_manual.md -o user_manual.

Hannes Braun 3 Sep 19, 2022
PeakEater is a free open-source VST3/AU waveshaper plugin

PeakEater Free open source VST3/AU wave shaping plugin for macOS and Windows. View Demo · Download · Report Bug Table of Contents About The Project Fe

Vladyslav Voinov 45 Dec 17, 2022
BYOD is a guitar distortion plugin with a customisable signal chain that allows users to create their own guitar distortion effects.

BYOD is a guitar distortion plugin with a customisable signal chain that allows users to create their own guitar distortion effects. The plugin contains a wide variety of distortion effects from analog modelled circuits to purely digital creations, along with some musical tone-shaping filters, and a handful of other useful processing blocks.

null 229 Jan 5, 2023
ChowKick is a kick drum synthesizer plugin based on creative modelling of old-school drum machine circuits

ChowKick is a kick drum synthesizer plugin based on creative modelling of old-school drum machine circuits. MIDI input to the plugin triggers a pulse with a parameterized size and shape. The pulse is then passed into a resonant filter which can be tuned to a specific frequency, or matched to the frequency of the incoming MIDI notes.

null 117 Dec 16, 2022
SuperCollider as a VST3 plugin

PluginCollider PluginCollider is an experimental fork of https://github.com/supercollider/SuperColliderAU and it is still not complete since it only b

Pascal Gauthier 33 Dec 23, 2022
Wolf MidiCurve is a MIDI remapping plugin.

Wolf MidiCurve is a MIDI remapping plugin. It can be built as an LV2 or VST plugin and as a standalone Jack application.

Wolf Plugins 8 Oct 21, 2022
Audio Plugin API

Audio Plugin API

null 1.3k Jan 3, 2023
Audacity is an easy-to-use, multi-track audio editor and recorder for Windows, Mac OS X, GNU/Linux and other operating systems

Audacity is an easy-to-use, multi-track audio editor and recorder for Windows, Mac OS X, GNU/Linux and other operating systems. Audacity is open source software licensed under GPL, version 2 or later.

Audacity 8.7k Dec 31, 2022
Sneedacity (formerly Audacity) is an easy-to-use, multi-track audio editor and recorder for Windows, Mac OS X, GNU/Linux and other operating systems.

Sneedacity (formerly Audacity) is an easy-to-use, multi-track audio editor and recorder for Windows, Mac OS X, GNU/Linux and other operating systems. Sneedacity is open source software licensed under GPL, version 2 or later.

Sneed's Feed & Seed 874 Dec 30, 2022