COVER STORY Streaming with Icecast

Streaming audio with Icecast and MuSE HOME RADIO

nternet audio comes in many forms, For live Internet radio, you need a streaming server. We’ll show you from ordinary sound clip links to Ipodcasts magically delivered with how to get started with Icecast, an open source streaming alternative RSS-based push technology. Many listen- for Linux. BY DANN S. WASHKO ers, however, will settle for nothing less than live content in real time. Internet radio broadcasts arrive at open project that runs equally well on Dann Washko has been running your home PC courtesy of a streaming Linux/ BSD, OS X, and Windows. Ap- Slackware systems for the past server. You’ll find streaming servers on ple’s commercial version offers slick in- eight years and has recently begun the Internet that can transmit live audio tegration with the OS X server utilities experiencing the joys of Debian and or video, pre-recorded playlists, or on- and support from Apple. The Darwin Arch Linux. demand media. Most streaming servers Streaming Server lacks official support, He is a Co-Founder of the Lehigh provide source buffers and offer com- but Darwin has a growing community Valley Linux Users Group and a co- pression to reduce bandwidth costs. accessible via IRC, mailing lists, and fo- host of The Linux Link Tech Show, a weekly live web radio show and A number of commercial and open- rums. podcast. For more Linux related source streaming servers are available Similarly, RealNetworks offers a com-

THEAUTHOR podcasts and web radio shows for Linux systems. Apple’s Quicktime mercial streaming solution called Helix please visit http:// www. thelinuxlink. Streaming server, a commercial product Server [2], built upon the Helix DNA net. Have a Linux related show that designed to run on OS X servers, is built Server, for which the source code is re- is not listed? Send an email to on Apple’s Darwin Streaming Server. leased under both the RealNetworks [email protected]. The Darwin Streaming Server [1] is an Community Source and RealNetworks www.photocase.com

32 ISSUE 66 MAY 2006 WWW.LINUX - MAGAZINE.COM Streaming with Icecast COVER STORY

Public Source. Although the commercial client to a multimedia content stream. nections. In the case of a live broadcast, version includes support for most media The Icecast server can transmit data in the source client might be an application formats, the open offerings are limited to , ogg , and unicast that interacts directly with the audio in- MP3, RealAudio, and RealVideo. streams over HTTP. terface to which the microphones are One stable and readily available In a typical streaming scenario the lis- attached. In the case of pre-recorded streaming server for Linux users is Ice- tener makes a connection to the stream- audio, the source client may simply be cast2 [3]. Icecast is an open source proj- ing server using an ordinary browser, acting as a music player transmitting and ect supported by Xiph.org, an organiza- and the stream becomes sound on the audio stream to Icecast. tion dedicated to “…protecting the foun- listener’s computer through a media In this article, I’ll describe how to in- dations of the Internet multimedia from player such as AmaroK or XMMS. stall and configure Icecast, and I’ll show control by private interests.” [4] You can Of course, the audio stream Icecast you how to set up a source client to download the source code for Icecast beams to the client must originate from stream content to the Icecast server. Sev- from [3], but the chances are your Linux somewhere. Icecast is capable of playing eral source clients are available, includ- distro already has an Icecast package audio files from a playlist. But it is per- ing IceS, which is produced by the Ice- ready for installation. As of this writing, haps more common to see Icecast receiv- cast team. I’ll tell you more about IceS, the current version of Icecast2 is 2.3.1. ing the audio feed from an external ap- and I’ll also show you how to set up a plication known as a stream source or stream using the MuSE source client. What is Icecast? source client. The source client transmits A streaming server such as Icecast lis- the streaming data to Icecast, and Icecast Installing Icecast tens for incoming connection requests then makes the stream available to the If you are going to compile from source, from Internet clients and connects the world through Internet-based client con- Icecast requires that you have the devel-

