Your own internet radio station with MPD/Icecast

This is a short, un-detailed howto of how to create your own internet station using the MPD music player daemon and icecast. There are some drawbacks with this solution, but since I have been an avid MPD user for a long time, this solution integrates nicely with what I am used to. Read on for complete instructions
Advantages:

  • Integrates directly with MPD
  • Quite customizable and very nice to control via an SSH shell.

Drawbacks:

  • Ogg Vorbis is the only audio format supported as of now
  • There is a bug when resuming playback that has been paused for a long time

Prerequisites

  • Your favorite Linux distribution. On this current server I have gentoo, while my favorite is Ubuntu. Your choice!
  • A good internet connection. Streaming music over a slow internet connection will probably halt your other traffic.

Software used:

  • mpd, at least version 0.12.0
  • icecast, I use version 2.3.1
  • your favorite MPD client, I favour “ncmpc”
  • a listener client, on Windows I use foobar2000 (you need ogg support for your player)

Let’s get started. Install all the above software on your computers, see the howto on the wiki for this.

Configure icecast. This can be a bit tricky and ther are many ways to fail in this step. You should:

  • Set hostname (mine is stream.broach.se)
  • Set the source password (the password that mpd will have to specify to be able to stream to the icecast server)
  • Set the admin password.

Icecast can be a bit tricky to configure, especially since it uses an XML file. The configuration is probably located at /etc/icecast/icecast.xml.
You also need to choose whether to use burst-on-connect. I have turned burst-on-connect on to reduce latency between MPD and the listener client, and I have no problems with lag. Remember that I mostly sit on high-speed internet connections and therefore your situation and configuration might vary.

Now configure mpd. See the howto on the wiki again. I use quality 4.00, which gives a bitrate of a bit lower than 128, which is OK for web-radio. If you are an audiophile you should use 5.00 or more. Also set the correct password needed to connect to the icecast server. This is the source password you have typed in the icecast xml file. If everything seems OK, fire up icecast and then MPD.

My mpd.conf:

music_directory "/var/music"
playlist_directory "/var/lib/mpd/playlists"
db_file "/var/lib/mpd/database"
log_file "/var/log/mpd.log"
error_file "/var/log/mpd.error.log"
pid_file "/var/run/mpd/mpd.pid"

audio_output {
type            "shout"
name            "Music stream"
host            "localhost"
port            "8000"
mount           "/stream.ogg"
password        "password"
quality         "2"

user            "source"
description     "All kinds of music"
genre           "Everything"
} # end of audio_output

Replace “user” and “password” with the information you specified in your icecast configuration.
Start icecast, then mpd, and then your mpd client to play some music. Now mpd streams music encoded as an Ogg Vorbis stream to icecast, which is now waiting for listeners. Goto another computer and start to listen to “http://your-server-adress:8000/stream.ogg.m3u”, which will be the name of the audio stream.

Everything should work now. If it doesn’t, you probably have a configuration issue. If the playback is skippy and it seems that MPD plays the file at wrong speed (ie. the timer seems to go very fast and jump a few seconds now and then), you have encountered the skipper bug. Restart MPD and resume playback. I don’t have another solution to this bug yet, but luckily it only occurs when you haven’t played any music for a few minutes. Prevent it to happen by always have a song in your MPD playlist. This bug was solved by upgrading libshout from 2.0 to 2.1. Thanks to the guys in the #mpd IRC channel for this!

Wishlist:

  1. A configuration option for MPD that sends a silent audio stream when the music is offline or paused. This prevents the skipper bug, and allows all clients to be connected even though you pause the music. You won’t have to reconnect again when starting to play, because there always has been a connection
  2. Reverse proxy support for icecast. I have the icecast server located behind my router, and the generated URL is invalid because port 80 on the webserver is routed to the icecast server for the domain “stream.broach.se”, but not “etnoy.broach.se” and “www.broach.se”. Therefore I need to manually change the source code to make this work. I resolved this problem by manually adding a stream.ogg.m3u file to the web directory containing the correct URL for the strem. Hackish, but it works well.

Report any problems by commenting on this blog entry, or ask me a question by e-mail.

Updated 06/07 2006
Updated 11/01 2006
Updated 11/03 2006
Updated 07/01 2007

