Using OBS studio on Sway with Pipewire

I am on Debian 12 / SWAY desktop which is WLR based.


I first install the "OBS Studio" version 29.0 with:

┌───┐
│ $ │ ziga > ziga--workstation > ~ 
└─┬─┘ /dev/pts/4
  └─> sudo apt install obs-studio

"OBS Studio" can now be started with terminal command:

┌───┐
│ $ │ ziga > ziga--workstation > ~ 
└─┬─┘ /dev/pts/4
  └─> obs

If "OBS Studio" is configured to run on "Xorg" by default we will not see our display! If this is the case we can still force it to run on "Wayland" like this:

┌───┐
│ $ │ ziga > ziga--workstation > ~ 
└─┬─┘ /dev/pts/4
  └─> env QT_QPA_PLATFORM=wayland obs

Now it is surely using "Wayland" but this is still not enough for it to detect the desktop! I tried installing packages:

┌───┐
│ $ │ ziga > ziga--workstation > ~ 
└─┬─┘ /dev/pts/0
  └─> sudo apt install xdg-desktop-portal xdg-desktop-portal-wlr

Attention:
"Sway" is based on "WLR" and therefore we installed xdg-desktop-portal-wlr "portal" implementation for xdg-desktop-portal. Different "portal" implementations exist and should be installed for different desktops. Debian supports "portals" for "KDE" (xdg-desktop-portal-kde), "GTK" (xdg-desktop-portal-gtk) or "Gnome" (xdg-desktop-portal-gnome).

I tested and made a conclusion that it does not matter which "Pipewire session manager" is used. By default people use pipewire-media-session but I use wireplumber which deprecates pipewire-media-session (link).

At this point I get no screens shown in "OBS Studio"! But I am able to record my screen and microphone using a simple CLI video recorder like this:

┌───┐
│ $ │ ziga > ziga--workstation > ~ 
└─┬─┘ /dev/pts/0
  └─> sudo apt install wl-recorder
┌───┐
│ $ │ ziga > ziga--workstation > ~ 
└─┬─┘ /dev/pts/0
  └─> pw-jack wf-recorder -a

And this works like a charm…

It is just "OBS Studio" that fails to work…

Asked By: 71GA

||

Of all the "portals" we only have to install xdg-desktop-portal-wlr:

sudo apt install xdg-desktop-portal xdg-desktop-portal-wlr

Note:
"Portal" xdg-desktop-portal-gnome is very large and will also install an entire Gnome desktop! So do not install this one unkless you use Gnome. In this case it will not make a difference for you.

This will also install a "portal" configuration file in /usrl/share/xdg-desktop/portal/portals/wlr.portal. Inside there is a list variable UseInwhich contains sway and instructs xdg-desktop-portal to use this "portal" if it detects environmental variables XDG_CURRENT_DESKTOP=sway, XDG_SESSION_DESKTOP=sway.

And then we have to export enviromental desktop variables by putting this line in the Sway configuration file ~/.config/sway/config:

exec dbus-update-activation-environment --systemd WAYLAND_DISPLAY DISPLAY SWAYSOCK XDG_CURRENT_DESKTOP=sway XDG_SESSION_DESKTOP=sway

Attention:
These enviromental variables will not work if they are only exported using the /etc/environment. If we want to do it like this, then we also have to import them in Sway by using this line of code in the
~/.config/sway/config:

exec systemctl --user import-environment"
Answered By: 71GA