My Own Streaming Radio, Thanks to Icecast

Icecast? Don’t worry, I am not going to talk about chiselling sculptures out of ice here. Icecast is a server—an audio streaming server to be precise. It can broadcast both MP3 and Ogg Vorbis format audio in the form of streams. What I wanted was to be able to access my music library on my iPod Touch while at home. So, I was looking for a way to stream my music over the home network. After a little search and review, MPD (Music Player Daemon) with the Icecast server seemed to be the best option.

With this set-up, you can run even your own Internet radio. You can select the bit rate of the stream, the number of channels to stream, and the quality of the Ogg streams…there are numerous options to choose from.

My own radio? Wow! Where do I begin?

It’s fairly simple actually. We will cover the basics about creating and using a basic MPD set-up, which can be used as a local streaming service on your machine. Personally, I find it better than most players out there. This will, in turn, help us with the streaming application in the backend. Then, we will explore setting up Icecast. Take a look at Figures 1 and 2 to get a more holistic view.

Figure 1: An overview of the streaming server

Figure 1: An overview of the streaming server

Figure 2: How the streaming server works

Figure 2: How the streaming server works

Music Player Daemon

MPD (Music Player Daemon) is a daemon (a piece of software that runs in the background) that manages your music for you. It’s a client-server architecture. MPD acts as a server; and when you install a client, you can use it to interact with MPD and play music. It’s great to set up some old computer as the MPD server and route that music throughout your network. The advantage lies in the fact that it will require less space for storage—everyone has their own account and they can listen to whatever music they want to as long as it is on the server (or optionally, on your local machine).

Unless you are using Linux from Scratch or Rock Linux, your distribution repositories have the binaries for MPD. Install MPD and copy the file /etc/mpd.conf.example to /etc/mpd.conf. Open it in any preferred text editor. And then configure MPD as follows.

Edit the file and add the following lines—this is the most basic and simple, single-user configuration for MPD that we will use with Icecast:

music_directory        "/home/user/music"# Your music dir.
playlist_directory     "/var/lib/mpd/playlists"
db_file                "/var/lib/mpd/db"
log_file               "/var/log/mpd/mpd.log"
error_file             "/var/log/mpd/mpd.error"
pid_file               "/var/run/mpd/mpd.pid"
state_file             "/var/lib/mpd/mpdstate"
user                   "mpd"
# Binding to address and port causing problems
# in mpd-0.14.2 best to leave commented.
# bind_to_address      "127.0.0.1"
# port                 "6600"

audio_output {
    type               "alsa"
    name                "My ALSA Device"
    device           "hw:0,0"           # optional
    format           "44100:16:2"      # optional
}

# We assume that you use ALSA in this config.
# If you are using any other driver, please visit the
# official docs at http://mpd.wikia.com/wiki/Configuration
# to know how to setup your driver.

Most of the fields in the configuration file above are self-explanatory. You only need to change the music directory to your music directory path. Keep the other paths and even the user as mpd. We will get back to that later. Save the file for now. Come back to the root console.

Let’s create a new user, mpd, which will be used to access MPD.

useradd -g mpd -d /var/lib/mpd

Then make sure that the directory is owned by the mpd user, as well as the mpd group, by issuing the following command:

chown mpd:mpd /var/lib/mpd -R

Moving along, we now have to create the files mentioned earlier, and then transfer ownership of some files and directories to mpd:mpd. Execute the following commands:

touch /var/lib/mpd/db
touch /var/lib/mpd/mpdstate
touch /var/run/mpd/mpd.pid
touch /var/log/mpd/mpd.log
touch /var/log/mpd/mpd.error
chown -R mpd:mpd /var/lib/mpd
chown -R mpd:mpd /var/run/mpd
chown -R mpd:mpd /var/log/mpd

Now almost everything is done. Create the MPD music database as the root user. Then set 755 permissions to your home music directory:

mpd --create-db
chmod a+x /home/user
chmod -R a+x /home/user/music

You are done. You can install some MPD client, say mpc, ncmpc or Sonata (my favourite) and check if MPD runs. Start MPD as follows:

/etc/rc.d/mpd start

If everything is working fine (which it should if you follow the instructions given), then we can move on to the next section.

About Aditya Shevade

National Talent Scholar, Aditya Shevade, a final year electronics engineering student, takes keen interest in programming and electronic design. A Linux user for past two years, he enjoys playing keyboard and is a good photographer.

Related Articles

2 Comments

  • andylock
    November 30, 2009 | Permalink |

    Web casting, or broadcasting over the internet, is a media file (audio-video mostly) distributed over the internet using streaming media technology. Streaming implies media played as a continuous stream and received real time by the browser (end user). Streaming technology enables a single content source to be distributed to many simultaneous viewers. Streaming video bandwidth is typically calculated in gigabytes of data transferred. It is important to estimate how many viewers you can reach, for example in a live webcast, given your bandwidth constraints or conversely, if you are expecting a certain audience size, what bandwidth resources you need to deploy.

    To estimate how many viewers you can reach during a webcast, consider some parlance:
    One viewer: 1 click of a video player button at one location logged on
    One viewer hour: 1 viewer connected for 1 hour
    100 viewer hours: 100 viewers connected for 1 hour…

  • prasadkolekar
    December 11, 2009 | Permalink |

    nice article thanks for such great info….

Leave a comment

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Your email is never shared. Required fields are marked *

Twitter Users!
Enter your personal information in the form or sign in with your Twitter account by clicking the button below.

Subscribe to comments on this post