Listing 1: Sample icecast.xml configuration file 01 27 02 28 /myshow 03 5 29 04 2 30 05 5 31 1 06 524288 32 07 30 33 08 15 34 /usr/local/share/icecast 09 10 35 /usr/local/var/log/icecast 10 1 36 /usr/local/share/icecast/web65535 webroot> 12 37 /usr/local/share/icecast/admin 13 38 14 39 15 sourcepassword 40 16 relaypassword relay-password> 42 access.log 17 admin 43 error.log 18 changeme 44 1 19 45 10000 20 46 21 myhost.org 47 22 48 23 49 0 24 8000 50 25 51 26

WWW.LINUX - MAGAZINE.COM ISSUE 66 MAY 2006 33 opmental libraries for libxml, figuration either in /etc or a libxslt, libogg and libvorbis. subdirectory of /etc. The ac- By default Icecast requires tual location of the file does curl, but you can opt to com- not necessarily matter, as you pile without curl using the must specify the path to the -without-curl switch. Without configuration file when start- curl, Icecast cannot perform ing Icecast. any Directory Server interac- Listing 1 illustrates a sim- tion; that is, you will not be ple icecast.xml file. When ed- able to advertise your stream iting the icecast.xml file, on the public Icecast YP lists. make sure all xml elements Theora libraries are re- are closed, xml tags are quired for theora video spelled correctly, only al- streaming (check out ez- lowed xml tags are used, and stream [5] for a theora source all nested elements are prop- client). For mp3 streams, you erly closed. should have Lame installed The most important values [6]. Most likely, the optional to set in icecast.xml are in the features will be detected by Authentication section. Make the configure script, so you sure you set your own source, may not have to provide the relay, and admin passwords, enabling switches. as well as the admin-user and After downloading and ex- admin-password values, tracting the source, install which are used for adminis- Icecast with the simple three trative functions accessible step process: through HTTP. Icecast has its own administrative webpages ./configure that are much easier to use make than the administrative syn- make install tax. For more information re- garding the administrative Icecast installs in /usr/local syntax, consult the Icecast by default. Installing Icecast documentation. The relay using your package manager password is necessary for should be pretty straightfor- relay servers . (See the box ward. Debian users take note titled “Icecast Relays.”) that, by default, Icecast is dis- The Authentication section abled in /etc/default/icecast2. settings are the only values Prior to enabling Icecast and that must be set in order to starting the service, it is im- begin streaming. The remain- perative that you edit the Ice- ing settings can be left at the cast configuration file and, at defaults, but inserting your the very least, change the own values is recommended. password for source and See the box titled “Icecast relay clients and the adminis- Settings” for more on Icecast trative account. configuration parameters. Arch Linux users should be Should you wish to serve aware that the log file subdi- up static files using your Ice- rectories are not created. You cast server, the fileserver will need to manually create value must be set to 1. Set- the directory, which by de- ting this value to 0 prevents fault is /var/log/icecast. static files from being streamed. These media files Configuring Icecast must be placed in the webroot The default configuration file, directory and specificied in icecast.xml is located in /usr/ the url path of the client as a local/etc if you install from relative path from the web- source. Most package manag- root directory. Ogg-vorbis, ers will likely install this con- ogg-theora, and mp3 files can COVER STORY Streaming with Icecast

