Easy streaming all Ubuntu audio from VLC to Airport Express

*nix specific usage questions
NYZack
New Cone
New Cone
Posts: 1
Joined: 12 Jan 2012 18:35

Easy streaming all Ubuntu audio from VLC to Airport Express

Postby NYZack » 12 Jan 2012 19:21

My goal was to stream *all* of my Ubuntu computer's (11.10, 64-bit Oneiric) audio output (using Pulseaudio) to my Airport Express (to use Banshee, for instance, or Pandora, or Google Music). For many reasons, I found that using Pulseaudio's native raop streaming capabilities were lacking. Apart from having grief just trying to make them work, I found that the audio was of extremely poor quality (cutting in and out every second or so), and Pulseaudio never seemed to release control of the Airport Express so that other sources (iTunes on another PC, for instance) could stream to it.

I've spent a lot of time reading posts about how to stream to an Airport Express using VLC; this is fairly straightforward if you want to stream an audio file that VLC is itself playing, but it's a little less straightforward if you want to stream the computer's own audio. However, it turns out to be fairly easy, with the only catch being that you need to install a later version of VLC (at least 1.2, I believe) than normally installs on Ubuntu 11.10. I used a nightly (you can get it here: http://nightlies.videolan.org/). This is because the ability to stream directly from Pulseaudio (using pulse://) is new to VLC. Then you have to find the monitor of your currently active sound sink (you may have to activate the monitor under "Input Devices -> Monitors" using "pavucontrol"). I found the name of the monitor by running "pacmd list-sources" in a terminal and using the "name" of the appropriate monitor. In my case, this was "alsa_output.pci-0000_00_1b.0.analog-stereo.monitor". If I then type this into a terminal:

Code: Select all

vlc pulse://alsa_output.pci-0000_00_1b.0.analog-stereo.monitor :sout='#transcode{acodec=alac,channels=2,samplerate=44100}:raop{host=<ip address of Airport Express>,volume=175}'
all of my computer's audio gets streamed to the Airport Express (obviously, you have to replace "<ip address of Airport Express>" with the ip address of your Airport Express).

There is a significant delay between the computer audio and the Airport Express, so you have to turn your computer speakers' volume down if you can hear the AE output from where the computer is, or you'll find the result pretty annoying.

To manage this delay issue (if it bothers you), I wrote a simple script (below) to divert all of my computer's audio to the null sink and then stream its monitor via VLC to the AE and simultaneously to my analog sink with an appropriate delay. This way, all of the audio comes via VLC, which can adjust for the delay so that the AE and my computer's sound are in sync (and both somewhat delayed from when the computer actually generated them). I had to add "load-module module-null-sink" to the end of /etc/pulse/default.pa to make this work, then killall pulseaudio (or restart the computer). Make sure to substitute the ip address of your Airport Express in the vlc line below:

Code: Select all

#default.pa loaded the null sink as sink 1; the analog (default) sink is sink 0. Set null as the default, so that all new audio gets routed to it. pacmd set-default-sink 1 #Set SPS to a list of all of of the currently playing audio inputs (e.g., browser, Banshee) SPS=$(pacmd list-sink-inputs | grep index | sed -e s/index://) #Move each input to the null sink. for d in $SPS; do pacmd move-sink-input $d 1 done #Sleep a little to let this all take effect sleep 3 #Start VLC monitoring the null sink, streaming to the AE, and playing via the analog sink with a 4.2-second delay. vlc --qt-start-minimized --aout alsa --alsa-audio-device front pulse://null.monitor :sout='#duplicate{dst="transcode{acodec=alac,channels=2,samplerate=44100}:raop{host=<ip address of Airport Express>,volume=175}",dst=display{delay=4200}}' #Once VLC is closed by the user (doesn't want to stream to AE anymore), set default sink back to 0 (analog, in my case) pacmd set-default-sink 0 #Assign the current sink inputs to SPS again SPS=$(pacmd list-sink-inputs | grep index | sed -e s/index://) #Move the sink inputs back to the analog sink for d in $SPS; do pacmd move-sink-input $d 0 done
Last edited by NYZack on 13 Jan 2012 18:31, edited 3 times in total.

Rémi Denis-Courmont
Developer
Developer
Posts: 15265
Joined: 07 Jun 2004 16:01
VLC version: master
Operating System: Linux
Contact:

Re: Easy streaming all Ubuntu audio from VLC to Airport Expr

Postby Rémi Denis-Courmont » 13 Jan 2012 08:09

You could probably reduce the latency using vlc --live-caching=X where is X is small. But there is intrinsically going to be more delay in the pipeline.

And
SPS=$(pacmd list-sink-inputs | grep index | sed -e s/index://)
could probably be simplified to
SPS=$(pacmd list-sink-inputs | sed -n -e s/index://p)
Rémi Denis-Courmont
https://www.remlab.net/
Private messages soliciting support will be systematically discarded

kseln
New Cone
New Cone
Posts: 1
Joined: 04 Aug 2012 18:25

Re: Easy streaming all Ubuntu audio from VLC to Airport Expr

Postby kseln » 04 Aug 2012 18:38

That helped me out a lot with my kitchen audio solution! However, I added some further simplicity and flexibility by making a dedicated pulseaudio sink. The result is that one can choose in pavucontrol what streams to send to the airport, so that not all audio has to go there.

All one has to do is run

Code: Select all

pactl load-module module-null-sink sink_name=airport sink_properties=device.description="Airport audio stream"
to add a null sink to pulseaudio. The key lines in the script (in my case they are the only lines) is then changed to

Code: Select all

#!/bin/bash -- cvlc pulse://airport.monitor :sout='#transcode{acodec=alac,channels=2,samplerate=44100}:raop{host=IP_OF_AIRPORT_HOST,volume=175}'
It is then most convenient to have the script running in a separate terminal window at all times, since it crashes from time to time.


Return to “VLC media player for Linux and friends Troubleshooting”

Who is online

Users browsing this forum: No registered users and 18 guests