Skip to content

Streaming MPD to Icecast as mp3—and more!

2011 February 11
by Tedb0t

Since it’s non-obvious, here’s what I had to do to stream MPD to Icecast using mp3. I had been using ogg and it worked, but the latency was over 10 seconds!! That means every time I changed a song or changed the volume it took 10 seconds to be reflected in the actual audible playback!! Using mp3 now seems to cut that at least in half. Still kind of annoying but MUCH better.  I’m not using the built-in httpd stream because then you can’t use the silent fallback stream; if you don’t need that though, the httpd output works great.

Read on!

in /etc/mpd.conf:

audio_output {
        type            "shout"
        name            "My MPD Stream"
        host            "localhost"
        port            "8000"
        encoding        "mp3"
        encoder         "lame"
        mount           "/mpd.mp3"
        quality         "5.0"
        format          "44100:16:1"
        user            "source"
        password        "source-password"

Note that both “encoder” and “encoding” must be specified (sigh, that took a good 15 minutes to figure out). “user” and “password” are the “source” credentials for your Icecast server, specified in /etc/icecast2/icecast.xml.

Now, if this doesn’t work, it may be because your build of mpd doesn’t have the lame encoder enabled (goddamn licensing issues…). However, as of just recently, this has been built-in to the “Maverick proposed” Ubuntu repository:

To upgrade mpd, I followed these instructions and everything works fine now!

Now then. Under normal circumstances, if the stream is interrupted (such as by pausing mpd), the stream closes. That means you’d have to open the stream again on your client whenever the music starts again—unacceptable!! What you need is Icecast’s fallback stream capability—this is why I’m not using mpd’s built-in httpd streamer. (Come to think of it, we need to just add this by default into mpd!)

To use the silent fallback stream, I followed these instructions:

Create the silent ogg file (in /usr/share/icecast2/web/):

dd if=/dev/zero bs=176400 count=5 | oggenc - -r -o silence.ogg

(Piping zeros directly into the ogg encoder!! See, this is why bash/linux is so freaking awesome!)

Add this to /etc/icecast2/icecast.xml:


Restart MPD and Icecast:

sudo service mpd restart
sudo service icecast2 restart

…and you should be good to go!!

Related Posts:

Comments are closed.