Shoutcast
Author: jason
Date: 2003-11-23
Category: Technical

Now you want to stream those MP3s you've worked so hard at downloading... Everyone needs to hear them!!

Go to: http://www.shoutcast.com and read the non-informative documentation. Root around for the download files.

FreeBSD: http://www.shoutcast.com/downloads/sc1-9-2/shoutcast-1-9-2-freebsd4-elf.tar.gz
Linux: http://www.shoutcast.com/downloads/sc1-9-2/shoutcast-1-9-2-linux-glibc6.tar.gz

And (for both): http://www.shoutcast.com/downloads/sc_trans_posix_040.tgz

Shoutcast consists of two parts: sc_serv and sc_trans.

sc_serv ss the SHOUTcast Distributed Network Audio Server (DNAS). The DNAS is responsible for accepting a broadcast feed from Winamp and the SHOUTcast Source DSP plug-in, and repeating the broadcast to listeners connected to this SHOUTcast DNAS. Once your source content is being fed into the SHOUTcast DNAS, it will also, dependent on the source content's configuration, list itself with the SHOUTcast directory so listeners can locate your broadcast. The DNAS also has the ability to deliver on-demand content in MP3 format stored in the content/ directory.

sc_trans is the SHOUTcast Source DSP plug-in. sc_trans operates in one of two modes, either reading mp3s off disk, decoding, re-encoding, and then broadcasting them, or relaying from a shoutcast server, transcoding to a lower bitrate, and broadcasting to a new server.

Listeners connect to sc_serv. sc_trans gives music/content to sc_serv.

Install!! We'll go out of the home directory...

>su
>cd /home
>tar -zxvf shoutcast-1-9-2-freebsd4-elf.tar.gz
* or shoutcast-1-9-2-linux-glibc6.tar.gz for linux *
>tar -zxvf sc_trans_posix_040.tgz
>mkdir /usr/local/bin/shoutcst
>chown YOURUSER /usr/local/bin/shoutcast
>cd shoutcast-1-9-2-freebsd4-elf
* or shoutcast-1-9-2-linux-glibc6 for linux *
>cp -R * /usr/local/bin/shoutcast
>cd ../sc_trans_posix_040
>cp * /usr/local/bin/shoutcast
>cd /usr/local/bin/shoutcast
>ls -ail

You should see:
Code

total 2576
1099 drwxr-xr-x 3 jason wheel 512 Nov 23 12:55 .
389380 drwxr-xr-x 5 root wheel 4608 Nov 23 12:54 ..
2094 -rw-r--r-- 1 root wheel 22553 Nov 23 12:54 README
2095 drwxr-xr-x 2 root wheel 512 Nov 23 12:54 content
2101 -rw-r--r-- 1 root wheel 1120 Nov 23 12:55 example.lst
2093 -rwxr-xr-x 1 root wheel 123192 Nov 23 12:54 sc_serv
2086 -rw-r--r-- 1 root wheel 14071 Nov 23 12:54 sc_serv.conf
2100 -rw-r--r-- 1 root wheel 2053 Nov 23 12:55 sc_trans.conf
2099 -rwxr-xr-x 1 root wheel 799804 Nov 23 12:55 sc_trans_freebsd
2098 -rwxr-xr-x 1 root wheel 799828 Nov 23 12:55 sc_trans_linux
2097 -rwxr-xr-x 1 root wheel 790416 Nov 23 12:55 sc_trans_macosx


You now have to configure your sc_serv.conf and your sc_trans.conf.

>vi sc_serv.conf

Things you need to change:
Code

; Just pick a crummy one, you'll need it for the sc_trans.conf though
Password=changeme

; In case yo have something else on this port (SAMBA?) you might want to change it. You'll update it in sc_trans.conf too.
PortBase=8000

; Change this to never !!
PublicServer=default

; Change this to no !!
AllowRelay=Yes

; Change this to no !!
AllowPublicRelay=Yes


The public server and relaying let other people use your signal, list you on the internet in shoutcast's forum, and stuff... You don't need them to broadcast on the internet or to friends. By now you should know to hit Insert to type in vi, hit escape to get out of edit so you can write and quit with :wq!.

Now sc_trans.conf:
>vi sc_trans.conf

Things to change:
Code

; Specifies the mp3s you want to play, more on this later
PlaylistFile=mymusic.lst

; Your server's IP, and the port you choose in sc_serv ServerIP=123.123.123.123
ServerPort=8000

; The password from sc_serv.conf
Password=yourpassword

; You may want to change these :)
StreamTitle=My Gay Son <
StreamURL=http://mygayson.com
Genre=genres go here

; Shuffle the playlist,if you don't want to use 0
Shuffle=1


You can also play with the bitrates and samplerates. I would recommend not doing that. I did, and it didn't save me much. For the default bit rate of 80000 you are streaming less then 10KB of info!!

Now you need to make a play list. This is easy:
>find /path/to/yourmp3s -type f -name "*.mp3" > mymusic.lst

Make sure your playlist name is the same in the sc_trans.conf file! You can cat mymusic.lst to make sure it picked up your mp3s. If not, check out the path to make sure it's right.

Got those taken care of? Now you can start shoutcast.
>./sc_serv sc_serv.conf &
>./sc_trans_freebsd sc_trans.conf &
* or sc_trans_linux for linux*

You need to tell sc_serv and sc_trans what configs to use. And the & tells the program to let you keep using the shell, instead of hogging the screen.

When you issue sc_serv you should see:

*******************************************************************************
** SHOUTcast Distributed Network Audio Server
** Copyright (C) 1998-2000 Nullsoft, Inc. All Rights Reserved
** Use "sc_serv filename.ini" to specify an ini file.
*******************************************************************************

When you issue sc_trans_freebsd (or _linux) you should see:

