Communecation.net

August 3, 2005

Howto: Streaming audio server on Debian

Filed under: Articles and howto's — admin @ 12:06 pm

This article is about how to to setup your own streaming audio server and audio source on Debian Linux, by the en dof the howto you will be able to stream *live content* to a server and redistribute it via a network. Please note that when I say *live content* this means using the line input on your sound card as the source (ie, dj’ing a mix with turntables not playing queuing up mp3s to play one after the other). It is a relativly simple process but there are a few little pitfalls.
I have used Icecast 2.20 for the server and DarkIce live audio streamer and Darksnow as a front end for it.


Icecast is a streaming media server which currently supports Ogg
Vorbis and MP3 audio streams. It can be used to create an Internet
radio station or a privately running jukebox and many things in
between. It is very versatile in that new formats can be added
relatively easily and supports open standards for commuincation and
interaction.
Icecast Readme


DarkIce is an IceCast, IceCast2 and ShoutCast live audio streamer. It takes audio input from a sound card, encodes it into mp3 and/or Ogg Vorbis, and sends the streams to one or more IceCast, ShoutCast and/or IceCast2 servers. DarkIce uses lame as a shared object as its mp3 encoder, and the Ogg Vorbis libs as its Ogg Vorbis encoder.
http://darkice.sourceforge.net/


DarkSnow is a simple GUI for darkice, written using GTK2, by Rafael Diniz, under GPLv2.
http://darksnow.radiolivre.org/index.en.html

All three applications are available under the GNU GPL and are opensource alternatives to commecial or closed source equivalents.

These are the steps we will take to install, configure and use our streaming audio server:

  • Meet the basic requirements.
  • Compile and install Lame.
  • Install the Ogg Vorbis tools.
  • Compile and install the Icecast server.
  • Compile and install DarkIce and Darksnow.
  • Configure the Icecast server.
  • Start the Icecast server and send some content to it using DarkIce via Darksnow and test to see if it all works!


Basic Requirements:

