This article is outdated and may not work correctly for current operating systems or software.
The following tutorial explains how to set up a IceCast radio streaming server and play audio files (music or podcasts) on the FreeBSD platform. This tutorial assumes that you are running FreeBSD 10.0 or higher and that you are logged in as the root user. It also assumed that you have a text editor to edit configuration files.
Before we begin, it is important to understand the three parts of an audio streaming server. First, we have the server software itself, IceCast. IceCast acts like a central hub where audio streams come in and get sent out. The IceCast service takes in audio streams from source clients. Source clients are programs which read audio files or other sources of audio, such as microphones. In our example, the source client is Ices and it supplies an audio stream to the IceCast server. The third component is a listening client. Audio streams travel from the IceCast server to listeners who then hear the audio. Typically a listening client is a desktop application, such as a web browser, the VLC multimedia player, or WinAMP. Visually, the arrangement looks like this:
Source client (Ices) --> IceCast server --> Listening client (browser)
To set up an IceCast streaming server on FreeBSD, we first install the server software itself. This can be done by running the following command.
pkg install icecast2
We then open the
/etc/rc.conf file and enable the IceCast background service. This is done by appending the following text to the bottom of the
Our next step is to configure the IceCast service. The IceCast package ships with a sample configuration file that we can modify. This sample file is located in the
/usr/local/etc directory. We will make a copy of this sample file before editing it.
cd /usr/local/etc cp icecast.xml.sample icecast.xml
We now want to edit a few key fields of the
icecast.xml file. Most of the file can be left with the default settings, but we should change the login information. We can do this by visiting the authentication section (at about line 30) and changing the source-password and relay-password to something appropriate. These passwords will allow us to stream data to the IceCast server from a source client. We should also change the admin-user and admin-password variables to something unique to our system. These two credentials guard the IceCast server's web-based interface. Then, down around line 150, we should change the variables mount-name, username, and password. These three variables protect the IceCast server's mount point. Finally, at the bottom of the
icecast.xml file we should see a security section that has been commented out. We should remove the opening <-- and closing --> symbols from around the security paragraph. Once the
icecast.xml file has been changed, save the file.
Once the configuration file has been edited, we want to enable logging. To do this, run the following commands.
mkdir /var/log/icecast chown nobody:nogroup /var/log/icecast
Finally, we start the IceCast server, This causes the server to listen for input and incoming client connections.
service icecast2 start
The IceCast server is up and running, so now we need to provide it with something to play. Our next step is to install the Ices source client. FreeBSD currently does not offer a binary package for Ices, so we need to build it from ports. This can be done by running the following commands.
portsnap fetch portsnap extract cd /usr/ports/audio/ices make install make clean
The Ices source client will need a user account and logging. To create a user for the Ices software and set a password on the account, run these commands.
pw groupadd ice pw useradd ices -g ice -m passwd ices
With the user created, we can now enable logging for Ices.
mkdir /var/log/ices chown ices:ice /var/log/ices
From here on, we should no longer need root user access and can operate as the ices user. Next, we need to create two directories. One directory,
music, will contain the audio files that we are going to stream. The second directory,
conf, will contain our configuration files.
su ices cd /home/ices mkdir music conf cp /usr/local/share/ices/ices-playlist.xml conf/configuration.xml
We now have a sample configuration file in place. It is time to edit the
conf/configuration.xml file to suit our environment. The only parts of the file that we need to change are down around line 60. Here we need to provide the password and mount location we set in the
icecast.xml file. For example, if we set our mount name in the
icecast.xml file to be
/radio.ogg, then we should change our
configuration.xml file's mount parameter to also be
/radio.ogg. Our password field in
configuration.xml should match the source-password we created in the
icecast.xml file. Once our
configuration.xml file has been edited, we will need to save our changes.
With the configuration file in place, the next step should be to copy audio files that we wish to stream into the
music directory. The audio files should all be in
.ogg format as IceCast will not handle
.mp3 files with its default settings. Once all of the audio files that we wish to stream are in the
music directory, we need to create a playlist. A playlist is a plain text file with a list of the music that we want to stream. We can easily create a playlist with the following commands.
cd /home/ices/conf ls -d ../music/*.ogg > playlist.txt
The audio files will be played in the order they appear in the
playlist.txt file. The file can be edited in any text editor to adjust the order of the streaming audio.
All that we need to do to begin streaming our audio files is to run this command.
Side note: Often we may want to run the Ices source client and then logout and go do something else. In that case, I like to run Ices from within a screen session. Here is an example on how to run ices with screen.
screen cd /home/ices/conf ices configuration.xml
Then press Ctrl + A and tap the D key. That will detach the screen session and allow us to logout while Ices plays audio in the background. Later, we can halt Ices by logging in and running:
screen -r killall ices exit
We can now connect to our server on port 8000 in a web browser to listen to our audio stream. The URL will look like
http://myservername:8000. This address can be made publicly available if you want to let others listen to the stream.
Earlier, I mentioned that IceCast plays
.ogg files and not
.mp3. This is fairly easy to overcome on FreeBSD. As the root user, we can install a conversion tool, called sox, which will convert our
.mp3 files to
.ogg files. Assuming all our
.mp3 files are in the
/home/ices/music directory, we can install sox and perform a conversion as follows:
pkg install sox cd /home/ices/music for i in *.mp3; do sox ./"$i" ./"$i".ogg; done
We can then refresh our playlist using:
cd ../conf ls -d ../music/*.ogg > playlist.txt
Please keep in mind that audio streaming can be bandwidth intensive. One or two clients listening to our radio station will not require much bandwidth, but 50 or more clients could push a server over its allotted monthly bandwidth. It is a good idea to enable bandwidth capping on the streaming server to avoid unexpected financial costs.