Posts Tagged ‘streaming’

pulseaudio – quick’n’dirty playback over the network

May 9th, 2010 2 comments

The joyful lives of many Linux desktop users are clouded by many packages and frameworks that are well-intentioned and try to solve real and painful problems, but which are immature, not designed in the UNIX spirit, poorly documented and most importantly, do not really have a working implementation. Oh well. I have taken the stance of patience and ascetic acceptance of the new burdens – instead of trying to purge my systems of all that is unholy and evil, I spend that time trying to debug and fix up the problems they incur (often in vain). Sometimes I even file bugs, but that can be rather… unrewarding experience – more about that at another time.

So, I have two OpenSUSE 11.2 machines – a notebook with GNOME and a workstation with KDE 4.2 and some real speakers. My notebook uses PulseAudio semi-automagically, but after many perpetual problems with pulseaudio, phonon, java and flash, I really gave up on the workstation and turned pulseaudio off. However, it is desirable to coil up in the bed and watch a movie on the notebook while NOT listening to the notebook speakers. So I want to play sound over the network, notebook to workstation.

What to do on the notebook:

$ echo default-server = $IP_of_workstation >>/etc/pulse/client.conf
$ mplayer -ao pulse ...

That was easy. Your girlfriend watches you type along over your head.

What to do on the workstation? Surely that will also be piece of cake!

$ echo load-module module-native-protocol-tcp auth-anonymous=1 >>/etc/pulse/
$ pulseaudio -v

Ok. Try to fire up mplayer and… it’s all silent! You stare at the log for a bit, then you see it:

I: sink-input.c: Created input 0 "audio stream" on alsa_output.pci-0000_01_00.1.hdmi-stereo with sample spec s16le 2ch 44100Hz and channel map front-left,front-right

But, that’s wrong! There is nothing hooked up on the HDMI! The speakers are analog. Why is it playing over the HDMI? You click around a bit, google around a bit, nothing comes up. Your girlfriend stirs impatiently.

You go through the log, see that pulseaudio first sees the HDMI sink, then the analog sink. Hm. You find the set-default-sink command somewhere and do

$ echo set-default-sink alsa_output.pci-0000_00_1b.0.analog-stereo >>/etc/pulse/

Pulseaudio restart. Nice red message:

E: main.c: Sink alsa_output.pci-0000_00_1b.0.analog-stereo does not exist

Aha! Pulseaudio sees HDMI right away, sets it up, _then_ finishes initializing and prints this error, and only about two seconds later it goes all “oh, look, there’s another card plugged in here!”. What the heck?

At this point, you either give up or try to google around again madly. After 10 minutes, while your girlfriend is browsing DeviantArt bored, sound finally comes from the speakers after you figure out to issue

pacmd  'set-default-sink alsa_output.pci-0000_00_1b.0.analog-stereo'

while having a running pulseaudio.

You will probably need to have a dbus connection to your pulseaudio if you want to do this. If you are setting up the workstation remotely, you need to either create your own dbus session or hook up to a running one if you are logged in physically as well. This is a very simple, user friendly step:

$ ps axu
chidori   3036  0.0  0.4 151192 16564 ?        S    09:40   0:00 kdeinit4: kded4 [kdeinit]
$ cat /proc/3036/environ | tr '\0' '\n' | grep DBUS
$ export `cat /proc/3036/environ | tr '\0' '\n' | grep DBUS`

Yay, what a nice, user-friendly, easy to set up piece of software we have here.

(BTW, the movie stutters every two minutes or so anyway; another time I feel shiny and optimistic, I will try to figure out if using some compression for the network audio is possible nowadays.)

VLC mpjpeg streaming

July 12th, 2009 4 comments

Last weekend, we were streaming four webcams from internal LAN behind firewall to the internet; the webcams were giving the stream as multipart jpeg and we wanted the stream at the internet to be multipart jpeg as well – it is not very effective, but the webcams aren’t high FPS and you can easily watch the stream in any browser.

You need a Linux system A in the LAN network, and publicly accessible Linux server B on a thick line at the internet (Windows should work too, but I didn’t test it). You need VLC 0.9.x (important! 0.8.x has mpjpeg streaming broken) installed on both.

On the A system, for each camera run:

while true; do \
  vlc -I dummy -vvv \
  '' \
  --sout '#es{access-video=udp,mux-video=ts,dst-video=}'; \
  sleep 1; done

(adjust URL for camera stream, IP address for B Linux server; hostnames mysteriously don’t work sometime!).

On server B, for each camera run:

while true; do \
  vlc -vvv udp://@ --sout \
  '#standard{access=http{mime=multipart/x-mixed-replace; boundary=--7b3cc56e5f51db803f790dad720ed50a},mux=mpjpeg,dst=}' \
  sleep 1; done

Then, connect with your browser to If the stream gets stuck, hit reload. For multiple cameras, just use port numbers 9992 and 8882 etc.

It’s a shame that you have to manually specify this magic to have browsers understand VLC-generated mpjpeg stream… I hope someone fixes this in future releases; in theory looking at the code it should work, but somehow something overrides the MIME type to application/octet-stream.

No re-encoding is done, you get the original quality as with the original stream. Unfortunately, the scheme doesn’t deal well with too thin uplink, if you fill your bandwidth from A to B, you don’t get dropped frames but completely corrupted stream. :-(

Categories: linux, software Tags: , ,