There are a few basic requirements for setting up your streaming audio server using this howto.

  • You need a computer with a spec of at least 700mhz, 512mb RAM and a soundcard with line in/mic in. (basically a computer that can handle encoding MP3’s on the fly, *I will find out the exact recommended spec soon*)
  • You need Debian installed on your computer (obviously this is far beyond the scope of this document.
  • A little time and patience! I had this up and running in about a hour or two.

Compile and install Lame:
** Please note, there is somthing weird with the licencing of mp3 encoders/decoders, I cant find anything about that specificly says that is is illegal or bad to compile, install and use LAME. I was told by somone in the Icecast irc channel that its probably a bad idea to suggest using it and that using Ogg Vorbis is much better, also using Ogg is more conforming to Debians open goals, I have however included LAME in the howto because I sometimes find it easier to stream to listeners in mp3, I have streamed in Ogg lots of times before and everytime I get someone complain they cant listen because they dont have the codecs installed (and are either too dumb or cant be arsed to install them), usually my only concern is playing music to people… not how they listen to it but I can see the mans point. If anyone could send me a quote and a source for the exact state on the licence issues It would be most appreciated. **

This is a fairly easy process as there is a debain build script already prepared by the Lame developers. I was stumped by two things tho, i was missing the G++ compiler and there is one file in the debian/ directory that needs to be edited.
First you need to get a copy of the Lame source. I used Lame version 3.96.1, this can be obtained directly

Here from the University of Kent’s Sourceforge repository or you can browse the Lame Sourceforge Project page yourself.
Once you have downloaded the source, extract it to a good place.

eddy@obiwan:~# tar -xvzf lame-3.96.1.tar.gz

eddy@obiwan:~# cd lame-3.96.1

Next we need to edit the file that gave me a few headaches.
The developers have left in a line that does not need to be there, once we remove it then Lame will compile properly and make a nice .deb package for you!
You may want to copy this file in case you need to keep it for some reason, i kept a copy just to be on the safe side… and if i forgot what the line we remove said.

obiwan:lame-3.96.1# cp debian/lame.docs debian/lame.docs.old

eddy@obiwan:lame-3.96.1# vim debian/lames.docs

The file contents of the look like this:

README
TODO
PRESETS.draft
USAGE

We need to remove the line that contains PRESETS.draft. So move the cursor down to that line and hit ‘dd’ then hit ‘wq’ to write and quit the file.
Next we just need to run dpkg-buildpackage to make our .deb. We do need to be root user to do this, so ’su -’ to become the superuser.

obiwan:lame-3.96.1# dpkg-buildpackage

The only other problem I came accross was that for some reason I had no copy of G++ installed, this was easily fixed by doing a quick ‘apt-get install g++’. Once the package has been built (hopefully without any errors) you can install it.
Three packages are actually made, Lame itself, the Lame libs and the development files for Lame libs.

obiwan:lame-3.96.1# dpkg -i ../lame_3.96-0.1_i386.deb
obiwan:lame-3.96.1# dpkg -i ../liblame0_3.96-0.1_i386.deb
obiwan:lame-3.96.1# dpkg -i ../liblame0-dev_3.96-0.1_i386.deb

Install the Ogg Vorbis tools:

This should be fairly easy, to be honest i already had the tools installed but i think you should only need vorbis-tools and libvorbis-dev.

obiwan:~# apt-get install vorbis-tools libvorbis-dev

Compile and install Icecast server:
Icecast server can be obtained here or you can browse their download page. Now we need to extract the files.

obiwan:~# tar -xvzf icecast-2.2.0.tar.gz
obiwan:~# cd icecast-2.2.0

I was missing a few packages, I am running a fairly stock install with not a huge amount of stuff already on it. To find out if you are missing any packages that Icecast is dependant on just run ‘dpkg-buildpackage’ in its directory, it will bork if you are missing anything.. if not then it will carry on. If you want MP3 support you need the lame libs installed, if you followed the earlier instructions then they should get picked up, the ./configure output will tell you.

obiwan:icecast-2.2.0# dpkg-buildpackage
dpkg-buildpackage: source package is icecast2
dpkg-buildpackage: source version is 1.9+2.0alphasnap2+20030802-1
dpkg-buildpackage: source maintainer is Keegan Quinn
dpkg-buildpackage: host architecture is i386
dpkg-checkbuilddeps: Unmet build dependencies: cdbs dh-buildinfo libxslt1-dev libxml2-dev
dpkg-buildpackage: Build dependencies/conflicts unsatisfied; aborting.
dpkg-buildpackage: (Use -d flag to override.)

Just install watever it says and hope for the best! :P

obiwan:icecast-2.2.0# apt-get install cdbs dh-buildinfo libxslt1-dev libxml2-dev
obiwan:icecast-2.2.0# dpkg-buildpackage

Once this has finished we can install the Icecast package!

obiwan:icecast-2.2.0# dpkg -i ../icecast2_1.9+2.0alphasnap2+20030802-1_i386.deb

Compile and install DarkIce:

Compiling darkice is quite easy, grab it from here. Again you will need the lame libs in order for MP3 support to work, the Ogg Vorbis libs are also needed for Ogg Vorbis support. Yet again we first have to extract the source.

obiwan:# tar -xvzf darkice-0.14.tar.gz

obiwan:# cd darkice-0.14


Now we will complie the source. We need to pass in an option to explicitly imply that we want MP3 support (of course unless you dont and just want to stream in Ogg!). Note that i also configured the source to compile with Ogg anyway, just to make sure. I also included the option to use ALSA aswell as the standard OSS input.

obiwan:darkice-0.14# ./configure –with-lame –with-vorbis –with-alsa
obiwan:darkice-0.14# make

obiwan:darkice-0.14# make install

This will make and install DarkIce and place the binary executable in /usr/local/bin/
Compile and install Darksnow: Darksnow is a frontend for Darkice, it makes using Darkice much simpler. Download Darksnow from here. Again, this is a pretty easy process as long as you have the GTK libs installed.

obiwan:# tar -xvzf darksnow-0.4.9.tar.gz
obiwan:# cd darksnow-0.4.9
obiwan:# ./configure
obiwan:# make
obiwan:# make install

..and that should be it, all installed! :D (…but dont forget to place a link on your Gnome or KDE toolbar using the handy dandy Darksnow icon I created, it is now included in the Darksnow tarball!)


UPDATE
: On Rafael Diniz’s Darksnow page, there is now link to a package for Debian created by Alexandre Amorim, you can grab it from here. But please note I have not tried and tested this deb so you’ll be on your own with it :P

Configure icecast server: There are a few important things that need to be changed in the basic config before we get up and running. Its an XML file so its east to navigate around.

obiwan:# vi /etc/icecast2/icecast.xml

Ok, the first thing is the number of clients you want to allow, I have set mine to 8 because I only have the crap upload speed of my ADSL line. This is in the first section entitled limits.

<clients>8</clients>

Next we want to sort out the authentication section, when we stream we will login to the server with the username of ’source’ but we need to set a password.


<source-password>spasswerd</source-password>

Next we need to set the relay password, relaying is where another server can connect to yours and rebroadcast the same stream. This is handy if like me you have no bandwidth, you can get other people to relay your stream to allow more listeners. The relay’s login name is ‘relay’.


<relay-password>rpasswerd</relay-password>

We then need to set the admin username and password.


<admin-user>admin</admin-user>

<admin-password>apasswerd</admin-password>

Now, the hostname

<hostname>my-streaming-host.com</hostname>

…and then set the ports you wish users to connect through, 8000 is the standard.

<listen-socket>
<port>8000</port>
<listen-socket/>

We need to set the paths to where the program, log files and webinterface reside but i think these should be set up fine already.

<logdir>/var/log/icecast2</logdir>

and make sure these point to the right place, the webinterface provides users with information about the stream and allows the admin user to see more detailed information aswell as move clients and mountpoints.

<webroot>/usr/share/icecast2/web</webroot>
<adminroot>/usr/share/icecast2/admin</adminroot>

Lastly we need to set the names of the log files

<accesslog>access.log</accesslog>
<errorlog>error.log</errorlog>

We can now start up the server!

obiwan:# /etc/init.d/icecast2 start

The error log should show somthing like this


[2005-03-16 13:41:18] INFO main/main Icecast 2.2.0 server started

[2005-03-16 13:41:18] DBUG yp/yp_recheck_config Updating YP configuration

[2005-03-16 13:41:18] INFO yp/yp_update_thread YP update thread started

[2005-03-16 13:41:19] DBUG slave/_slave_thread checking master stream list

Configure Darksnow: We should now be ready to try streaming some audio to the server so lets fire up Darksnow!
The first tab ‘Server Options’ is where we put the details for the server.

  • Streaming Destination: You want to select ‘Icecast2′ here, you can use Darkice/snow to stream to Winamp Shoutcast servers and Icecast 1 servers too.
  • Server: This should be the IP of the machine on which you installed theIcecast2 server, probly ‘localhost’ if its the same machine your running Darkice/snow on.
  • Port: Set this to whatever you set the port as in the icecast.xml file, 8000 is the default and standard.
  • Mount Point: This should somthing sensible like ’stream1′, the address for your stream will reflect this, http://www.my-streaming-host.com:8000/stream1 for example.
  • Password: This will be the source password we defined in icecast.xml.
  • Verbosity: This will be the amount of data that is shown in the details window when we start streaming.

The next tab is the ‘Audio Options’, this is where we set the quality we want to stream at and the input device.

  • Format: This is the type of audio format you want to stream in, Ogg Vorbis or MP3.
  • Bitrate mode: You can set this to constant bitrate or VBR.
  • Bitrate: The bitrate in which you want to stream, I usually use 24kbps so i can stream to about 7-8 people over my ADSL line, there is a handy bitrate calculator over at Radio Toolbox.
  • Samplerate: Seeing as were using a bitrate of 24kbps there not that much point in sampling at really high frequencies, so I set this to 22050.
  • Quality: This is the quality of the encoding 0-1, I set this to about 0.8.
  • Bits per sample: I use the default of 16, it will sound really terrible if any less really.
  • Number of channels: Stereo 2 or Mono 1, I use mono because it requires less bandwidth.
  • Buffer size: The amount of seconds buffered by the server before sending it on to clients. I set this to around 5.
  • Input device: /dev/dsp is the usual unless you have some weird configuration. The input comes from watever you set as the record device in your mixer app. I use aumix but you can use alsa-mixer or any other mixer.

The ‘Streaming description’ is where we have fun and get to make up a cool radio station name!

  • Radio name: The name of you station, ‘Eddy Radio’ for example.
  • Description: …not suprisingly a description ie, ‘The best fun you can have online without a box of tissues to hand’.
  • URL: The URL to your server.
  • Genre: A genre, dont worry you can put anything in here, like ‘Tech Step Deathcore’ if you really want.
  • Public: Yes/No, if you select ‘Yes’ then the server will appear on the Icecast stream directory.

Test the setup: Now we have everything set up you can plug somthing in to your soundcards line-in socket and fire it up! hit the ‘Start Streaming’ button in Darksnow to start streaming. You should now be able to connect to your server using XMMS etc, enter a url like:

host:port/mountpoint

mine would be

192.168.0.10:8000/stream1

You can also open host:8000/ in a browser are and get a url to open the stream with.
If everything has been setup correctly then you should be able to hear the input you are sending and XMMS’s EQ meters should be dancing about.
You can now give people the url and they will be able to connect and listen to your stream, make sure you open and forward the ports you specified in icecast.xml.

Well, there we go, it worked for me and I hope it works for you, if i have missed out any steps or have gotten somthing wrong dont hesitate contact me via the contact page and i shall make amendments. :)
Comments:

 

