Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 31 down vote accepted

Try something like this:

In a terminal enter


(this is the CLI of the PulseAudio-Server) then use


(where you get the indices of the running inputs) Now find the index of your input. Now referred to as $INDEX

the scriptable part is:

pactl load-module module-null-sink sink_name=steam
pactl move-sink-input $INDEX steam
parec -d steam.monitor | oggenc -b 192 -o steam.ogg --raw -


  • The first command will add a null-sink as you already knew.
  • The second command moves the sink-input from your standard-audio-sink to steam
  • The third command records the monitor of the device steam (-d) and puts the output (raw-wave-stream) into oggenc, which encodes this wave-stream to an oga-file. (for mp3 use lame)

Greez Waschtl

share|improve this answer
Brilliant, thank you so much for this great answer! :) – Force Nov 24 '11 at 11:32
can you please explain how to undo this operation? my null sinks are still mapped to various applications, and now i have no sound! – ixtmixilix Aug 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. – Takkat Mar 2 '13 at 19:48
@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 – Ciaran Feb 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.

share|improve this answer
If you can, upload a screen-shot in Imgur and link it into your answer. – Lucio Mar 2 '13 at 19:11
Grabbed one, thanks for the suggestion. – Jack O'Connor Mar 4 '13 at 20:05

Improving Waschtl answer of this thread so you can BOTH LISTEN AND RECORD the app sound:

First, we look for our default output and put its sink name in $DEFAULT_OUTPUT:

$ pacmd list-sinks | grep -A1 "* index"
  * index: 1
    name: <alsa_output.pci-0000_00_1b.0.analog-stereo>
$ DEFAULT_OUTPUT=$(pacmd list-sinks | grep -A1 "* index" | grep -oP "<\K[^ >]+")

Then, we create a combined sink that has only one slave: $DEFAULT_OUTPUT. The sound generated by the app (source) will be forwarded to the slave sink (ie. real output), and we'll also record it. It is different than a null sink where the source sound is not forwarded.

$ pactl load-module module-combine-sink \
  sink_name=record-n-play slaves=$DEFAULT_OUTPUT \

sink_properties is optional and may bug if you use spaces in the description name.

Then, we could use pactl move-sink-input ... command of Waschtl answer (with record-n-play instead of steam) but GUI pavucontrol is more simple (and great for checking/troubleshooting):

$ sudo apt-get install pavucontrol
$ pavucontrol &

Then, we play some sound in the app we want to record. In pavucontrol Playback tab, we select in the app dropdown list: "Record-and-Play".

Finally, we're good to record and listen at the same time! (lame mp3 example, run in foreground)

$ parec --format=s16le -d record-n-play.monitor | \
  lame -r --quiet -q 3 --lowpass 17 --abr 192 - "temp.mp3"

Or we can record in background and stop at any time:

$ parec --format=s16le -d record-n-play.monitor | \
  lame -r --quiet -q 3 --lowpass 17 --abr 192 - "temp.mp3" \
   > /dev/null &1>/dev/null
$ killall -q parec lame


  • To unmess everything or retry the procedure: Delete or reset the sinks by using this answer. pulseaudio -k works great to reset everything to session's defaults.
  • If we change the default output in the System Sound Settings, the custom app Playback setting will be overwritten and we will have to go back in pavucontrol to set it back to the combined interface.
  • To be able to listen to the sound from several "real" interfaces (eg headphones, HDMI output, etc...), we should include all "real" outputs that we may use to listen, as record-n-play slink slaves, like: pactl load-module module-combine-sink sink_name=record-n-play slaves=real-output-1,real-output-2.
share|improve this answer

Improving KrisWebDev's answer further, if you want record-n-play to always be available, first find out the default output:

pacmd list-sinks | grep -A1 "* index" | grep -oP "<\K[^ >]+"

which will output something like:


Next, create a file ~/.config/pulse/

.include /etc/pulse/

load-module module-combine-sink sink_name=record-n-play slaves=alsa_output.pci-0000_00_1b.0.analog-stereo sink_properties=device.description="Record-and-Play"

Please replace alsa_output.pci-0000_00_1b.0.analog-stereo with whatever output you got from the pacmd command. Pulse does not read the default config file when a custom config file exists - that's why the first line above includes the default config file. That way pulseaudio still loads the default config first.

Run pulseaudio -k to kill the current pulseaudio instance so a new one is started with the new configuration.

If at any time you want to undo the changes here, just remove the ~/.config/pulse/ file and run pulseaudio -k.

If you want the record-n-play to be the default sink for all outputs, you can do that by adding yet another line to the end of ~/.config/pulse/

set-default-sink record-n-play

For programs that pulseaudio already has stored information on, it remembers whatever output device they used last, so you'll have to manually reconfigure those using one of the methods described in KrisWebDev's answer.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.