Stream any pulseaudio application

Steaming any application we like to a media server like icecast2 or shoutcast was made easy with pulseaudio.  You wont need any special plugins for every application. Pulseaudio has all the needed tools to make it work 🙂

Note: The procedure below wont work with Ubuntu Lucid 10.04 because of a known bug. Ubuntu 9.10 and 10.10 will do just fine, or any other bleeding edge pulseaudio setup. For our tests we will be using Icecast2 server.

If you dont have gst-launch-0.10 and pavucontrol installed, then

$ sudo apt-get install gstreamer0.10-tools pavucontrol

Part 1:
In this part we will just stream the monitor of our audio device (Anything we hear). Many of you might just prefer this. Its easy and fast. Just run the following command:

$ gst-launch-0.10 pulsesrc device=device ! \
audioconvert ! \
audio/x-raw-int,rate=44100,channels=2 ! \
lamemp3enc bitrate=128 ! \
shout2send \
ip=host \
port=port \
password=pass \
mount=mount

Where device is the output of the following command:

$ echo $(cat ~/.pulse/*-sink).monitor

Part 2:
In this part we will use the previous command and take it to the next level by choosing the application we want to stream and not just the monitor. Firstly you should load all  the needed pulseaudio modules.

$ pactl load-module module-null-sink
$ pactl load-module module-combine \
sink_name=STREAM_ME \
slaves=”`cat ~/.pulse/*-sink`,null”

Now use the following streaming command:

$ gst-launch-0.10 pulsesrc device=null.monitor ! \
audioconvert ! \
audio/x-raw-int,rate=44100,channels=2 ! \
lamemp3enc bitrate=128 ! \
shout2send \
ip=host \
port=port \
password=pass \
mount=mount

The only difference with the command from part 1 is that we changed the device to null.monitor
Now we are ready to stream our favorite application 🙂

Run pavucontrol and move the application you want from your sound card to our newly created virtual device “STREAM_ME”. Voila!

To undo everything, stop the streaming command with control+c and

$ killall pulseaudio

to fast unload the 2 modules we loaded.

Share on FacebookTweet about this on TwitterShare on Google+Share on StumbleUponShare on RedditShare on TumblrShare on LinkedInEmail this to someone