Pulseaudio and Pipewire streaming audio setup
Over the years Linux gaming has become more and more viable as an alternative Windows gaming. You might have switched to Linux and might be wondering how to capture only the game audio for OBS. Well you have come to the right place! Here I’ll be showing how to setup it up for Pulseaudio and Pipewire.
Pulseaudio setup
To set this up we will be using module-combine-sink. This allows you to combine multiple outputs into one output.
You need to create a virtual output and link it to your real output so that you can hear the game and capture only the game at the same time.
Firstly start by finding the name of your output device by using:
pacmd list-sinks
You can then run this command to create the sink:
pacmd load-module module-combine-sink sink_name="Game" slaves="alsa_output.pci-0000_00_1f.3.analog-stereo"
Make sure you replace the slaves name with your output device name and the sink_name can be changed to what you want output to be called.
Then you can open pavucontrol and you should see a new output device.
The new sink is called ‘Simultaneous ouput to Built-in Audio Analogue Stereo’. For some reason pulseaudio ignores the sink name. This is resolved by Pipewire so I never bothered to find a solution especially as it isn’t that important.
Finally to make it create the combine-sink at startup you need to add it to the user config file in:
~/.config/pulse/default.pa
If you don’t have the folder or file just create it. Then add this to the file:
.include /etc/pulse/default.pa
load-module module-combine-sink sink_name="Game" slaves="alsa_output.pci-0000_00_1f.3.analog-stereo"
The first line tells it to use the information in main pulseaudio config file and then the second line is the command you created beforehand. Make sure to remove pacmd and change the sink_name and slaves to what you ran above.
Pipewire setup
Update 22 Feburary 2022
If you have Pipewire 0.3.45 or newer you don’t need to use a script anymore. Instead you can make a new folder in: ~/.config/pipewire/
called pipewire-pulse.conf.d
.
The full path should be:
~/.config/pipewire/pipewire-pulse.conf.d/
Within this folder make a new file. This can be called whatever you want with .conf
at the end but I will use pipewire-pulse.conf
Finally add the following code to the file:
context.exec = [
{ path = "pactl" args = "load-module module-combine-sink sink_name=StreamingAudio slaves=alsa_output.pci-0000_00_1f.3.analog-stereo" }
]
Make sure to replace the slave name following the rest of the guide. Then just reboot or restart pipewire-pulse to apply the new configuration.
Original Guide
For the Pipewire setup you require Pipewire version 0.3.29 however I recommand at least 0.3.31 as many issues with module-combine-sink were resolved in this version.
Firstly run the following command to find the name of your output device: pactl list sinks
. This output will be very similar to pulseaudio.
Once you have the output name you can then create the combine-sink output device with the command below:
pactl load-module module-combine-sink sink_name="StreamingAudio" slaves="alsa_output.pci-0000_00_1f.3.analog-stereo"
As with Pulseaudio make sure you change the sink_name (if you want) and the slaves to fit your specific setup.
Pipewire has no specific config file to make it run at startup. Hopefully this changes and if it does I will be sure to update the guide. However, there are several ways to make it start at startup regardless. Firstly start by making a bash script:
#!/bin/bash
pactl load-module module-combine-sink sink_name="StreamingAudio" slaves="alsa_output.pci-0000_00_1f.3.analog-stereo"
Replace the second line with the command you have just ran. And then make it executable with the following command: chmod +x path to script
For KDE you can set scripts to run on login in settings. For Gnome it is slightly more complex. I have created an application shortcut by creating a new file in ~/.local/share/applications/StreamingAudio.desktop
with the following information:
[Desktop Entry]
Encoding=UTF-8
Version=1.0
Name=Streaming Audio
Exec=/home/user/StreamingAudio.sh
Comment=
Terminal=false
Type=Application
Hidden=false
Make sure to change the ‘Exec’ path to where your script is located. Then you can open gnome-tweaks and add it as a startup program.
If you want to hide it from your program list just change Hidden=false
to Hidden=true
however make sure you do this after adding the program in gnome-tweaks or it won’t appear preventing you from adding it in gnome-tweaks.
Capturing only the game
To capture the game it’s very simple. Open the program to want to capture and then open pavucontrol. Simply change the output device of the program to your combine-sink output.
Finally open OBS and go to Settings > Audio and ensure that the Desktop Audio is set to your combine-sink output
Conclusion
Congratulations you now know how to stream without it capturing every other application on your system! If anything changes I will make sure to update this guide.