15 Comments

  1. Posted Friday, July 14, 2006 at 12:10 | Permalink

    Read my question about the playback speed bug here

  2. Posted Friday, October 27, 2006 at 17:26 | Permalink

    Hi!

    I’ve follow your guide and I’d be pleased if you could send me your icecast.xml and mpd.conf files, as I’m not able to connect mpd with icecast.

    Thank you!

  3. Posted Saturday, November 4, 2006 at 00:21 | Permalink

    chunow,
    I have posted my mpd.conf now, but I am still figuring out how to post the icecast.xml file. Can you describe the problem more in detail?
    Jonathan

  4. Ben West
    Posted Thursday, November 16, 2006 at 03:24 | Permalink

    the mountpoint is not created on the icecast2 server.
    winamp (v5.x) doesn’t connect.
    using icecast 2.3.1
    using mpd 12.0
    debian

    playing, but unalble to connect, no mountpoints show up in administration interface for icecast

  5. Ben West
    Posted Thursday, November 16, 2006 at 03:48 | Permalink

    I had specified ‘hostname’ as the name of the shoutcast server to connect to…

  6. Posted Sunday, November 26, 2006 at 19:15 | Permalink

    Try starting mpd with –no-daemon –verbose and start playback from your mpd client. You should see some information to why mpd is unable to connect to icecast. Also try starting icecast with debugging (however, I don’t have the command line options for icecast in my head right now, check out “man icecast”)

    Good luck!
    Jonathan

    PS.
    Please forgive me that I am slow on responding to your comments, I am on a ship and quite far away from internet connections.

  7. Ricardo Lanziano
    Posted Tuesday, November 28, 2006 at 22:34 | Permalink

    Nope, no luck for me either, the mountpoint doesnt seem to be created, cannot connect to the shout/ice cast servers for streaming.

  8. Ricardo Lanziano
    Posted Tuesday, November 28, 2006 at 23:04 | Permalink

    nevermind, user hast to be source in mpd in order to icecast :)

  9. Posted Friday, December 1, 2006 at 18:25 | Permalink

    Ricardo:
    The user mpd uses to connect with is specified in icecast.xml as the source-user directive

  10. ouaibsky [websky]
    Posted Saturday, December 16, 2006 at 15:56 | Permalink

    Very interesting.
    It works fine at home.
    Sometime, the connection between mpd and icecast is broken, i don’t know why. not really a pb but client need to rstart the stream reading.
    About your whish (send silent when no files are playing), it’s also my whish. Do you no if this feature is planned for a next version of mpd ?

    Thx
    Christophe

  11. Posted Monday, December 18, 2006 at 14:33 | Permalink

    Christophe,
    I spoke to the guys at #mpd, and they took up the idea. However, after some research they seemed to conclude that there was a lot of work needed. It would not be impossible for them to make this feature come true, file a bug or ask them to implement it!

    About the occasional resets, try upgrading libshout as stated in the post. You might have encountered the “skipper bug”.

    Jonathan

  12. Posted Tuesday, August 21, 2007 at 18:55 | Permalink

    Hi, thanks for the howto, and I think it’s working, but I’m not sure it is properly.
    When I play music on the host machine, I can hear no sound, however I can hear it remotely. I think this is due to the audio output being redirected to icecast, but what if I wanted to listen to my music on the actual host machine? would I need to use another player (one that plays m3u files) rather than a MPD client?

    Thanks :)

  13. Posted Tuesday, August 21, 2007 at 19:19 | Permalink

    Ok, I reply to myself. I just added another audio_output, and pointed it to my alsa device, so now I can play music with my MPD client as well :)

  14. Posted Thursday, April 10, 2008 at 00:16 | Permalink

    Whenever i try to save the config file after editing, it says:
    “Cannot create the icecast.XML file”
    Please HELP!

  15. james
    Posted Monday, March 22, 2010 at 21:26 | Permalink

    About the wishlist item regarding a silent fallback stream: see this entry in the mpd wikia about how to configure that.
    http://mpd.wikia.com/wiki/Icecast2

    I know this blog post is a few years old but it’s still referenced on some mpd/icecast tutorials, so I figured I would post a comment.

One Trackback

  1. By Wenn die WG ein Radio hat | goblor grübelt on Wednesday, September 17, 2008 at 09:54

    [...] Es gibt viele Stellen im Netz, wo Installation und Benutzung ganz gut erklärt werden. Z.B. hier, hier oder [...]

Post a Comment

Your email is never shared. Required fields are marked *

*
*