frozen

Here at the college, we used to have a streaming media server running Windows Server 2003 for the purpose of broadcasting our athletic events. At some point, it broke, and it became apparent that it would be necessary to rebuild said media server. Being the fan of Microsoft that I am, I decided to go a different route, and try my hand at running Icecast on Linux. Originally, I intended to use ogg for audio encoding, but given our user-base, I decided to do mp3 instead. I didn’t want the headaches of dealing with plugins, and weird file associations on Windows, and making the user jump through twenty hoops to listen to our games. My initial concerns were with licensing, since mp3 is a proprietary format, and typically looked down upon with scorn by the linux community. So I went to the source. The licensing for mp3 explicity permits using the mp3 format without licensing fees if you are a non-profit, and are making absolutely no money from your use of the mp3 format. If you aren’t sure about that, see http://mp3licensing.com/royalty/emd.html.

So now for the fun stuff. Ices2 doesn’t support mp3, so it was off to find an encoder that supported mp3 and would talk to Icecast2. In case you’re not too familiar with Icecast or Ices, you must have 2 parts to stream audio. A front end (Icecast) to serve the comressed audio to clients, and a back end encoder (Ices, darkice, liveice, etc.) to compress the audio from whatever source you are using.

We are running on actual server hardware, which doesn’t have any built-in audio capability. It also only has one available PCI slot, which is used by the RAID card, because it is a 1U rackmount chassis. So we bought a Startech USB Audio Adapter from newegg.com for our input source. We’re using Ubuntu 9.04, although 9.10 is coming out in several days.

First we want to get icecast up and running:

aptitude install icecast2

Then you want to make sure you edit the passwords in /etc/icecast2/icecast.xml. The source-password will be the password that ices, or in our case, liveice-sn uses to connect to icecast.

Once we’ve changed the passwords to something a little more secure, we can modify /etc/default/icecast2 to enable the icecast2 daemon, and then start it up with:

/etc/init.d/icecast2 start

If you get a failure message, make sure you have nothing else running on port 8000 (like I did).

That’s the easy part, now we want to get our encoder, liveice-sn from http://liveice.sourceforge.net/

We’re compiling it from source, but don’t bail out on me now. You first need to install the build tools:

aptitude install build-essential

Extract the tarball:

tar xvzf liveice-sn04.tar.gz

Before we compile anything, we need to make a small change to liveice.h to avoid getting garbage for sound.

Find the line that says #define NUMBER_LITTLE_ENDIAN and change it to #define NUMBER_BIG_ENDIAN

./configure
make

I’m running it right from the source folder, so I’m skipping the ‘make install’ command, you can do as you wish.

To get audio working properly, it seems I had to do the following (you can skip this and come back if you need to)

aptitude install alsa-base alsa-utils alsa-tools libasound2
asoundconf list

Then choose your sound card from the list, and do this to set the default:

asoundconf set-default-card name-of-soundcard-here

I believe a reboot was necessary to get /dev/dsp1 (yours might be just /dev/dsp) to show up.

Ok, if your audio is already working, you can copy the provided config file to the config file you’re actually going to use. It’s a good idea to make this copy, just in case you blow something up, and need to start fresh from the default config again.

cp liveice.cfg.dist liveice.cfg

Then you need to modify the following:

PASSWORD can be deleted, we’re going to set it later towards the bottom of the file (if you have issues, put it back)

USE_LAME3 /usr/bin/lame

SOUNDCARD (NO_SOUNDCARD should be commented out, put a # in front of it)

I had to set SOUND_DEVICE /dev/dsp1 for my USB audio device

comment out the X_AUDIOCAST_LOGIN and MOUNTPOINT lines, and uncomment HTTP_LOGIN and set MOUNTPOINT if you want

Set NAME, GENRE, URL (to your website or some relevant page), DESCRIPTION, and PASSWORD to appropriate values. PASSWORD should be what you set in the icecast config earlier.

comment out PLAYLIST, and that should be it. You can also set VERBOSE 10 if you’re having trouble making it work.

We’ve told liveice to use lame for the encoder, so we should probably install it…

aptitude install lame

Then (from the liveice-sn04 folder) run this command to give it a whirl:

./liveice -F liveice.cfg

Test it out by browsing to http://servername:8000

You can adjust bitrate, and quality settings to suit your particular application, but the defaults seem to be just splendid for broadcasting sports games (we could probably drop them even lower).

Once you’re satisfied with the way it is running, run it like so:

./liveice -@ 2 -F liveice.cfg

To see more command line switches, try ./liveice -h

To have liveice run at startup, put that command in /etc/rc.local, but use full paths. For mine, it is:

/home/username/liveice-sn04/liveice -@ 2 -F /home/username/liveice-sn04/liveice.cfg

Hope that helps someone else out there, the first time I set this up, it took several days, and lots of frustration, to get it working.

If you’re interested in doing the same, except using mp3’s as your input source, see Unthawed.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.