Serving an Audio Stream from Fedora Linux

The logos of the Icecast and Fedora projects.

An audio stream server allows you to make any audio content on your computer available to anyone on your own local network or on the internet. This page provides a summary of the steps required to set up a stream server on Fedora Linux.

This tutorial shows how to use the Icecast media streaming server to stream audio in the Ogg/Vorbis format. For more information on streaming and this software, see the Links section at the bottom of this page.

Installing the software

All of the software required for getting a basic streaming server up and running is available through the Fedora and RPMFusion repositories for YUM.

Icecast
This server software streams content to any compatible client on the local network or on the internet. A package called icecast is provided in the Fedora YUM repository.
Music Player Daemon (mpd)
This player provides the icecast server with content to stream. A package called mpd is provided in the RPMFusion YUM repository.
Music Player Client (mpc)
This command-line program is a client program for controlling the Music Player Daemon. It provides commands similar to a music player e.g. play, stop, forward, load playlist. A package called mpc is provided in the Fedora YUM repository.

To install this software, execute the following command as root:

$ yum install icecast mpd mpc

Note: the RPMFusion repository should be enabled in your YUM configuration before executing this command. These packages have various dependencies but these should be resolved automatically by YUM.

Configuring the Icecast server

The Icecast server package includes a sample configuration file which is installed at /etc/icecast.xml. Although there are lots of options in this file, I found that I just had to change the hostname value to the name of the machine I wanted to stream media from.

It should be noted at this point that the default port for the server is set to 8000. If you have a firewall program installed, you should check that access will be allowed to that port from whatever machines you want to listen to the stream on.

You can also change the passwords of the three user accounts set up by default for the server:

source
This account is used by the program that is providing the content to the Icecast server
relay
This account is used to connect various stream servers together
admin
This account is used by to change settings e.g. via the web frontend (which we will discuss shortly)

You should be able to start the Icecast server at this point. Execute the following command as root:

$ service icecast start

You should see the following output:

Starting icecast streaming daemon:                        [  OK  ]

Once the service has started successfully, you can use you web browser to access the web configuration tool. This can be found at the URL http://your-hostname:8000/

In the menu bar at the top of the page, click the Administrator link. You should then be asked for a username and password. This is the admin account mentioned above. Once logged in, a page entitled Icecast Streaming Media Server should show with some summary information about the current configuration. This web page will contain much more information once you are actually streaming content.

Configuring the Music Player Daemon (MPD)

Once the server is up and running, you must provide it with some content to stream. This can be achieved in a number of ways but for this example we will use the Music Player Daemon. The mpd package does not contain a sample configuration file so I have included one here. I suggest you copy the following text into a file at /etc/mpd.conf.

music_directory "/mnt/stream"
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"
        format "44100:16:2"
    name "Music stream"
    host "localhost"
    port "8000"
    mount "/stream.ogg"
    password "changeme"
    quality "5"

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

The first group of options specify various file and directory paths including music content, playlists, and logs. The values I have used here are just suggestions. Note however that the directories /var/lib/mpd and /var/run/mpd are not created when the package is installed so you should create them and the subdirectory /var/lib/mpd/playlists or choose other paths before starting mpd.

The audio_output section specifies the properties of the content that will be provided to the Icecast server. These values should provide a stream of audio with reasonable quality.

Once you have created the configuration file, you can start the mpd daemon by executing the following command:

$ mpd

You will notice an error indicating that a database could not be found. This is normal the first time the daemon is run. The daemon should then start to list all the compatible content found in the music_directory as it imports into a new database. When this is completed you should be returned back to the command line.

At this point it might be useful to recap on what we have achieved: you are currently running the Icecast streaming server on port 8000 and the Music Player Daemon is running and ready to provide your media content to that server.

Streaming content to clients

The final step in the process is to load content into the playlist of the Music Player Daemon. This is achieved easily by using the mpc program. If you execute the following command, you will get an idea of how this program can be used:

$ mpc --help

The use of some of the mpc commands are shown below. Note that mpd must have been started before some of the functionality of mpc will work. You can find out if the daemon is running by executing the following command:

$ ps -e | grep mpd

If no results are shown, then the mpd daemon is not running.

When you first start the Music Player Daemon there will be no content in the playlist. You can confirm this by executing the following command:

$ mpc playlist

The content which can be added to the playlist can be determined by executing the following command:

$ mpc ls

This will display the content that is immediately below the music_directory path which you specified in the configuration file. You can use normal command-line syntax with this ls command to navigate the directory structure e.g.:

$ mpc ls Classical/Beethoven

To add content to the playlist you can use the following command:

$ mpc add <PATH_TO_CONTENT>

If you want to add all content to the playlist use:

$ mpc ls | mpc add

To add all content below a subdirectory to the playlist use:

$ mpc ls <SUBDIR_PATH> | mpc add

Verify that the playlist contains the content you wanted by executing the playlist command again:

$ mpc playlist

To start playing the content simply execute:

$ mpc play

A brief message will be displayed summarising the playing options that are currently set:

volume: 74%   repeat: off   random: on

If you refresh the Icecast server page on your browser, you should see information about the content which is currently being streamed.

Listening to the stream

In order to listen to the stream, you will need a media player capable of receiving streams. Xine, MPlayer, and Amarok are just some of the player which support this format.

To connect to the stream you will need the URL of the playlist published by the Icecast server. This is usually located at: http://your-hostname:8000/stream.ogg.m3u .

Once you open this URL in your player, you should be able to hear the content.

The following links provide more information on the steps outlined here:

  • The Icecast homepage
  • The Music Player Daemon homepage
  • Gentoo Wiki page on using Icecast and the Music Player Daemon
  • Gentoo Wiki page on the Media Player Daemon
  • Jonathan For's Blog: Your own internet radio station with MPD/Icecast
  • General FAQ site for Fedora