be served this way. Additionally, you can likely, you will not need to change these that is the case, simply issuing the start create a playlist containing a mixture of values, but do take note of them, partic- script (debian users: /etc/init.d/icecast supported media types. A playlist would ularly if you installed from source or are start) should initialize the server. If you contain a list of mount-points and usu- using Arch Linux. The log path may not have installed from source, you have a ally has an .m3u extension. An example exist, requiring you to manually create few choices. playlist might look like: the directory structure. Setting the log- First, make sure you have created the level may be helpful in debugging prob- log sub directories under the as per log- http://mystream.org:8000/U lems with the server, source streams, or dir element in the configuration file. Sec- intro.ogg relays. The value set in the example only ond, decide what user account you will http://mystream.org:8000/U reports errors. If you are having prob- be using to run the icecast server (create song1.ogg lems, raise the value to 4 for debugging. a new account and group if necessary). http://mystream.org:8000/U You will need to set the owner and own- song2.mp3 Starting Icecast ing group of the icecast log directory to Once the icecast.xml file has been prop- the user and group you will be running You can mix media types in a playlist. erly configured, it is time to start the the Icecast server as, and ensure that This playlist requires that the three files Icecast server. Do not run the server as this user and group have write permis- all be located in the webroot directory. root. If you have installed Icecast from sions to the log directory and the files The remaining configuration sections your package manager, chances are an under the log directory. Then as root: have to do with paths and logging. Most icecast user and group were created. If su [user] -c 'U Icecast Settings [path_to_icecast_binary]U The first section of the icecast.xml sets point. These values are all in seconds. /icecast U -c [path_to_configuration]U some restrictions for the server. Your Burst-on-connectwill send a burst of bandwidth will determine the number of audio data to the client upon connection, /icecast.xml &' clients allowed to connect simultane- This helps reduce the delay time clients U ously. Be aware that your source may experience should their media su iceuser -c streams will also consume bandwidth. player maintain a buffer. While the over- '/usr/local/bin/icecast -c U You risk interrupting the source stream all time from connection to the user ex- /usr/local/etc/icecast.xml' or causing problems with client connec- periencing the content is reduced, imple- tions if these values are set too high. menting Burst-on-connect will introduce Alternately, if you are logged in as the Threadpool indicates how many sepa- a short lag in the client’s stream. account that you want to run Icecast, rate threads the server should start to Burst-on-connect accepts a 1 for on and simply run it under your current ac- handle client connections. The default a 0 for off. Burst-size is a size of the data count: value is five, but you may need to raise burst in bytes. The default value is 65535 this value to account for high traffic bytes (64kb), which should be sufficient. [path_to_icecast_binary]U streams. Be careful not to set this value Hostname is pretty evident; enter the /icecast -c U too high and risk running out of re- hostname or IP address of your server. [path_to_configuration]U sources on your server. Icecast uses this value to create the url /icecast.xml & Queue-size is the maximum value in for playlists and for listing under YP di- bytes to allocate for each client queue. rectories. YP stands for yellow pages. /usr/local/bin/icecast -c U The queue accounts for lags that may Remember that Icecast must be com- /usr/local/etc/icecast.xml occur due to bandwidth issues or net- piled with curl support in order to make work interruptions. The Icecast server use of YP posting. Xiph.org hosts a YP If you have set the fileserve element to 1, maintains a separate queue for each directory for Icecast streams. To get your you can quickly test your server by copy- user. Should the amount of data in the stream listed under the Icecast YP direc- ing an .ogg file to the webroot directory queue exceed the maximum queue-size tories, consult the Icecast documentation and connecting to your Icecast server value, the client will be disconnected or the comments in the default configu- with a media player running on a sepa- from the stream. ration file supplied by the Icecast rate system. For instance, using , sources. The three timeout values: Client-timeout, simply choose a play location and enter header-timeout, and source-timeout The listen-socket sets the port from the following URL: should be left at their default values. Ac- which the Icecast server will accept both cording to the Icecast documentation, cli- source and client connections. Although http://[url or ip of server]:U ent-timeout is not used. Header-timeout you can use any port number above 8000/yourfile.ogg refers to the interval between the client’s 1024, most Icecast servers typically run initial connection and the request for on ports between 8000 and 8010. Unless http://myhost.org:U content. The source-timeout indicates you absolutely have to change this, 8000/hellow.ogg how long to wait when the source con- leave the value at 8000. Clients will re- nection is terminated before dropping quire the port number when attempting The Icecast documentation recommends the source connection and that mount- to connect to your server. including the .ogg extension for any ogg

36 ISSUE 66 MAY 2006 WWW.LINUX - MAGAZINE.COM Streaming with Icecast COVER STORY

