YoLinux: Linux Audio Streaming

This tutorial covers the set-up of an MP3 audio streaming server. Once configured, you will be an internet radio station broadcasting to anyone in the world willing to listen. Uncompressed CD-quality WAV and AIFF files are too large to stream over the Internet, thus formats which support compression and reduced data such as Real Audio and MP3 are used.
Four options are available for the Linux platform:

The option of using Real Networks "Real Audio" software is probably the most popular commercial solution and is proven but it uses a proprietary format and costs money. Real Audio has the benifit that it adapts to a clients bandwidth. MP3 uses a proprietary format but has wide client support. (MP3 format is patented and licensed by Fraunhofer IIS-A). OggVorbis is a competing compressed audio file format with a non-proprietary format and is gaining in popularity. It does not yet have the wide support of audio clients.

The O'Reily tutorial on streaming audio Part 1 and Part 2 by Dave Philips is a good overview of streaming audio technology. It leaves out many technical details (That's why I wrote this piece) but it is has a good overall view.

Also see the YoLinux tutorial on generating MP3 files on Linux.

Related YoLinux Tutorials:

°Linux Networking

°Linux Sys Admin

°Internet Security

°Security Tools

°Web site configuration

°Web Tricks

°YoLinux Tutorials Index




Free Information Technology Magazines and Document Downloads
TradePub link image


   

    Bookmark and Share


Advertisements




Audio Streaming Server Set-Up Using IceCast 1:

This tutorial outlines the installation and set-up of an Icecast MP3 audio streaming server using the binary Linux RPM from icecast.org. Icecast comes with an http server built in. Icecast can use this if staticdir directive is incuded in the configuration file or icecast will use an existing server such as Apache or Netscape. This example will employ the http server within Icecast.

Note on using Linux RPM's: The configuration I used was the icecast 1.3.10 server from the RPM downloaded from icecast.org and the shout module supplied by the Red Hat RPM.

The icecast.org icecast-1.3.10 RPM did not include the shout module. The Red Hat powertools icecast RPM included shout but in other ways the RPM was horribly incomplete (No templates or configuration file.) and thus the icecast server it shipped with was unuseable. The configuration file detailed below is intended for the icecast 1.3.10 server and does NOT work with the Red Hat RPM (icecast-1.3.op2). Bottom line: I had to install both RPM's to get a complete set of tools. Amazingly enough there were no RPM conflicts and both installed without hassle.

