Skip to content

Instantly share code, notes, and snippets.

@rondhi
Last active February 8, 2024 11:49
  • Star 17 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save rondhi/f9163e7649aa734b5421a8f58bd6c49e to your computer and use it in GitHub Desktop.
How to stream games from OBS directly from Steam Deck's Gaming Mode

How to stream games from OBS directly from Steam Deck's Gaming Mode (as of 2023-02-26)

DISCLAIMER: As with any guide, please make sure to read through and understand everything before following the steps in this guide. I'm not responsible for you breaking anything on your own device. This guide assumes you have a little background with the linux command line as well as the text editor nano. If not, please educate yourself


Description: It's possible to stream Vulkan and OpenGL games from Gaming Mode on your Steam Deck. This guide is heavily based on robertkirkman's guide, which is linked multiple times throughout this guide. Much thanks to them


Basic summary

  1. Install OBS Studio and OBS VkCapture Plugin via flatpak
  2. Add OBS Studio to Steam
  3. Install rwfus Read-Write OverlayFS for Steam Deck
  4. Add the chaotic-aur repository
  5. Install obs-vkcapture-git via chaotic-aur
  6. Add Game Capture source to OBS
  7. Edit game launch options

In Steam Deck Desktop Mode

1. Install OBS Studio and OBS VkCapture Plugin via flatpak

  • OBS Studio
  • OBS VkCapture Plugin
  • Note: You may notice that the Discover Store also has an OBS VkCapture tools but I haven't been able to get a game capture going that way. I was only able to get a game capture by installing obs-vkcapture via command line/AUR.

According to OBS VkCapture Github

If you use Flatpak OBS, you need to install Flatpak OBS plugin. For capturing games outside Flatpak runtime, you need native build regardless of if you are using Flatpak OBS or not.

OBS-flatpak-install

2. Add OBS Studio to Steam (Source)

a. From the start menu, find OBS Studio, right-click, and add OBS Studio to Steam. I also recommend adding it to your favorites in Steam.

b. In order to get OBS Studio to launch in Gaming Mode: In Steam, edit the launch options for OBS Studio:

LD_PRELOAD= OBS_USE_EGL=1 QT_QPA_PLATFORM=xcb %command% run --branch=stable --arch=x86_64 --command=obs com.obsproject.Studio

OBS-launch-options

3. Install rwfus Read-Write OverlayFS for Steam Deck Source

These instructions may not be up-to-date. Visit the rwfus github page for up-to-date installation instructions.

The advantage of using an OverlayFS is that any packages you install via pacman or AUR will persist even after a SteamOS update. We want to use the dev branch of rwfus because it's been updated for SteamOS 3.4.

