Skip to content

Instantly share code, notes, and snippets.

@AnonymerNiklasistanonym
Last active December 28, 2023 09:53
Show Gist options
  • Save AnonymerNiklasistanonym/ddac288b225d1fc05c3851ed76b2b6ca to your computer and use it in GitHub Desktop.
Save AnonymerNiklasistanonym/ddac288b225d1fc05c3851ed76b2b6ca to your computer and use it in GitHub Desktop.
Linux OBS Configuration to Stream to Twitch audio without saving it to the VOD

With the following configuration it is possible to stream 2 audio sinks to Twitch and then on the VOD mute one of the sinks while at the same time hearing forwarding both audio streams to your headphone audio output/sink.

Pipewire

How to add virtual audio sinks and make them loop back to another audio sink

See what audio sinks exist

pactl list | grep Name                                                                                                         
        Name: libpipewire-module-rt
        Name: libpipewire-module-protocol-native
        Name: libpipewire-module-profiler
        Name: libpipewire-module-metadata
        Name: libpipewire-module-spa-device-factory
        Name: libpipewire-module-spa-node-factory
        Name: libpipewire-module-client-node
        Name: libpipewire-module-client-device
        Name: libpipewire-module-portal
        Name: libpipewire-module-access
        Name: libpipewire-module-adapter
        Name: libpipewire-module-link-factory
        Name: libpipewire-module-session-manager
        Name: module-always-sink
        Name: alsa_output.pci-0000_01_00.1.hdmi-stereo
        Name: alsa_output.usb-Kingston_HyperX_Quadcast_4110-00.analog-stereo
        Name: alsa_output.pci-0000_15_00.6.analog-stereo
        Name: virtual_sink_audio
        Name: virtual_sink_game_audio
        Name: alsa_output.pci-0000_01_00.1.hdmi-stereo.monitor
        Name: alsa_output.usb-Kingston_HyperX_Quadcast_4110-00.analog-stereo.monitor
        Name: alsa_input.usb-Kingston_HyperX_Quadcast_4110-00.analog-stereo
        Name: alsa_input.usb-046d_Logitech_StreamCam_7445CE45-02.analog-stereo
        Name: alsa_output.pci-0000_15_00.6.analog-stereo.monitor
        Name: alsa_input.pci-0000_15_00.6.analog-stereo
        Name: virtual_sink_audio.monitor
        Name: virtual_sink_game_audio.monitor
        Name: audio-volume-change
        Name: alsa_card.pci-0000_01_00.1
        Name: alsa_card.pci-0000_15_00.1
        Name: alsa_card.usb-Kingston_HyperX_Quadcast_4110-00
        Name: alsa_card.usb-046d_Logitech_StreamCam_7445CE45-02
        Name: alsa_card.pci-0000_15_00.6

Create virtual audio sink that loops back to another audio sink

With the following command a virtual sink with the name game_audio_sink is created with the description Game-Audio-Sink as long as the process is not closed:

pw-loopback -m '[ FL FR ]' --capture-props='media.class=Audio/Sink node.name=game_audio_sink node.description=Game-Audio-Sink' --playback-props='target.object="alsa_output.pci-0000_15_00.6.analog-stereo"'

Pulseaudio

Attention: If you use Pulseaudio and virtual sinks the loopback has a considerable amount of additional latency which is very clearly noticeable.

How to add virtual audio sinks and make them loop back to another audio sink

See what audio sinks exist

pacmd list-sinks | grep name:
        name: <alsa_output.pci-0000_15_00.6.analog-stereo>
        name: <alsa_output.usb-Kingston_HyperX_Quadcast_4110-00.analog-stereo>
        name: <alsa_output.pci-0000_01_00.1.hdmi-stereo>

Create virtual audio sink

With the following command a virtual sink with the name game_audio_sink is created with the description Game-Audio-Sink:

load-module module-null-sink sink_name=game_audio_sink sink_properties=device.description=Game-Audio-Sink
# Check if the sink was created:
pacmd list-sinks | grep name:
        name: <alsa_output.pci-0000_15_00.6.analog-stereo>
        name: <alsa_output.usb-Kingston_HyperX_Quadcast_4110-00.analog-stereo>
        name: <alsa_output.pci-0000_01_00.1.hdmi-stereo>
        name: <game_audio_sink>

Loop back virtual audio sink to another audio sink

With the following command the virtual sink with the name game_audio_sink is looped back to the audio sink alsa_output.pci-0000_15_00.6.analog-stereo:

load-module module-loopback source="game_audio_sink.monitor" sink="alsa_output.pci-0000_15_00.6.analog-stereo"

Twitch Setup

Create virtual loopback audio sinks (Pipewire)

Determine first what audio sink is your headphone jack/audio output you want to forward the audio streams to. In this case it's alsa_output.pci-0000_15_00.6.analog-stereo. Now we create 2 virtual audio sinks for the game audio (game_audio_sink) and for the music audio (music_audio_sink) that will be looped back to this audio sink:

# Terminal 1
pw-loopback -m '[ FL FR ]' --capture-props='media.class=Audio/Sink node.name=game_audio_sink node.description=Game-Audio-Sink' --playback-props='target.object="alsa_output.pci-0000_15_00.6.analog-stereo"'
# Terminal 2
pw-loopback -m '[ FL FR ]' --capture-props='media.class=Audio/Sink node.name=music_audio_sink node.description=Music-Audio-Sink' --playback-props='target.object="alsa_output.pci-0000_15_00.6.analog-stereo"'

Create virtual loopback audio sinks (Pulesaudio)

Determine first what audio sink is your headphone jack/audio output you want to forward the audio streams to. In this case it's alsa_output.pci-0000_15_00.6.analog-stereo. Now we create 2 virtual audio sinks for the game audio (game_audio_sink) and for the music audio (music_audio_sink) that will be looped back to this audio sink:

# Create virtual audio sinks
load-module module-null-sink sink_name=game_audio_sink sink_properties=device.description=Game-Audio-Sink
load-module module-null-sink sink_name=music_audio_sink sink_properties=device.description=Music-Audio-Sink
# Loopback virtual audio sinks to a real audio sink
load-module module-loopback source="game_audio_sink.monitor" sink="alsa_output.pci-0000_15_00.6.analog-stereo"
load-module module-loopback source="music_audio_sink.monitor" sink="alsa_output.pci-0000_15_00.6.analog-stereo"

Setup OBS

Go to settings, Audio and select the both sinks as Desktop Audio 1 and Desktop Audio 2. If your Music-Audio-Sink is Desktop Audio 2 you open the Advanced Audio Properties of the Audio Mixer dock/widget and uncheck Track 2 of the Desktop Audio 2 entry in the list.

To make OBS use these settings while Streaming you go again to the settings but this time to the section Output and check Enable Custom Encoder Settings (Advanced) and then check Twitch VOD Track (Uses Track 2).

Change audio source to virtual sink

If you can't change the audio output/sink with the default audio application you can install pavucontrol where you can change the sink of any audio output in the section Playback.

Sources

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