Technology
 

Icecast2

From Music Player Daemon Community Wiki

There is already sufficient documentation on how to setup MPD to stream to icecast. This document only explains on how to maintain a persistent stream even if Music Player Daemon stops or pauses playback. At least on Debian Lenny (mpd 0.13.2, icecast2 2.3.2) icecast will disconnect listeners once this happens. The solution is to setup a fallback stream using a silent OGG Vorbis audio file on your icecast2 server. Before you attempt the below, please follow the Documentation on how to setup MPD for icecast streaming.


Contents

[edit] Configuring MPD

I took this directly from the MPD configuration documentation. If you followed the steps there, your mpd.conf should include the following:


################# SHOUT STREAMING ########################
#
# Set this to allow mpd to stream its output to icecast2
# (i.e. mpd is a icecast2 source)
#
audio_output {
        type              "shout"
        name              "my cool stream"
        host              "localhost"
        port              "8000"
        mount             "/mpd.ogg"
        password          "IceCast_mpd"
        quality           "5.0"   
        format            "44100:16:1"
        user            "source"
} # end of audio_output
##########################################################


[edit] Configuring Icecast2

The main configuration file for icecast2 is /etc/icecast2/icecast.xml. In the default configuration file you will first need to change at least the username and password for the source client:


<authentication>
        <!-- Sources log in with username 'source' -->
        <source-password>IceCast_mpd</source-password>
        <relay-password>someRelayPassword</relay>
        <admin-user>admin</admin-user>
        <admin-password>someAdminPassword</admin-password>
</authentication>


I found the other default settings to work fine for me. However, we need to setup a mount section to setup the fallback stream. Find the following lines:


<!-- Only define a <mount> section if you want to use advanced options,
         like alternative usernames or passwords


And insert the mount-section before this line (since that line starts a comment, if you know your way around with XML, you can of course change the comment or uncomment the section that follows and adapt it. This is what you will need at the least:


<mount>
        <mount-name>/mpd.ogg</mount-name>
        <fallback-mount>/silence-fallback.ogg</fallback-mount>
        <fallback-override>1</fallback-override>
</mount>

The mount-name is the same as you specified in your mpd.conf. The fallback-mount is actually an ogg-file that we are going to place in icecast's web-root in a minute. The fallback-override option specifies that icecast will take you back to MPD once it resumes streaming.


The fallback-mount refers to a file silence-fallback.ogg. In theory this could be any silent ogg stream but in practice a number of problems can arise if this file is too short or encoded with a very low bitrate.


[edit] Creating a silent stream

I used audacity to do this. There might be easier ways. If you use audacity you just want to create a new project and press the record button (If you have a microphone or line-in, you want to mute those first). I recommend waiting for about 30 seconds since shorter files apparently cause problems. Hit File->Export and save the file as WAV.


It's tempting to export the file directly to OGG but that can cause problems. It seems like the export dialog only allows you to specify a Quality setting for OGG. However, even with a high quality, silence can be compressed very well in OGG. Thus, if your listener uses a large buffer (I use mplayer with 1024kbit), the silence stream is cached again and again leading to an extreme lag once MPD resumes streaming. The solution is to encode the file with a minumum or average bitrate.
The silent WAV can now be converted to a 384 kbps OGG file:


oggenc -b 384 -o silence-fallback.ogg silence-fallback.wav


[edit] Final Steps

The resulting silence-fallback.ogg should now be placed in icecast's webroot, which on Debian systems is located in /usr/share/icecast2/web/.


Restart your icecast2 and mpd services and you should be all set.

Rate this article: