I would like to record an output of a program with PulseAudio using command line/bash script. It is important not to record every output of the sound card, but only the one of one specific program.
I thought I would have to create a new null-sink and than move the programs output to this new sink. Than tell parec to use this specific monitor to record.
The first step would be something like this:

pactl load-module module-null-sink sink_name=steam

But how to move the programs output now to this sink?
And how to record the specific sink with a bash script?

Brilliant, thank you so much for this great answer! :)
–
ForceNov 24 '11 at 11:32

1

can you please explain how to undo this operation? my null sinks are still mapped to various applications, and now i have no sound!
–
ixtmixilixAug 20 '12 at 12:44

@ixtmixilix: the easiest way to restore all settings to default is to just kill and restart the pulseaudio server. If set to autospawn (this is the default) you simply issue pulseaudio -k in a terminal.
–
TakkatMar 2 '13 at 19:48

1

@ixtmixilix When you run list-sink-inputs take note of the sink value. To swap back just run pactl move-sink-input $INDEX $SINK. Something like pactl move-sink-input 4719 1
–
CiaranFeb 21 '14 at 10:28

@Waschtl's answer is fantastic. @ixtmixilix asked about restoring regular audio after the recording is finished. Here's the easiest way I know of:

Install and run the pavucontrol GUI. You should see your audio-outputting application and it's volume meter under the Playback tab in there. There will be a button next to it showing that it's playing on Null Output. Click on that and change it to your ordinary audio output, Built-in Audio Analog Stereo in my case.

Here's a screenshot of what you're looking for:

You can also use this approach to set up your recording in the future, after you've run the load-module command in @Waschtl's answer to create the sink.