This tutorial will guide you through the process of installing and configuring Icecast2, MPD, and ncmpcpp.
First, a quick summary of the various components that make up the entire internet radio system:
- Icecast2: This acts as a front-end that is presented to clients, and handles the publishing to public internet radio directories, making the playlist files available to the client, and generally making the whole process for clients a lot easier.
- MPD (Media Player Daemon): This handles the actual media playback, transcoding, and streaming to the client.
- ncmpcpp (NCurses Media Player Client Plus Plus): This controls the MPD and tells it what files and playlists to play, and when. Basically your remote control.
Stuff you’ll need:
- Computer with an adequate CPU
- What is adequate enough? Depends on how many radio streams you’ll be running simultaneously, how many people will connect to each of those streams, and how high quality the stream is going to be.
- A 1Ghz, Single-core CPU should be enough to run a single radio stream for one client at 256Kbps quality in Stereo. However, your mileage may vary, especially if your system is running other stuff besides the internet radio server.
- A big enough storage medium to hold all the music.
- A fast enough network upload speed to handle all the clients.
- What is fast enough? Again, depends on some factors. In this case, the only factor we need to calculate is three things per stream; the number of people connected, the bitrate quality of the music, and if it is mono or stereo.
- Basically, the formula breaks down to this:
- ( ( s * q ) * c ) = x
- s = 1 for Mono, 2 for Stereo
- q = Bitrate quality of stream (if stream content has a variable bitrate, take the highest bitrate value possible for worst-case scenario)
- c = Number of clients connecting to the stream
- REMEMBER: This is per stream, not per server. You will need to run this formula again for the other streams you have, then add all the totals together for your maximum required upload speed. Remember to convert from Kbps to Mbps as needed.
- Linux Kernel 2.6 or newer, and the dependencies satisfied for the following packages:
- A text editor (Take your pick on this one. I like nano because it’s easy to use, but vi is worth learning how to use as well.)
Before you get started, you’ll want to have the following tasks completed:
- Linux installed, and fully updated.
- If you are behind a firewall or NAT device, forward TCP port 8000. (If you change the Icecast2 default port, you will need to adjust this appropriately).
- Gather your media files and upload them to a empty directory on the server. We’ll move them to the correct location later. You can skip this step if you are going to convert the files to Ogg Vorbis format on your own PC before uploading.
- Have ncmpcpp, mpd, and icecast2 installed. Either compiled from source or installed via your package manager, it doesn’t matter.
- Do your bandwidth calculations! This is the most important part, if you don’t want your station to keep cutting out randomly or buffering all the time for your clients, doing this work now will save you a lot of troubleshooting heartache later.
Let’s do it!
- Open and edit /etc/mpd.conf (or wherever your mpd install is looking for the config file)
- The first directive, music_directory, we can leave as default. If you want to change this so you can use alternative storage, you can do so here.
- Next, the playlist_directory directive is similar to the previous one; we can change it or leave it as default. Typically playlist files are only a few kilobytes in size, so they don’t take up too much space.
- Skip down to the log_file directive. Here, you can change the log file’s location. I recommend leaving this as the default.
- Skip down to the bind_to_address directive, and set it to “127.0.0.1” (with quotes). Make sure to include a space between bind_to_address and “127.0.0.1”.
- The port directive tells mpd which port to bind to; since we’re running both mpd and Icecast2 on the same computer, we can leave this at the default of “6600”.
- Jump down to the save_absolute_paths_in_playlists directive. This doesn’t matter too much. Setting this to yes won’t hurt you in the long run.
- Scroll a long ways down to the audio outputs section of the config file. Here is where we will detail our streams. If you don’t see this section in mpd.conf or you’re making your own mpd.conf file, use this template:
encoding "ogg" # optional, unless you want to force a particular encoding type
name "Example Radio"
quality "10.0" # This is the defined VBR quality for the stream. Either
# use this setting for a VBR with a target quality of 10
#(numbers vary based on your encoding type).
# bitrate "320" # Uncomment and use this to force a CBR in kbps
format "44100:16:2" # SampleRateKhz:Bits:Channels (1=Mono, 2=Stereo) - Example: 44100:16:2 - *'s are also acceptable
protocol "icecast2" # optional
# user "source" # optional
description "Example Radio Station" # optional
genre "Example Music Genre" # optional
public "yes" # optional, enable this so you can be listed on stream lists
timeout "2" # optional, amount of time you will wait for the output to become available
always_on "yes" # for shoutcast or icecast, always enable this
# MORE DETAILS:
# copy the entire block above for another stream, only mandatory change is the mount option, all others are optional,
# but changing the name, etc. is recommended especially for the end user's sake
# if MPD throws errors about trying to output to a sound card or other physical
# audio device, you can try this to suppress it - ALWAYS LIST THIS OUTPUT LAST
name "fake out"
- If your music or paths to your music contain non-ASCII characters you might need to define the encoding scheme here.
# Character Encoding ##########################################################
# If file or directory names do not display correctly for your locale then you
# may need to modify this setting. After modification of this setting mpd
# --create-db must be run to change the database.
# This setting controls the encoding that ID3v1 tags should be converted from.
- Now is a good time to go through mpd.conf and check for stray braces; they can cause MPD to silently fail with no errors!
- Make a backup copy of /etc/icecast2/icecast.xml to your homedir or other location outside of /etc/icecast2/. Then start editing /etc/icecast2/icecast.xml.
- The first thing you'll want to edit will be the <location> and <admin> tags; Change the location to wherever your server is located, and change the admin tag to your email address.
- Take note of the <limits> section. Obviously, <clients> is the maximum amount of streaming clients that can stream from the server at any one time. <sources> is the number of different radio "stations" or "streams" you can have added to the Icecast2 server simultaneously.
- In the <authentication> section, change <source-password> to whatever you set in mpd.conf in the previous steps.
- Change the <admin-user> and <admin-password> to something secure that you can remember. This is used for the web admin portion of Icecast2.
- If you want your server to be on the public listings at dir.xiph.org, uncomment the following block:
- Change the <hostname> parameter to match the DNS record of the server that Icecast2 is running on. If Icecast2 is running on a server that has example.com as its domain name, put "example.com" here.
- Locate the first <listen-socket> block and modify it to make it look like this:
(If you've defined a different stream password for each stream, define it inside the <listen-socket> block instead of the main <icecast> block using <source-password>.)
- Edit each block as needed:
Stop and restart the mpd and icecast2 servers by calling them through your system init daemon. Generally this will mean running the following as root:
- port: This is the port you specified for the stream in mpd.conf earlier. They need to match.
- bind-address: Set this to 127.0.0.1, since MPD is running on the same PC as Icecast is.
- mount: Change this to match the mount specified in mpd.conf. Proper extensions are recommended as some streaming clients like Winamp are picky about this.
/etc/init.d/icecast2 stop && /etc/init.d/mpd stop && /etc/init.d/mpd start && /etc/init.d/icecast2 start
Now we need to tell MPD that we have music for it to play. As any user on the system, run ncmpcpp.
Finally, open your web browser and go to the IP address or domain name and the port you picked in your browser. In our example, we would go to http://example.com:8000/.
- ncmpcpp is set up to automatically connect to the locally running MPD instance. It will first start at the current playlist window, which is empty right now since we haven't added any files yet.
- Press "2" to switch to the file browser window. This will show you the contents of the /var/lib/mpd/music/ directory (or whichever music directory you told MPD to use).
- If the file browser is empty, press "u". This will force an update of the MPD database. It may take some time depending on how many files you have in there.
- To add files to the current playlist, just press "t" to toggle to select mode, use Up/Down to move the cursor, Space to highlight, then press "a" to add the files you highlighted to a playlist. You'll then be asked if you want to add these files to a new playlist or the current one.
- If you want to add all the files in the current directory, just press "v", then "a". The "v" key inverts the current selection.
- Now press "1" to go back to the current playlist. Any change you make here (if you've opened up a previously saved playlist) will not be saved in this window (use the playlist editor for that by pressing "5"). Use the following keys to start playing music:
- Enter: Play currently highlighted song, and continue to follow current playlist.
- "s": Stop currently playing song.
- "p": Pause currently playing song.
- ">": Skip to next song.
- "<": Skip to previous song.
- Backspace OR Ctrl+H: Restart current song from the beginning.
- For all possible commands, you can press F1 at any time. To leave the help menu in ncmpcpp, press any window number ("1", "2", etc.)
- Depending on what you want to do, you can have ncmpcpp repeat the current playlist and/or pick songs to play at random. To toggle repeat mode, press "r". To toggle random mode, press "z".
Congrats, you're done!
- You should see the streams on the main page with all the correct details, and links to a M3U file, and a XSPF file. Pick whichever format is supported by your streaming client.
- For a list of compatible clients, go here.
- You'll be prompted to download the M3U file, go ahead and do so. Open it with a supported player and you should start hearing your music!
- In your web browser you'll also notice an "Administration" link. This is used to manage some aspects of the streams, including who's currently listening to them. When you click on the link you'll be asked for a username and password, which you set previously in /etc/icecast/icecast2.xml.
- In here you can view diagnostic details about all streams as well as the server itself. You can also view any clients who may currently be connected and listening to the stream right now, and optionally kick those clients if you want.
Need further help?