Using icecast2 server and ices2 client.
Following steps were tried on an Ubuntu server.
Install icecast2 server
Install icecast2 server and configure default password when prompted for during the installation
sudo apt-get install icecast2
Start the server
icecast2 -b -c /etc/icecast2/icecast.xml
Install ices2 client
Install client which is responsible for reencoding and sending the mp3/ogg files to the icecast2 server.
sudo apt-get install ices2
Modify /etc/ices2/ices-playlist.xml
, to change metadata, log file path, encoding params as per your requirement.
Make sure relevant folders are in place to hold the config files, log files and the audio files that are to be streamed. As per the default configuration, following files should be in place in /etc/ices2/ices-playlist.xml
<?xml version="1.0"?>
<ices>
<!-- run in background -->
<background>1</background>
<!-- where logs, etc go. -->
<logpath>/var/log/ices</logpath>
<logfile>ices.log</logfile>
<!-- 1=error,2=warn,3=info,4=debug -->
<loglevel>4</loglevel>
<!-- set this to 1 to log to the console instead of to the file above -->
<consolelog>0</consolelog> ... <stream> <input>
<module>playlist</module>
<param name="type">basic</param>
<param name="file">/etc/ices2/playlist.txt</param>
<!-- random play -->
<param name="random">0</param>
<!-- if the playlist get updated that start at the beginning -->
<param name="restart-after-reread">0</param>
<!-- if set to 1 , plays once through, then exits. -->
<param name="once">0</param>
</input> ... <instance>
<hostname>localhost</hostname>
<port>8000</port>
<password>hackme</password>
<mount>/play.ogg</mount>
<encode>
<nominal-bitrate>64000</nominal-bitrate> <!-- bps. e.g. 64000 for 64 kbps -->
<samplerate>22050</samplerate>
<channels>1</channels>
</encode>
</instance>
<stream>
...
Start ices2 client to start streaming audio via server,
ices2 /etc/ices2/ices-playlist.xml
Verify the setup
Verify if both the server and client are running.
$ ps aux | grep ice
icecast2 72943 0.0 0.7 395348 7392 ? Sl May14 0:35 /usr/bin/icecast2 -b -c /etc/icecast2/icecast.xml
root 73181 0.7 0.5 116972 5212 ? Sl May14 5:13 ices2 /etc/ices2/ices-playlist.xml
Check the setup by connect to the server from a browser
http://server-ip:8000/play.ogg
You will need to whitelist port 8000 on your server. Alternately you could also setup a nginx reverse proxy to stream the file from port 80. Inside you server block on nginx, have the following.
location /play.ogg {
proxy_pass http://localhost:8000/play.ogg;
}
Issue with mp3 format
ices2 doesn't support .mp3, and .ogg is not supported in safari, to make .mp3 streaming work, use ices0.
ices0 has to be built from source
apt-get install libmp3lame-dev libxml2-dev libshout-dev libvorbis-dev
cd /tmp/
wget http://downloads.us.xiph.org/releases/ices/ices-0.4.tar.gz
tar xf ices-0.4.tar.gz
cd ices-0.4/
./configure --prefix=/usr/local --with-pic --with-lame
make
make install
mkdir /etc/ices
cp /usr/local/etc/ices.conf.dist /etc/ices/ices.conf
Run the server
/usr/local/bin/ices -c /etc/ices/ices.conf -v
Notice, the config structure for ices0 is changed when compared to that of ices2. Make the relevant changes if you wish and restart the client.
Other commands
You can get the current file info that is being streamed from the ices0 client from /etc/ices2/ices.cue
You can also use sox tool to get details of any other mp3 files from your playlist.
sudo apt install sox
sudo apt-get install libsox-fmt-mp3 # to run sox on mp3 formats