easiest way to get up and run- ning with MuSE is to download and boot Dynebolic. Inciden- tally, Dynebolic includes an Icecast server and the capabil- ity of easily editing the configu- ration file. If you choose to try out Dynebolic for the server and source client, you must use two separate systems. You can- not attach MuSE to an Icecast server running on the same Figure 1: The MuSE channel window with two system. files queued. The MuSE source code is available from the Dyne.org stream mount-point or .ogg files. Some website, along with packages media players may not properly process for Slackware, Debian, Redhat, the stream as an .ogg file unless the ex- and OS X.. To compile MuSE tension is specified. from source with a graphical Figure 2: Fill in your Icecast server information and client, you will need GTK+, begin streaming! Adding a Source Client along with the libxml and glib Now that the Icecast server is running, it developmental libraries. MuSE port for uncompressed sound files re- is time to connect some external sources. has an ncurses frontend (which requires quires that libsndfile be present. A number of source client programs can that you install ncurses [9]) and can also Be careful not to confuse Dyne.org’s send a source stream to an Icecast be run as a command line application. MuSE application with the MusE MIDI/ server. The Icecast team offers Ices. Ices Installing Lame is recommended for mp3 Audio sequencer project.(http:// www. is a command line utility that is config- streaming support. MuSE can also muse-sequencer. org). Make sure you do ured using an XML file. The Ices source stream ogg-vorbis if the ogg and vorbis not have MusE installed or you know documentation contains example config- libraries are installed. Additionally, sup- that installing MuSE will not overwrite uration files. (If you are installing Ices any of the MusE files. Given that possi- from a package, you should be able to Icecast Relays bility, if you have the MusE MIDI/ Audio find these files in the package’s doc or sequencer, you may want to configure If your stream become so popular that share directory.) Copy the desired con- MuSE to install into it’s own directory you begin to run up against bandwidth figuration file to your home directory, structure: limitations, you may want to add a relay and make the necessary edits. It is espe- server. Icecast offers two kinds of relays: cially important to input module and ./configure -prefix=/opt/MuSE Master-Slave and Single-Broadcast. A server details. When you have made the Master-Slave relay mirrors all the con- necessary changes to the configuration Once installed, simply start MuSE with figured mount points on the master file, you can ices: the command: muse. The main MuSE server to the slave server. Setting a window (Figure 1) will appear with six mount point is critical if you plan on ices configfile.xml buttons across the top, a control bar, and having any relays, particularly if you a channel window. You can cue up have an Icecast slave mirroring all The configuration of Ices is pretty de- media files in the channel by right-click- mount points. The mount settings in tailed; be sure to read the documenta- ing in the window. You can add more Listing 1 show a simple mount point tion carefully. channels by pressing the second button with no further parameters. The mount at the top. To remove channels, click the uses the default values and those values MuSE as Source X icon in the lower left corner. Figure 1 specified in the other sections of the If you want to get up and running displays one channel in MuSE with two configuration file. Mounts can accept a quickly with a graphical source client, media files queued. To the left of the number of parameters, including spe- check out MuSE from Dyne.org [7]. channel window is a volume slider that cific source passwords, a fallback source MuSE is a multiple streaming engine that makes it easy to reduce the volume of a (should the original source be unavail- is part of Dyne’s live multimedia Linux media file, allowing you to voice over. able), limits, intro audio files, and more. distribution called Dynebolic [8]. The Below the channel window is the option COVER STORY Streaming with Icecast

automatically be created. The Name, URL, and Description are optional. De- pending on how the server is set up, this information may not appear to the cli- ents. Finally, select Icecast2 for Login Type and enter the source password from the server. Click the connect button and you should be streaming. MuSE offers additional audio options in the “Let’s Stream” window. You can adjust the quality of the audio, bitrate, and frequency among other settings. Chances are, for voice, the defaults will be adequate. Be aware that raising any of these values will consume more band- width per client. You can also record what you are streaming for archival purposes. Simply browse to the directory you want to save the stream to, enter a file name. and hit OK. When you are ready to begin your Figure 3: The general information page of the Icecast web interface displays information session, press the record button. Should about the mount-points and allows clients to easily connect. you have an existing file of the same name in that directory, the new file will to single play the files in the channel, to Before you can send the stream to the have a # appended to it, where # is the loop a specific file repeatedly, or to play server, you must fill in the server infor- next incremental value. the list continuously. If you were per- mation in the bottom-third of the win- forming live and wanted background dow. For Host, enter in the url (without Icecast Web Administration music, you would queue up the audio the http://) or the IP address of the Once Icecast server is up and streaming, file and select the loop option, then ad- streaming server and verify that the port you can visit the information and admin just the volume accordingly. is correct. If there is no specific mount pages of the server through your chosen In addition to files, you can queue up point defined for you on the server, you web browser. Enter the url or IP address other streams. The order of the queued can put any mount point in and it will of the streaming server, followed by the media can be adjusted by drag-and-drop in the list, and queued files can be de- leted by highlighting and choosing de- lete from the right-click menu. The microphone (third) and speaker (fourth) buttons toggle the audio input source. Both buttons can be active at the same time. By default, only the speaker button is active, which means only the media playing in the queue will be streamed to the server. Pressing the mi- crophone will stream audio from the line-in on your audio card. The fifth but- ton, vumeter, provides a graphical vol- ume meter so you can keep an eye on your levels. Once you are set up with what you want to stream, the first button, “Let’s Stream,” will take you to the streaming server configuration window (Figure 2). Muse can send out mp3 and/ or ogg-vor- bis streams. You can add additional serv- ers to each session by clicking the “Add Server” option at the top of the window and choosing either a Lame (mp3) or Figure 4: Administration is easy with the Icecast web interface. Use the Global Server Stats ogg stream. page to check the current status of the server.

38 ISSUE 66 MAY 2006 WWW.LINUX - MAGAZINE.COM Streaming with Icecast COVER STORY

port the Icecast server is streaming on, way to creating your own web radio sta- INFO to reach the Icecast Status page (Figure tion. Before you really take off, though, 3). All the mount points currently served make sure you consult your ISP’s terms [1] Darwin server: by Icecast will be accessible via this of service or your campus network http:// developer. apple. com/ darwin page, along with some basic statistics. agreement. Operating a streaming server [2] Helix server: http:// helix-server. Clients can click on the link to listen in may violate your contract and jeopardize helixcommunity. org/ their preferred media player. your service. [3] Icecast: http:// www. icecast. org Access to the Adminstrative web pages Running your own web radio server [4] Xiph.org: http:// www. xiph. org/ is also available. Clicking on this link can be tremendously entertaining and [5] Ezstream – Client that will stream will require authentication using the educational. Be sure, however, that you Theora videos: streaming server admin username and are aware of any applicable copyright http:// www. ezstream. com/ password. One can also access the ad- laws for your locality. [6] Lame: http:// lame. sourceforge. net/ ministrative pages by typing in the direct The exact rules for what you can and index. html URL (e.g.; http://myhost.org:8000/ can’t stream may depend on the laws of [7] MuSE – Multiple Streaming Engine: admin). your country. Should you wish to stream http:// muse. dyne. org The administrative interface will allow music, you might want to look for audio [8] Dynebolic Live Multimedia Distribu- you to perform such tasks as listing the released under a creative commons li- tion: http:// www. dynebolic. org clients connected to a source, moving cense that permits re-streaming for non- [9] ncurses: http:// www. gnu. org/ clients to a different mount point, or commercial use. software/ ncurses/ ncurses. html even killing a source. You can also view Check out music services like Magna- [10] --free, music store: http:// pertinent Icecast server statistics (see tune [10] for streamable media, and www. magnatune. com Figure 4). make sure you always credit the original [11] Ogg Vorbis: http:// www. vorbis. com/ artist. If, at any time, you have doubts Conclusions about whether you have permission to [12] Theora.org: http://www.theora.org/ Within a few minutes of installing and stream any content, err on the side of [13] Wikipedia on : configuring the Icecast open source caution. http://en.wikipedia.org/wiki/ streaming server, you will be on your Most of all, have fun! ■ Streaming_media