Capturing game audio into a file
Shmerl Apr 21, 2022
I was playing Black Geyser: Couriers of Darkness and there is a nice music theme in the game that I wanted to find, but OST isn't available yet, so I thought may be to simply record audio output in a file. It ended up being not very hard using PulseAudio tools (also should be doable using Pipewire tools, but I didn't get to trying that yet).

You can see your Pulse sinks like this:

pactl list short sinks

49      alsa_output.pci-0000_0f_00.1.hdmi-stereo-extra4 PipeWire        s32le 2ch 48000Hz       SUSPENDED
50      alsa_output.pci-0000_11_00.4.iec958-stereo      PipeWire        s32le 2ch 48000Hz       RUNNING


Firstly, I'm using my digital output for audio already.

In my case it's alsa_output.pci-0000_11_00.4.iec958-stereo (S/PDIF output). s32le means audio format is signed 32-bit little endian. 2ch means it has two channels and 48000 Hz is the sample rate.

Now you can simply capture it using parec like this (note .monitor suffix for it):

parec --device='alsa_output.pci-0000_11_00.4.iec958-stereo.monitor' \
 --rate=48000 \
 --file-format=flac > theme.flac


By default parec records in 44100 Hz, 16 bit depth and native endianness. I suppose to avoid resampling, you can match sample rate to the native sink one (48000 Hz in my case). FLAC only supports 16 and 20 bit depth, and parec's default 16 is perfectly enough, so no need to change that.

That's all :)

Once I recorded the theme I had to trim it a bit in Audacity to make it loopable.

Last edited by Shmerl on 21 April 2022 at 5:52 pm UTC
Shmerl Apr 24, 2022
Figured out how to do it with Pipewire tools too for fun.

Get the list of targets first:

pw-record --list-targets

Available targets ("*" denotes default): alsa_input.usb-046d_C922_Pro_Stream_Webcam_D7C1577F-02.analog-stereo
*       47: source description="C922 Pro Stream Webcam Analog Stereo" prio=2009
        34: monitor description="Starship/Matisse HD Audio Controller Digital Stereo (IEC958)" prio=736
        48: monitor description="Navi 21 HDMI Audio [Radeon RX 6800/6800 XT / 6900 XT] Digital Stereo (HDMI 5)" prio=584
        81: stream description="mpv" prio=-1


You can also get some more info with:

pw-cli list-objects Node

Get currently used format of the sink, which in my case is 34 for digitial S/PDIF output. You can get a better idea which is which from pw-cli list-objects Node.

pw-cli enum-params 34 Format

  Object: size 160, type Spa:Pod:Object:Param:Format (262147), id Spa:Enum:ParamId:Format (4)
    Prop: key Spa:Pod:Object:Param:Format:mediaType (1), flags 00000000
      Id 1        (Spa:Enum:MediaType:audio)
    Prop: key Spa:Pod:Object:Param:Format:mediaSubtype (2), flags 00000000
      Id 1        (Spa:Enum:MediaSubtype:raw)
    Prop: key Spa:Pod:Object:Param:Format:Audio:format (65537), flags 00000000
      Id 267      (Spa:Enum:AudioFormat:S32LE)
    Prop: key Spa:Pod:Object:Param:Format:Audio:rate (65539), flags 00000000
      Int 48000
    Prop: key Spa:Pod:Object:Param:Format:Audio:channels (65540), flags 00000000
      Int 2
    Prop: key Spa:Pod:Object:Param:Format:Audio:position (65541), flags 00000000
      Array: child.size 4, child.type Spa:Id
        Id 3        (Spa:Enum:AudioChannel:FL)
        Id 4        (Spa:Enum:AudioChannel:FR)


Note S32LE, 48000 and 2 channels. Same info we got from pactl before.

Just for the reference, to list all supported formats of the sink, you can use:

pw-cli enum-params 34 EnumFormat

Then you can actually record:

pw-record --target 34 --rate=48000 --format=s16 --channels=2 audio.wav

This can be simplified, since 48000 Hz, s16 and 2 channels are defaults:

pw-record --target 34 audio.wav

Currently it only supports recording a WAV file.

Last edited by Shmerl on 24 April 2022 at 8:28 am UTC
While you're here, please consider supporting GamingOnLinux on:

Reward Tiers: Patreon. Plain Donations: PayPal.

This ensures all of our main content remains totally free for everyone! Patreon supporters can also remove all adverts and sponsors! Supporting us helps bring good, fresh content. Without your continued support, we simply could not continue!

You can find even more ways to support us on this dedicated page any time. If you already are, thank you!
Login / Register


Or login with...
Sign in with Steam Sign in with Google
Social logins require cookies to stay logged in.

Buy Games
Buy games with our affiliate / partner links: