If your station DJs only have the ability to broadcast in OGG/Vorbis but your listeners listen mainly in MP3 via shoutcast (for example, Traktor can only broadcast in OGG), this howto guide is for you as it shows how to seamlessly integrate and transcode an Ogg (icecast) broadcast to a shoutcast (mp3) broadcast using some off the shelf, free technology. The way the system works is using the feature in icecast to call programs when a source connects or disconnects. These scripts then invoke (or terminate) a custom perl program which uses ogg123 to receive the ogg stream from the icecast server, pipes it into the lame program to convert to MP3 and then uses the libshout bindings to send the stream to the Shoutcast MP3 server. While this will work with any linux distribution, in this howto I use the Ubuntu and Debian ‘apt-get’ system to install the various required components. If you use a different distribution you should substitute any apt-get commands with your distribution specific package manager (or build from source if you are into punishment).
Requirements:
- 1x Linux server
- 1x Shoutcast server installed and running
- 1x Icecast server installed and running
- Perl
- libshout (inc dev files)
- vorbis-tools (specifically the ogg123 binary)
- lame
- oggtoshout.pl
In debian or ubuntu, vorbis-tools and lame can be installed using apt-get (Note that in Ubuntu versions prior to 9.04 you will need to enable the ‘multiverse’ repository in /etc/apt.sources.list to install lame). We also need the libshout libraries, dev libraries and pkg-config program to install the Xiph perl shoutcast libraries
Installation
sudo apt-get install lame vorbis-tools pkg-config libshout3 libshout3-dev
You should also install the perl shout bindings from xiph.org
wget http://downloads.us.xiph.org/releases/libshout/Shout-2.1.tar.gz tar -zxvf Shout-2.1.tar.gz cd Shout-2.1 perl Makefile.PL make sudo make install
Now we download and install the oggtoshout package
sudo su - cd /usr/share/icecast wget http://iwtf.net/wp-content/uploads/2010/01/oggtoshout.tar.gz tar -zxvf oggtoshout.tar.gz chmod 777 oggtoshout.pl start.sh stop.sh
Configuration
Icecast needs to have a new mountpoint configured where your OGG sources(DJ’s) will connect to. This mountpoint should call the ‘start.sh’ and ‘stop.sh’ scripts obtained in the oggtoshout.tar.gz package. Here is an example of the relevant ‘mount’ section within my /etc/icecast2/icecast.xml configuration:
<mount>
<mount-name>/trans.ogg</mount-name>
<password>somepassword</password>
<max-listeners>5</max-listeners>
<burst-size>128</burst-size>
<no-yp>1</no-yp>
<on-connect>/usr/share/icecast2/startogg.sh</on-connect>
<on-disconnect>/usr/share/icecast2/stopogg.sh</on-disconnect>
</mount>
You would give the source (DJ) the password ‘somepassword’ and mountpoint ‘trans.ogg,’ along with the icecast servername/port to put into their OGG compatible streaming client. This configuration tells your icecast server that when the source (DJ) connects or disconnects it is to run the specified shell scripts located in /usr/share/icecast2. Restart the icecast server to pick up the new configuration
sudo /etc/init.d/icecast2 restart
Next you need to configure the /usr/share/icecast2/start.sh script. Open it in your favorite text editor and alter the format to point to the correct servers, set your bitrate and your destination shoutcast server source password:
/usr/share/icecast2/oggtoshout.pl http://icecast.server.name:port/trans.ogg \ http://destination.shoutcast.server.name:port 128 shoutcastpassword
If you wish to adjust the MP3 samplerate from 44.1Khz, you can search for and change the following in oggtoshout.pl
# Adjust this to your desired sample rate. 44.1 = 44100 khz my $srates = '44.1';
That is all there is to it. Now when a DJ connects to the /trans.ogg mountpoint on your icecast server, the system will automatically begin transcoding the stream from OGG to MP3 and pass it to your shoutcast server.
I’m trying to download the oggtoshout.tar.gz to look over the sh files, but i’m getting a archive corrupted error
I wanted to update the people here who have been asking about sending metadata (current song) between icecast and shoutcast. We couldn’t get that to work after a bunch of messing with the 2 servers, and didn’t see a good place in the perl script to include it, so my solution was to write a bash script that pulls song data from icecast and sends it to shoutcast via the admin web interface. This script is just a loop that periodically gets the current song from icecast, encodes it into a URL friendly format (urlencode), and sends it to shoutcast using curl. The script is added to the start.sh and stop.sh scripts that are called when the icecast mount is activated (where the oggtoshout perl script is called). It is not a clean or pretty solution – but it works, and solves the problem of the metadata getting eaten by the transcoding.
Also I would like to thank the author for writing this guide, as it was instrumental in me getting this all working. I’m now successfully streaming directly from Traktor to Shoutcast-only stations and sending song IDs, and couldn’t be happier! Cheers- djscsi
Hi There,
I am very intrested in your bash script ? Can you share it with me ?
Greets
Dave
I’m using Traktor too and the Metadata preservation would be perfect!
I hope Native Instruments will make direct mp3 streaming possible in Traktor 2
Thanks for this great Tutorial
Hi guys,
I hadnt really thought of metadata. This project is a bit mothballed for me at the moment but I will definitely look into it. If anyone out there fancies a go, please let me know how you get on so I can link the new code here.
Hi,
This is great, many thanks.
As mentioned in another comment, if it’s possible to get the metadata from the ogg stream converted to the mp3 stream it would be perfect.
Tags include Stream URL, Stream Name, Description, Genre and the ID3 tags.
I use Traktor also.
many thanks
Howard
what you posted is good but would you know if it is possible to convert ogg to mp3 if i’m using a centova cast server. (icecast setup)
Hi,
great tutorial. Thanks a lot! I use this setting with the traktor broadcasting feature.
Is there a way to get the id3 tags sent to shoutcast by the perl script?
Greets!
Hey there,
Trying to do what you have explained here – confirmed that I am getting audio out of the icecast server just fine.
However, no matter what I do when I run the oggtoshout program, it connects, but then closes after 10 seconds with the “bailing!” error.
So basically I don’t know if it is connecting to the source stream or if it is sending it to the end stream. During the period between it starting and auto-killing itself I can connect to the shoutcast server. After it kills itself I get the “service unnavailable” error.
Any thoughts?
If you get the ‘bailing’ error, the bit of code that produces that is this
sub error_alarm {
print STDERR "$progname: timeout: $timeout seconds with no data!\n";
print STDERR "$progname: bailing!\n";
kill 9, $parent_pid; # Send KILL to self. Finally.
}
Basically its not getting any data in if you get that error. first off, check your start.sh file and verify you have the correct URL and mount point specified (the one you listen to on the icecast server to confirm it works). One of my friends was getting the exact same problem, but he had left the mountpoint out of the start.sh file (so he had http://server.com:8000/ instead of http://server.com:8000/hismountpoint.ogg)
Let me know if that doesnt sort it out
I have exactly the same problem. I can listen if I connect to the icecast2 stream and the oggtoshout.pl has also the correct settings correct. Any idea?
Same problem, no input data even though I tried with different ogg streams.
Hi! I did everythin’ what is mentioned here but when I want to start the stuff I get an error from oggtoshout.pl: HTTP/1.0 401 Authentication Required
Can you advise somethin’?
Ok I was lame.
I found the problem. Thanks for this HOWTO. Very useful! ;]
Regards
Hello,
I tried your method, followed the directions to the T.. Even figured out what to do where you typo’d the directory..
but all I get is static on the shoutcast stream..
Thats a bit strange its working in production for me, we have been running it for over a year with daily use. To being troubleshooting, id recommend first connecting to your Icecast server directly using a media player, verifying there is audio available on the stream you are grabbing. If thats the case, do a netstat to ensure ogg123 is connecting to your icecast server and grabbing audio. ps auwx can check to ensure lame is running and higher cpu use should indicate it is transcoding. Let me know how you get on. p.s, where was the typo?
In the Mointpoint config (icecast.xml) you have the “startogg.sh” and “stoppogg.sh” in the code sample instead of “start.sh” and “stop.sh”
Took me some while to figure it out.
Thanks for this great tutorial, now everything works fine!
I can see what you mean about the complexity however this setup is designed more from a broadcast point of view due to the nature and dynamic of the stations I provide. My main constraints were:
- Shoutcast source port must vacate immediately when the OGG source disconnects from icecast (this lets the next live DJ connect with minimal silence/dead air to listeners)
- Transcode will commence immediately when an OGG source connects, without regular polling of icecast server by scripts or programs (this also cuts down on dead air/silence during DJ switchovers)
- Both icecast and shoutcast servers source ports must remain open and not used when no OGG source is connected
If you are not as constrained as me, you could look into Oddsock Stream Transcoder as this may do what you want at the cost of some delay, dead air or polling. It works under windows too.
This seems like an awfully complicated operation for a relatively simple task.
Would this work with cygwin or do I really need another computer with Linux to be able to stream mp3 from Traktor?
If only someone would bother to make a program that’d convert an ogg-stream to an mp3-stream on windows…