Open up the the terminal app (by default, it's Konsole on SteamOS). Keyboard shortcut is usually CTRL+ALT+T. Enter the following commands one by one.

cd ~
wget -O rwfus.zip https://github.com/ValShaped/rwfus/releases/download/v0.4.1-beta1/rwfus-0.4.1-beta1.zip && unzip rwfus.zip -d rwfus
cd rwfus
chmod +x rwfus

These commands download the latest rwfus release. Side note: if you don't have a sudo password set up, use passwd, then enter the rest of the commands to install rwfus.

sudo ./rwfus --install
sudo pacman-key --init
sudo pacman-key --populate
sudo pacman -Sy

4. Add the chaotic-aur repository

First, you should educate yourself on what the Arch User Respository (AUR) is. It's a community driven repository which is meant to help users build packages from source. It's up to the user to verify the contents of the package.

The Chaotic AUR is a repository of pre-built packages. Please see this on the safety of using Chaotic AUR and AUR in general. Is chaotic-aur safe to use?

Add the chaotic repository to your list of repository mirrors. Find up-to-date instructions here

sudo pacman-key --recv-key FBA220DFC880C036 --keyserver keyserver.ubuntu.com
sudo pacman-key --lsign-key FBA220DFC880C036
sudo pacman -U 'https://cdn-mirror.chaotic.cx/chaotic-aur/chaotic-keyring.pkg.tar.zst' 'https://cdn-mirror.chaotic.cx/chaotic-aur/chaotic-mirrorlist.pkg.tar.zst'

Now to add the chaotic-aur mirror to the repository list. We do this by appending some text to the end of the /etc/pacman.conf file. You can do this by editing the file with nano or vi with root access.

sudo nano /etc/pacman.conf
[chaotic-aur]
Include = /etc/pacman.d/chaotic-mirrorlist

Finally, refresh the repository list

sudo pacman -Sy

5. Install obs-vkcapture-git via chaotic-aur

sudo pacman -S obs-studio chaotic-aur/obs-vkcapture-git

After confirming, you should have obs-vkcapture installed. You can make sure you have it installed by typing

obs-vkcapture

And you should see something like

WARNING: Please use obs-gamecapture instead.
ERROR: No program supplied

Usage: obs-gamecapture <program>

7. Add Game Capture source to OBS

  • You can add a Game Capture source within OBS. Default settings are fine.
  • I suggest right-clicking the source and selecting Transform > Fit to Screen so it fits to the canvas no matter what resolution you're playing at.

add-game-capture-source

8. Edit game launch options

Once you have obs-vkcapture installed, edit a game's launch options with the line below. The Game Capture source will capture whatever game you're running with these launch options:

obs-gamecapture %command%

edit-game-launch-options

In Steam Deck Gaming Mode

  1. Press the Steam button. Go to Library. Press R1 until you get to NON-STEAM. Launch OBS Studio (you can also find it in your Favorites if you favorited it earlier in the guide)
  2. Press the Steam button. Go to Library. Launch your desired game
  3. As long as the game you choose supports OpenGL or Vulkan, OBS Studio should be able to capture that game.
  4. Have fun streaming on the go!

OBS-gaming-mode

Note: Even if the game is OpenGL or Vulkan, there's no guarantee that OBS will be able to capture the game. Your mileage may vary.

Other tips

  • If you don't want to pull from chaotic AUR all the time, you can remove the repository from pacman.conf by commenting out the lines with # and then refresh the repository list:
#[chaotic-aur]
#Include = /etc/pacman.d/chaotic-mirrorlist
  • You can use Droidcam OBS plugin to use your smartphone as a webcam source in OBS. More info here
  • Another possible smartphone-as-a-camera method is VDO Ninja
  • If you want to isolate game audio, you can use Helvum (found in Discover Store) and a Jack audio source within OBS to isolate the game sounds
  • In case you want to stream over to Discord or something, you can enable Virtual Camera in OBS

Install OBS VirtualCam (Source)

sudo pacman -S linux-neptune-headers libappindicator-gtk3
sudo pacman -S v4l2loopback-dkms v4l2loopback-utils

Support

If you need any support, feel free to post open a support post in the help channel on the Steam Deck discord and tag @rondhi#1234

@OpenBagTwo
Copy link

Thank you so much for this guide, and thank you to @ValShaped for the amazing work on rwfus--following this guide to the letter got obs recording working, and, as a bonus, I can now install anything from the full arch package repository and AUR on my Deck!

@ValShaped
Copy link

ValShaped commented Jan 18, 2023

Doing Step 4 inside Rwfus is going to break updating when Valve adds a package to the base OS with dependencies installed inside the overlay. It's a known issue, (See #20,) and I'm not sure how (or if there's even a way) to fix it without somehow limiting what people can do. steamos-devmode enable will do step 4 in a Valve-sanctioned way, at the least.

Otherwise, awesome work!

Regarding rwfus -iI, the capital I installs the rwfus scripts to [/home/.steamos/offload]/usr/local/bin so you can do rwfus -d and rwfus -e from anywhere. It piggybacks off Valve's "SteamOS Offload". As of recently, -i also inits pacman for you. :D

@rondhi
Copy link
Author

rondhi commented Jan 18, 2023

@ValShaped

Doing Step 4 inside Rwfus is going to break updating when Valve adds a package to the base OS with dependencies installed inside the overlay. It's a known issue, (See ValShaped/rwfus#20,) and I'm not sure how (or if there's even a way) to fix it without somehow limiting what people can do.

I have experienced SteamOS breaking after the recent SteamOS updates. I couldn't figure out if it was steamos-btrfs or rwfus, or a combination of both. I always just reinstalled SteamOS and started from scratch (which kinda defeats the purpose of rwfus).

steamos-devmode enable will do step 4 in a Valve-sanctioned way, at the least.

Seems this is a better way of doing it. Does this mean that the guide should omit installing rwfus, or have rwfus installed and then run this command instead of Step 4?

I appreciate the feedback. And great work on rwfus! 🫡

@ValShaped
Copy link

Enabling steamos-devmode should be done with Rwfus disabled/uninstalled, or you'll run into the same issue. Devmode doesn't persist through updates, though, if I remember right.

However, if you intend to install one version of OBS, and then keep it that way, it should be fine to enable devmode on one version, then enable Rwfus and install OBS on that version. If you're going that route, you don't really even need Rwfus; the functionality is built into SteamOS (via Steamos-Offload. Do systemctl enable usr-local.mount and then install OBS (and associated libraries) to /usr/local/bin and /usr/local/lib.

Lastly, thanks! I'm looking forward to working on Rwfus more, to make it safer and less prone to breakage where possible.

@tepiloxtl
Copy link

tepiloxtl commented Mar 16, 2023

So if I don't want to deal with rwfus potentially borking my system, can I do steamos-devmode enable, then add chaotic-aur, refresh pacman repos, install chaotic-aur/obs-vkcapture-git, remove chaotic-aur repo, refresh pacman repos again and finally do steamos-readonly enable, and that should basically put me back to normal operation except that obs-vkcapture is installed, but I'll lose it on system update, right?

@ValShaped
Copy link

Yep, that sounds correct.

@Kiwii
Copy link

Kiwii commented Mar 25, 2023

Despite what's stated on the VkCapture github page, it's actually possible (and quite simple) to use the vulkan layer and opengl preload libraries provided by the capture tools flatpak. You do not need a native build, which means there's no need to mess with the read-only filesystem, devmode or hacky overlay shenanigans.

Get OBS, the VkCapture plugin, and the capture tools from flathub:

flatpak install com.obsproject.Studio
flatpak install com.obsproject.Studio.Plugin.OBSVkCapture
flatpak install org.freedesktop.Platform.VulkanLayer.OBSVkCapture//22.08

The flatpak installs the obs-gamecapture script, libraries, and layer definitions into a folder structure under:
/var/lib/flatpak/runtime/org.freedesktop.Platform.VulkanLayer.OBSVkCapture/x86_64/22.08/active/files

Copy the obs-gamecapture script from the flatpak into a local folder (e.g. ~/.local/bin), make sure it is in your $PATH (echo 'export PATH="$PATH:$HOME/.local/bin"' >> ~/.bash_profile) and modify the paths inside the script to point to the actual install location outside the flatpak sandbox.

For convenience, here's the modified file: ~/.local/bin/obs-gamecapture

Copy the vulkan layer definitions from the flatpak into ~/.local/share/vulkan/implicit_layer.d/ and adjust the paths to the library files inside.

For convenience, here's the modified files:

~/.local/share/vulkan/implicit_layer.d/obs_vkcapture_64.json
~/.local/share/vulkan/implicit_layer.d/obs_vkcapture_32.json

You can now add obs-gamecapture %command% to the launch options of your game on Steam and it should work with pretty much any game.

Edit: Also it seems to not be necessary anymore to edit the OBS launch options. Just add the OBS shortcut to Steam and it'll work in game mode.

@rondhi
Copy link
Author

rondhi commented Mar 26, 2023

@Kiwii Very good info! I'll give this a try.

@Kiwii
Copy link

Kiwii commented Mar 29, 2023

I came across another cool solution that lets you record/stream the entire gamescope session just with things you can get via flatpak and without doing hacky things like ffmpeg kmsgrab and local network loopback.

Just get OBS and the OBS GStreamer plugin:

flatpak install com.obsproject.Studio
flatpak install com.obsproject.Studio.Plugin.Gstreamer

Then open OBS and add a GStreamer Source and replace the example pipeline with:

pipewiresrc do-timestamp=True ! video.

I unticked the first four checkmarks about time stamps and syncing because I got some weird pausing in the video and that seemed to fix it but I'll gladly admit I don't really know what I'm doing here.

You can get audio just by adding an Output Capture (PulseAudio). Or you can use a JACK Input and connect it manually with a patchbay if you want to single out the game audio and avoid capturing a VOIP call or media player.

For me the pipewiresrc in the GStreamer pipeline automatically connected to Gamescope's Pipewire output but if that for some reason doesn't happen, you can also use a patchbay like qpwgraph or helvum (both are on flathub) to connect it.

I'm sure somebody who actually knows how GStreamer pipelines work could improve it (I think you can add a queue and tell it to drop frames if OBS doesn't keep up to avoid building up latency or things like that)

@trebllaw
Copy link

trebllaw commented Apr 5, 2023

@Kiwii followed your solution to avoid having to mess with the read only file system but if I add a Game Capture source to OBS, its just black (i think since no game is running, its the default behavior). When i modify launch options of a game to have "obs-gamecapture %command%", game auto closes and switches back to OBS. any ideas?

@Kiwii
Copy link

Kiwii commented Apr 5, 2023

@trebllaw Are you sure you have the obs-gamecapture script in a folder that is in your $PATH ? You could put the full path to it in the launch options to rule out that issue. Other than that, I think I saw there was an update to the VkCapture plugin a few days ago so it's possible the layer files might need to be changed to have the correct version info but I'm not sure (I haven't tested it since).

The capture source being black when no game is running is normal, yes.

Are you trying to record a Steam game, or a non-Steam game added to Steam?

@trebllaw
Copy link

trebllaw commented Apr 5, 2023

@Kiwii yep. did echo $PATH and seeing /home/deck/.local/bin on there. You mean on launch options instead of "obs-gamecapture %command%" use "/home/deck/.local/bin/obs-gamecapture %command%" instead?

I'm trying to stream a steam game, but will also test it on a non-Steam game added to Steam.

EDIT: Adding in the full path worked. Not sure what I did wrong, but I'm seeing the full path on where i saved it on $PATH

@Kiwii
Copy link

Kiwii commented Apr 5, 2023

@trebllaw The environment can be different in your terminal in desktop mode vs Steam in gaming mode (or even Steam in desktop mode) depending on what file you're using to add ~/.local/bin to $PATH as not all files will be sourced in all situations.

For example, SteamOS' default ~/.bashrc file has a check at the beginning that exists if it doesn't detect an interactive shell:

# If not running interactively, don't do anything
[[ $- != *i* ]] && return

So anything added in ~/.bashrc after that line will probably only be set for things you run from a terminal. That's why I'm setting it in ~/.bash_profile.

@rondhi
Copy link
Author

rondhi commented Apr 5, 2023

I tried the vkcapture via flathub method. I got it working in Desktop mode, but games wouldn't launch in Gaming mode. However, the gstreamer method seemed easy enough to get working. I like the idea of using gstreamer since you don't even need to touch the command line if you install obs and the obs-gstreamer plugin via the Discover Store.

I think this pipeline should get frames to drop:

pipewiresrc do-timestamp=True ! queue max-size-buffers=100 max-size-time=1000000000 ! video.

@Kiwii
Copy link

Kiwii commented Apr 5, 2023

@rondhi

I tried the vkcapture via flathub method. I got it working in Desktop mode, but games wouldn't launch in Gaming mode.

Could be the same problem that $PATH is set differently in gaming mode so it doesn't include the location of the obs-gamecapture script as I discussed with trebllaw in the previous comments

@rondhi
Copy link
Author

rondhi commented Apr 7, 2023

That seems to be the case. My $PATH showing in gaming mode via Konsole:

/usr/local/bin:/usr/bin

@L1Z3
Copy link

L1Z3 commented Jul 25, 2023

I came across another cool solution that lets you record/stream the entire gamescope session just with things you can get via flatpak and without doing hacky things like ffmpeg kmsgrab and local network loopback.

just in case anyone comes across this and is trying to use the pacman version of obs-gstreamer like I was and was confused why it wasn't working, try additionally installing:
gstreamer-vaapi gst-plugin-pipewire gst-plugins-bad-libs gst-plugins-good

@atsen-dev
Copy link

ANy way now to use OBS in Gem mode without use of pacman or any system modification ?

@rondhi
Copy link
Author

rondhi commented Aug 7, 2023

I haven't updated my guide in a while, but I currently recommend Kiwii's gstreamer method here. You can do all this without having to touch the terminal.

  1. Install OBS and OBS Gstreamer Plugin from the Discover store (this store is also known as flatpak).

  2. To make OBS launchable from Gaming Mode: add OBS to Steam and edit the launch options:

LD_PRELOAD= OBS_USE_EGL=1 QT_QPA_PLATFORM=xcb %command% run --branch=stable --arch=x86_64 --command=obs com.obsproject.Studio
  1. Open OBS and add a Gstreamer source into OBS and replace the example pipeline with:
pipewiresrc do-timestamp=True ! queue max-size-buffers=100 max-size-time=1000000000 ! video.
  1. Make the source fit to screen so it'll display no matter the resolution of the game. Right-click your newly-created Gstreamer source > Transform > Fit to screen

  2. Add an Output Output Capture to capture the audio from the Steam Deck. See Kiwii's instructions if you wanna specifically capture game audio

@csc-chicken
Copy link

Such a damn good explaination @rondhi .GStreamer is really great. I have one improvement to tell you. maybe use the gstreamer VA-API plugin is better.

@carpeggios
Copy link

carpeggios commented Nov 28, 2023

I've followed the instruction and got OBS to capture video in Gaming Mode, but only of the OBS program itself. The OBS hangs the recording as soon as I press Steam button, and swap process (to a game, etc.) Any ideas as to how to keep the OBS running in background?

I'm using the GStreamer plugin, and methods described by @Kiwii @rondhi above.

UPDATE: found a weird behavior with GStreamer method;

Was finally able to keep OBS recording up until game launch. The recording was now able to record swapping to Library and subsequent Steam menus. However, in order to do this, I went to 'Decky Plugin browser' (which opened a Steam Web browser), and then when I pressed the Steam button at this point, OBS would no longer hang.

Upon launching a game from this point, the game would eventually pause the OBS instance/recording. Pressing B, or swapping back into OBS instance would resume the recording.

https://streamable.com/bkrwz1

Here you can see the hang-ups and workaround, at least to access library.

Sorry not knowleadgable with the way it makes xwayland windows, but does it spawn a new instance for each of these steps it's getting hung up on? By opening library from Decky plugin, it's becomes a nested instance and doesn't have to swap?

Is there anyway to tell the gstreamer pipeline to swap to the foreground/focused xwayland instance? That way the Gstreamer always has something to stream and doesn't hang?

@X-m7
Copy link

X-m7 commented Dec 5, 2023

The recording doesn't pause with the GStreamer method for me (both when switching back to the library view as well as when switching to games), but the colours in the capture look quite dark, like this:

20231206022550_1

@rondhi
Copy link
Author

rondhi commented Dec 7, 2023

I noticed this behavior. This didn't happen before 3.5 went stable. My workaround was to apply a color correction filter. Play around with the gamma/contrast until you get a color that works for you.

The recording doesn't pause with the GStreamer method for me (both when switching back to the library view as well as when switching to games), but the colours in the capture look quite dark, like this:

20231206022550_1

@RblSb
Copy link

RblSb commented Dec 15, 2023

About darker colors, there is another workaround without playing with filters. It's funny, but you just need to install decky recorder.
Then, before opening OBS, enable replay mode in decky recorder, open OBS, and you will get good colors in OBS preview and recordings. Decky recorder replay can be disabled after you opened OBS.

This hack works probably because they both use gstreamer and override some parameters for each other. I don't really know what exactly, and it is pain in ass to change and test complex gstreamer args for obs, but still, there's my 2 cents.

@itzzjd123
Copy link

Hey so I am trying my absolute best at implying the obs-gamecapture %command% into one of my emulator games launch options. Any idea as to how?

The games launch option is vblank_mode=0 %command% -f -g "'/home/deck/Emulation/roms/switch/Animal Crossing New Horizons [01006F8002326000] [v1835008] (1G+1U+3D).xci'"

image

@rondhi
Copy link
Author

rondhi commented Dec 20, 2023

@itzzjd123

vblank_mode=0 %command% -f -g "'/home/deck/Emulation/roms/switch/Animal Crossing New Horizons [01006F8002326000] [v1835008] (1G+1U+3D).xci'"

Should be something like

vblank_mode=0 obs-gamecapture %command% -f -g "'/home/deck/Emulation/roms/switch/Animal Crossing New Horizons [01006F8002326000] [v1835008] (1G+1U+3D).xci'"

I don't know if that will work. I haven't touched vkcapture in forever since I prefer to use the gstreamer method now.

@itzzjd123
Copy link

@rondhi it worked thanks!

@L1Z3
Copy link

L1Z3 commented Jan 2, 2024

@Kiwii Your guide for getting obs-gamecapture working without any overlays works great, thanks! But just today I noticed that it stopped working. Upon further investigation it seems that libobs_glcapture.so has moved, probably due to an update to the Flatpak. To fix this, I just modified your obs-gamecapture script so it looks in the new directory, changing

LD_LIBRARY_PATH="${LD_LIBRARY_PATH}${LD_LIBRARY_PATH:+:}${lib_path}/x86_64-linux-gnu/:${lib_path}/i386-linux-gnu/"

to

LD_LIBRARY_PATH="${LD_LIBRARY_PATH}${LD_LIBRARY_PATH:+:}${lib_path}/x86_64-linux-gnu/:${lib_path}/i386-linux-gnu/:${lib_path}/x86_64-linux-gnu/obs_glcapture/:${lib_path}/i386-linux-gnu/obs_glcapture/"

in your script. Thanks again for the guide!

@SuDunPo
Copy link

SuDunPo commented Jan 17, 2024

Hi! but how to remove black bars on the sides on the stream?

@Frankenmint
Copy link

Hi! but how to remove black bars on the sides on the stream?

that has to do with your settings for the resolution based on the emulator and also on the obs i'd suspect. Check to see if you can set the emulator to remove the black bars but if you stretch it across the screen it may not fit the native resolution, (think nintendo game in 4:3) and will look stretched funny. I know my punchOut game for NES has horizontal black bars and im certain that they will show on the screen if I mess with it.

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