“thanks
for this HOWTO, i’ve been looking for this for a while in some forums
and haven’t been able to find anything as clear as this. my darkice is
finally working :-)
now a question: is it possible to use darkice to stream also playlists?
i’m new to linux (thanks to ubuntu) and have worked with shotcast and
oddcast. both programs let you stream either soundcard input or
playlists.
i’ve seen that there is an oddcast version for linux using jack, but i
haven’t been able to meke it work (jack doesn’t have a lot of
documentation, at least for the newbies).
thanks again.”

#1 ignacio on 2005-08-02 16:59

Eddy Says: Well, to stream playlists of MP3s you need to use somthing like MuSe, this allows multiple streams to different servers or mount points. Alternativly if you want to stream playlists of Ogg files (as recomended by Xiph.org) then you can use Ices 2.0.

I may well add to this howto sometime soon as a few people have now asked me the same question.

1 Comment »

  1. This seems promising. I am at school now and haven’t the chance to try it yet. I have been fighting with an ubuntu computer to stream a line on the internet. The computer is for a radio station that wants it online (it will be from this pc until thye get a host for more listeners to connect due to bandwidth). As if now I run a 1/8″ from my laptop to the mic in. I have tried muse and also jack, and although muse once worked with jack, it does now. Now using darkice/icecast/darksnow it never starts streaming (in darksnow). I press stream and it doesn’t. In the details it says its ok with ogg mono (can’t do stereo) but it isn’t. I will try aumix again without jack and then alsa mixer. I will also try the dsp again as the input in darksnow. Thanks

    Comment by DJ HaKa — July 11, 2008 @ 1:43 pm

RSS feed for comments on this post. TrackBack URL

Leave a comment

Powered by WerdPress seen!!