Icecast Setup:

  • Download:
    • RPMs:
      • The prefered RPM for the icecast server can be found at http://www.icecast.org/download.php - RPM download (Install with the "rpm -ivh" command)
        After installation, the icecast manual will then be found in /usr/share/doc/icecast-1.3.10/manual.html. This is the best source for configuration information. Runtime icecast html templates can be found in /usr/share/icecast/templates/.
        Binary: /usr/sbin/icecast
        Configuration files: /etc/icecast/icecast.conf
        Log Files: /var/log/icecast/...
        This RPM did not include shout. Download and compile the source or use the Red Hat powertools version of shout.

      • Another RPM version of icecast is available on the Red Hat Powertools CD (or download site) (RPM Dependency: "perl-Time-HiRes" Powertools RPM)
        Documentation for Red Hat 7.1 is found in /usr/doc/icecast-1.3.0p2/.
        Binaries:
        • /usr/bin/icecast
        • /usr/bin/shout: Streams MP3 files to the icecast server. A perl equivalent, "iceplay" is also included.
        • /usr/bin/listen: Listen to streaming audio.
        • /usr/bin/liveiceconfigure.tk: Tcl GUI configuration tool for Liveice.
        Default configuration file location: /etc/icecast.conf (not included)

        OR

    • Compile from source obtained from IceCast.org/download.php.
      • ICECAST:
        • Note: If installing a source RPM, the install (rpm -ivh) will place icecast-1.x.x.tar.gz in /usr/src/redhat/SOURCES/
        • tar zxvf icecast-1.x.x.tar.gz -C /tmp
        • cd /tmp/icecast-1.x.x/
        • ./configure - View options: ./configure --help
        • Note: Red Hat 6.x places documentation in /usr/doc/program-name/
          Red Hat 7.1 places documentation in /usr/share/doc/program-name/
          To follow this convention on 7.1 I made the following changes to Makefile:
          ICECAST_DOCDIR=/usr/doc/icecast-${ICECAST_VERSION_SMALL}
          Changed to:
          ICECAST_DOCDIR=/usr/share/doc/icecast-${ICECAST_VERSION_SMALL}
        • ./configure --sysconfdir=/etc/icecast --prefix=/usr --exec-prefix=/usr --datadir=/usr/share --enable-fsstd --with-libwrap
        • make
        • make install
      • SHOUT:
        • tar zxvf shout-1.x.x.tar.gz -C /tmp
        • cd /tmp/shout-x.x/
        • ./configure --sysconfdir=/etc/icecast --prefix=/usr --exec-prefix=/usr --enable-fsstd
        • make
        • make install

  • Configuration file: /etc/icecast/icecast.conf
    location Music from the University of Linux   - Server and location of Streaming Station - Display only
    rp_email webmaster@your-domain.com            - State contact info
    server_url http://www.your-domain.com         - URL of the web page corresponding to the music
    
    # Set Limits
    max_clients  300                              - Max simultaneous clients connected to the server.
    max_clients_per_source  20
    client_password not_used                      - This feature has not been implemented yet
    throttle 10.0
    
    encoder_password mypassword                   - Clear text password by which the server accepts encoders
    admin_password mypassword                     - Required to use admin console
    oper_password mypassword                      - For access to server operator commands
    
    port 8000
    port 8001                                     - +1 for shoutcast compatability.
    server_name node.your-domain.com                - Not required. Used when virtual hosting multiple URL's with the icecast server.
    logdir   /var/log/icecast
    logfile  icecast.log                          - Log file in directory /var/log/icecast/
    console_mode  3                               - Run icecast server in the background, as a daemon process.
    client_timeout 30
    staticdir /home/MP3                           - Turns on http server capabilities of Icecast and sets root directory for content.
                        

    Sample files: icecast conf

  • M3U playlist file: playlist_01.m3u
    /home/MP3/classical/Beetovan1.mp3
    /home/MP3/classical/Bach1.mp3
    /home/MP3/rock/RollingStones1.mp3
    Use fully qualified path names.

  • Start icecast: /usr/sbin/icecast

  • Start shout: /usr/bin/shout localhost -P mypassword -a -x -p /directory-name/playlist_01.m3u -l -u "http://node.your-domain.com:8000" -z
    For a full list of options: shout -h
    Red Hat RPM binary logs to: /tmp/shout/shout.log

  • Test: xmms http://node.your-domain.com:8000

  • View icecast server statistics: http://node.your-domain.com:8000/list.cgi

  • Try the web based administration interface: http://node.your-domain.com:8000/admin


Using TCP wrappers:

  • File: /etc/hosts.deny
        icecast: ALL
    or use nothing at all to allow everyone.

  • File: /etc/hosts.allow
        icecast: 192.168.10.                          - Allow from 192.168.10.* network addresses
                  
    OR
        icecast: ALL                                  - Allow all to listen
                    


More Icecast Info:

  • People typically use 128 kbps compression mono MP3 files. (Sample rate: 44100 Hz)
  • Icecast uses TCP port 8000
    [Potential Pitfall]: Many corporate firewalls block everything except port 80. Many of the large MP3 streaming stations such as live365.com have changed all their servers to stream over port 80 to avoid problems.
  • The streaming protocol used is called the shoutcast protocol.
  • Header type: application/x-audio
  • Icecast has a web interface for administration which is good for viewing the status of the icecast server but useless at making changes. (That part is broken.)
  • Remote administration can be performed in console mode:
    • telnet node.your-domain.com 8000
    • Enter: ADMIN password then Enter + Enter (carraige return twice)
    • Switch to operator status: oper operator-password
    • Get list of commands: help
  • You can list your server with a directory server to gain exposure and more listeners.
    List of directory servers:
    • yp.shoutcast.com
    • yp.breakfree.com
    • yp.musicseek.net
    • yp.van-pelt.com
    • yp.radiostation.de
    • yp.mp3.de
    Point your browser at: http://dir.xiph.org/ to take a peek of the directory listings.
  • Icecast can run as a relay thus adding scalability by adding more servers. Use the "alias" directive to employ this capability.
  • Icecast can support access control lists (ACL) using "deny" and "allow" directives.
  • There are NO man pages.