*******************************************************************************
** TRANScast Distributed Network Audio Content Provider
** Copyright (C) 2000 Nullsoft, Inc. All Rights Reserved.
** Use "sc_trans filename.conf" to specify a config file.
*******************************************************************************
<11/23/03@13:18:08> [TRANSCast] DNAS/posix v0.400-LAME (Mar 4 2003) starting up...
<11/23/03@13:18:08> [MAIN] PID: 336
<11/23/03@13:18:08> [MAIN] Loaded config from sc_trans_alternative.conf
<11/23/03@13:18:08> [MAIN] Loading playlist (alternative.lst)
<11/23/03@13:18:08> [MAIN] Found (142) entries in playlist
<11/23/03@13:18:08> [MAIN] Playlist decoder thread starting
<11/23/03@13:18:08> [MAIN] Streaming thread starting
<11/23/03@13:18:08> [DECODE] Opened Filter - Welcome To The Fold.mp3
<11/23/03@13:18:09> [CONFIG] WARNING: No InputSamplerate defined, assuming 44100!
<11/23/03@13:18:09> [CONFIG] WARNING: No InputChannels defined, assuming 2!
<11/23/03@13:18:09> [STREAM] Creating stream socket
<11/23/03@13:18:09> [STREAM] Connected to host server
<11/23/03@13:18:09> [STREAM] Host server gave success (OK2)
<11/23/03@13:18:09> [STREAM] Stream to 10.10.10.101 established
<11/23/03@13:18:09> [STREAM] Sending stream information
<11/23/03@13:18:11> [MAIN] Title Updated

If you see errors and a lot of reconnects then you need to check your IP address and port settings. Since this is sending local to itself, you should use the local IP.

You should be able to connect to your server via http on the port you specifed: http:/ /yourip:8000 And see a black window with:

Server Status: Server is currently up and private.
Stream Status: Stream is up at 80 kbps with 0 of 32 listeners (0 unique)
Listener Peak: 0
Average Listen Time: 0m 01s
Stream Title: jtf.org: alternative
Content Type: audio/mpeg
Stream Genre: alternative
Stream URL: http://music.jasonthomasfrance.org/music.php
Stream ICQ:
Stream AIM: AIMHandle
Stream IRC: shoutcast
Current Song: Filter - Welcome To The Fold

You should also be able to connect to your shoutcast server with windows media player, winamp, or xmms. Just look for a Open URL (or location) and type: http:/ /yourip:8000 And you should be listening to your MP3s!!

For a script you can use this to automate the starting and stopping of shoutcast:
Code

#!/bin/sh

case "$1" in

start)
/bin/mkdir -p /var/run/sc_start
if [ -x /usr/local/bin/shoutcast ]; then
cd /usr/local/bin/shoutcast
./sc_serv sc_serv.conf &
./sc_trans_freebsd sc_trans_alternative.conf &
echo -n ' shoutcast'
fi
;;

stop)
killall sc_serv
killall sc_trans_freebsd
;;
*)
echo "$0 start | stop"
;;

esac


You can also run multiple shoutcasts by specifying different configs:
>./sc_serv alternative.conf &
>./sc_trans_freebsd sc_trans_alternative.conf &
>./sc_serv trance.conf
>./sc_trans_freebsd sc_trans_trace.conf &

Just remember to change the ports. For alternative if you use 8000, then use 8050 for trance, or something... Change the ports in both configs!!

Shoutcast builds the webpage with XML and you can call the different parts with PHP. Here's a snippet:
Code

// Fill in your own server information here:
$host = "YOURIP";
$port = "8000";
$listenlink = 'http://YOURIP:8000/listen.pls'; //make link to stream

$fp = fsockopen("$host", $port, &$errno, &$errstr, 30); //open connection
if(!$fp) {
$success=2; //se-t if no connection
}
if($success!=2){ //if connection
fputs($fp,"GET /7.html HTTP/1.0\r\nUser-Agent: XML Getter (Mozilla Compatible)\r\n\r\n"); //get 7.html
while(!feof($fp)) {
$page .= fgets($fp, 1000);
}
fclose($fp); //close connection
$page = ereg_replace(".*", "", $page); //extract data
$page = ereg_replace(".*", ",", $page); //extract data
$numbers = explode(",",$page); //extract data
$currentlisteners=$numbers[0]; //set variable
$connected=$numbers[1]; //set variable

if($connected==1) //if DSP is connected
$wordconnected="yes"; //set variable
else //if no DSP connection
$wordconnected="no"; //set variable
$peaklisteners=$numbers[2]; //set variable
$maxlisteners=$numbers[3]; //set variable
$reportedlisteners=$numbers[4]; //set variable
}

if($success!=2 && $connected==1){

// song information is splitted in artist - title:
// This requires consistent artist & title format (no ' - ' in title/artist)
// else you can use $numbers[6] as current song info below
$song=explode(" - ",$numbers[6]);

// strings can of course be replaced with your own bla
$string1= "Now playing on YOURIP:8000 ::: ";
$string2= $song[0];
$string3= $song[1];
$string4= $song[2];
$string5= "[$currentlisteners/$maxlisteners users]";
}
else {
$string1= "The music station is";
$string2= "OFFLINE. ";
$string3= "Please return later. ";
$string4= " ";
$string5= " ";
}

echo $string1;
echo $string2. " ";
echo $string3. " ";
echo $string4. " ";
echo $string5. " ";
?>


Call the file whatever.php and place it in your apache html directory.

Now you're a Shoutcast geek!!

*********
written by jasonthomasfrance
date 23 Nov 2003
systems RedHat 9.0, FreeBSD 4.8
*********



jason @ jasonthomasfrance.com - www.masterstationlog.com - copyright 2009