Icecast configuration file directives for /etc/icecast/icecast.conf

Directive Description
icydir yp.shoutcast.com Directive for old directories.
directory yp.shoutcast.org Directive for new directories. Icecast 1.3+
Default port: 80
touch_freq integer How often the directory servers get 'touched' by the icecast server.
Default: 5 minutes
max_admins integer Max. number of simultaneous connected admins.
console_mode integer 0: admin console
1: same as 0 but without logfile info
2: Use as logfile window
3: Run icecast as a daemon process.
reverse_lookups integer 0: Turns off reverse lookups of IP addresses.
1: Reverse lookup all ips to hostnames.
acl_policy integer 0: Deny connections if no rule is given.
1: Allow connections by default if no rule is given.
logfiledebuglevel integer Debugging messages output to log file:
0: No debigging output
1: more
2: Even more output
...
..
6: Max debugging output
consoledebuglevel integer Debugging messages output to console:
0: No debigging output
1: more
2: Even more output
...
..
6: Max debugging output
streamtitletemplate string Template for stream title sent to client and directory servers. The symbol "%s" will be replaced with the filename of the current song.
accessfile file-name Access logging which can be parsed by Apache log file parsers.
templatedir directory-name HTML templates.
/usr/share/icecast/templates/
http_admin integer 0: No www admin access
1: Allow www admin access
include file-to-be-included Include the contents of another include file.
alias /directory-1 /directory-2 Server mount points set as the same logically.
mount_fallback integer 0: Send message "HTTP 404 Stream Not Found" if not found.
1: Send default stream if not found.

For more information and a full list of directives see the icecast manual.
See: http://node.your-domain.com:8000/admin?mode=help


Icecast command line directives:

Useage: icecast [options]

Directive Description
-c configuration-file Command line parameters overide configuration file directives.
Default: /etc/icecast/icecast.conf
-P port-number Used for all client, source, and admin connections.
Default: 8000
-m max-clients If exceeded, icecast will issue the error: 'HTTP/1.0 504 Server Full'
-p encoder-password Password used to deliver stream to server.
-b Run in background as a daemon process.
-d directory Configuration files.
i.e.: /etc/icecast
-V Full debugging.


Shout configuration file directives for /etc/icecast/shout.conf:

Format: option value or option bool
where bool is yes/no, on/off or 1/0.

Directive Description
port 8000 Same port as configured in icecast.conf.
Default: 8000
server_name localhost Name of server.
password password Same as defined in the icecast.conf as the encoder password.
mount default Mount point for this stream/channel. (Other examples: rock, rap, etc)
Default: default
name name Name of this stream.
Default: Icecast Radio
desc text A description of the channel.
url URL Web address associated with this stream.
public bool If you want this published on a yp server lookup list.
Supported only if the icecast server has yp touch enabled.
genre genre talk, rock, rap, alt, techno...
Default: misc
playlist file Fully qualified file names to play.
loop bool true: Endless playing loop.
shuffle bool true: Shuffle playlist entries.
autodetect bool Check the file for bitrate info, before trying to stream it. If no, it will be sent at the default bitrate.
default_bitrate 128000 If different than file and autodetect is off, you get a mess.
force bool on: If file does not match the default_bitrate, skip file.
truncate bool .
update bool .
usedj bool .
djprogram file Program/script to run before every song.
usecuefile bool .
short_titles bool Trim path names from file names when using non ID3 data for stream title info.
title_streaming bool Turns title updates on or off.
id3 bool Use id3 tags for title streaming.
Requires: title_streaming yes
autocorrect bool Adapt the stream calculations to match each file's bitrate.
daemon bool yes: launched in the background.
verbose bool yes: Extra text output.

Download source and see file shout.h for full list of directives and the defaults.

Sample: shout.conf

# Comments are valid

server_name localhost
port 8000
password mypassword mount default name Radio_Linux desc The_best_linux_music genre Music url http://www.your-domain.com/

public yes

short_titles yes
title_streaming yes
id3 no
autocorrect yes

playlist shout.playlist_01
loop yes
shuffle no

autodetect yes
default_bitrate 128000
force no

daemon no
verbose no

Signals:

  • SIGINT: makes shout skip to the next song.
  • SIGUSR1: makes shout reshuffle the internal playlist.
  • SIGHUP: makes shout re-read its configuration file.

You may run multiple instances of shout, one for each channel. i.e. http://localhost:8000/rock, http://localhost:8000/rap, etc... using rock and rap etc as the different mount points.


Shout command line directives:

Useage: shout host-name [options]

Directive Description
-B directory-name Base/root for all of shout's files.
Default: /tmp
-C configuration-file Specify a configuration file.
-D DJ-file Run this before every song.
-P password Specify encoder password.
Must match that specified in /etc/icecast.conf
-S Display all settings and exit.
-V Use verbose output.
-X description Use specified description.
-a Turn on automatic bitrate (transfer) correction.
-l Go on forever. Loop through playlist endlessly.
-p playlist-file Use specified file as a playlist.
-u URL Use specified url
-v Show version.
-z Go into the background (Daemon mode)
-t Enable title streaming

To view all directives use the command shout -h.


MP3 MIME Types:

MIME type Extension Description
audio/x-scpls pls Used by shoutcast.com for their MP3 streams
audio/mpegurl m3u Used by icecast.org for their MP3 streams
audio/x-mpegurl m3u Used by mp3.com for their MP3 streams
audio/mpeg mp3
audio/x-mpeg mp3
audio/mp3 mp3
audio/x-mp3 mp3

Testing with the Xmms client:

  • Attaching xmms to a streaming server:
    • xmms http://localhost:8000
      or
    • xmms http://216.226.139.62:8016 - Clasical
      or
    • xmms http://netrock.inyc.com:8045 - Rock
      or
    • xmms http://www.live365.com/play/26395 - Heavy Rock

    ctrl-L will allow you to enter a new URL.

Testing with the FreeAmp client:

  • Attaching FreeAmp to a streaming server:
    • freeamp http://216.226.139.62:8016

MP3 Streaming Stations: See http://www.live365.com


Links:

Clients:

Directories of MP3 Streaming Stations: (pick one and listen)

Audio Streaming Servers:

  • IceCast.org - Open Source MP3 and OggVorbis Streaming Server
  • Shoutcast.com - Commercial MP3 Audio streaming
  • DarkIce - Live streamer - Takes live input from a soundcard, encodes it and sends the encoded stream to an IceCast server. DarkIce uses an external mp3 encoder.
  • AmpJuke - Web based. Uses Apache, MySQL and PHP. AmpJuke streams music files to one or more clients using the HTTP-protocol. Scanning and import of music stored in the MP3, OGG, WMA and/or APE format.
  • Ampache - Web-based Audio file manager. Implemented with MySQL, and PHP. It allows you to view, edit, and play your audio files via the web. Supports playlists, artist and album views, album art, random play, playback via Http/On the Fly Transcoding and Downsampling.
  • kPlaylist.net - PHP interface to a streaming web site (ogg, mp3, wav, ...) Allows upload, creation of playlists, share, search and download.
  • Agatha - Stream music and playlists
  • Edna - MP3 streaming
  • Fluid - MP3 streaming server written in JAVA
  • Streamcast - Supports ID3 tags, mountpoints. The PHP-stream version is a database enabled version of streamcast.
  • netjukebox - Web based Winamp/httpQ media jukebox.

Stream encoders:

  • Comparason of MP3 encoders on Linux
  • Shout - MP3 stream encoder from the icecast site
  • LiveIce - Provide "Real Time" streams for icecast.
  • MuSE - Desktop GUI application for the mixing, encoding, and network streaming of sound. Can use 6 encoded audio bitstreams (from files or network) plus a souncard input signal to be played locally or encoded for broadcast. Also hadles Ogg Vorbis.

Support tools:

Ogg Vorbis Encoders:

Other Links:

Copyright © 2000, 2001, 2002 by Greg Ippolito