Wednesday, 1 January 2014

What is Icecast - page one

This is a short article on installing, configuring and running an Icecast streaming server on Debian. Everything I describe here should work on Debian 7 with Icecast 2.3.2 and or Icecast Release 2.4-beta3, however I used Icecast server version 2.3.2 on Debian 6.0.7

What is icecast?
Icecast is free server software for streaming multimedia. It currently supports Ogg Vorbis and MP3 audio streams. It can be used to create an Internet radio station, a stream for freinds and family, or your own private playlist stream. I use Icecast to stream my favorite music within my home. By using an audio stream I can listen to my music on any device within my home.

In this article comments and instructions are in this font; commands you enter are in bold, and settings in config files you enter or verify are in italic bold .


I am  going to install Icecast and all acillery programs on an OpenVZ virtualized instance of Debian 6.0.7. To find out more about virtualiation see my article; "OpenVZ on Debian" here; http://openvzondeb.blogspot.ca/

To jump to a particular topic or page in this article;
What is Icecast                                      - page one
Installing and configuring Icecast                   - page two
The web interface                                    - page three
source clients and what they do                      - page four
setting up on server music directories               - page five
Ices2, installation, configuration, and use          - page six
Ezstream, installation, configuration and use        - page seven
using off streaming server music sources             - page eight
Ezstream source from a windows machine               - page nine
VLC source from a windows machine                    - page ten
multiple streams                                     - page eleven
references                                           - page twelve

Install & configure Icecast - page two

To correctly install software on a Debian server, or any linux machine for that matter, you must be or become root. I strongly reccommend that you DO NOT log on as the root account itself, but as a user account and become root by using su or sudo. For more information about server security see my article " Linux Server Hardening " here; http://linuxserverhardening.blogspot.ca/ [ it pertains to centos, but the ideas are universal ]. So, throught this article rather than saying "become root" or prefacing commands with "sudo" I will assume you have become root.

Now, just in case you don't know how to become root, this is what you do;
Sign onto your server with a common user account, either locally [open a terminal, command prompt] or remotely through a terminal session. Putty is a great, free, terminal client that works with both linux and windows machines.
To become root enter
su
or
sudo before every command.
or
sudo su


The difference between the commands are;
su - asks you to enter the root users password
sudo before every command. - asks for your password. Your user id must be in the sudo user's group
sudo su - asks for your password once. Your user id must be in the sudo user's group



Lets begin!

Install & configue Icecast - page three

This the last time I'll say, 'become root'. At the command prompt enter
su
or
sudo su

You don't need to do this, but to verify the debian version;
command; cat /etc/debian_version
output;  6.0.7

and to find out the kernel version;
command; uname -mrs
output;  Linux 2.6.32-5-openvz-amd64 x86_64

Make sure your machine is up to date;
apt-get update
apt-get upgrade

I like nano as a text editor and use it exclusively
apt-get install nano

install icecast. [note, Debian and its derivatives (e.g. Ubuntu) name the icecast package 'icecast2'.]
apt-get install icecast2

This will install icecast, and create an associated user & group. You will see something like this scroll up your screen;
...
Adding system user `icecast2' (UID 103) ...
Adding new user `icecast2' (UID 103) with group `icecast' ...
Not creating home directory `/usr/share/icecast2'.
icecast2 daemon disabled - read /etc/default/icecast2.

If you don't read the installation messages closely, you may miss " icecast2 daemon disabled - read /etc/default/icecast2."

Install & configue Icecast - page four

Edit /etc/default/icecast2 and set ENABLE to true.
nano /etc/default/icecast2

find this text fragment;

# Change this to true when done to enable the init.d script
ENABLE=false

and change ENABLE setting to true
# Change this to true when done to enable the init.d script
ENABLE=true

Now, note that the comments say "# sourced by /etc/init.d/icecast2 " and " # Edit /etc/icecast2/icecast.xml and change at least the passwords." Edit icecast.xml. Most of the settings can stay at their defaults, but you should change all the "hackme" passwords to something you will remember.

nano /etc/icecast2/icecast.xml

Find the authentication section;

 <authentication>
        <!-- Sources log in with username 'source' -->
        <source-password>hackme</source-password>
        <!-- Relays log in username 'relay' -->
        <relay-password>hackme</relay-password>

        <!-- Admin logs in with the username given below -->
        <admin-user>admin</admin-user>
        <admin-password>hackme</admin-password>
    </authentication>

and change the passwords. In this article I use "my1pa55w0rd"; but make sure you use something different.

 <authentication>
        <!-- Sources log in with username 'source' -->
        <source-password>my1pa55w0rd</source-password>
        <!-- Relays log in username 'relay' -->
        <relay-password>my1pa55w0rd</relay-password>

        <!-- Admin logs in with the username given below -->
        <admin-user>admin</admin-user>
        <admin-password>my1pa55w0rd</admin-password>
    </authentication>

The source password is used by the stream source program to stream to the server. The admin password is used by the admin user to access the web admin pages. The relay password is used if the server is used as a stream relay.

To change the location, hostname, admin, and server ID information on the web interface administration "Global Server Stats" page you can add in the following settings right below  <hostname>localhost</hostname>

    <location>your location, unchaged it defaults to; earth</location>
    <admin>your email account or name, unchanged it defaults to; icemaster@localhost</admin>
    <fileserve>1</fileserve>
    <server-id>version of icecast, or whatever, unchanged it defaults to; icecast 2.3</server-id>


A few things you should make mental note of from the icecast.xml file;

     Sources log in with username 'source'            -     <!-- Sources log in with username 'source' -->
     and use the password you set.                    -     <source-password>my1pa55w0rd</source-password>
     default number of clients [listeners] is 100     -     <clients>100</clients>
     default number of sources is 2                   -     <sources>2</sources>
     default listen-socket is port 8000               -     <port>8000</port>
     logs are saved to /var/log/icecast2              -     <logdir>/var/log/icecast2</logdir>

save the file.

The web interface - page five

We noted "# sourced by /etc/init.d/icecast2" in the comments in /etc/default/icecast2. What that means is that is the init file we use to start icecast. You can start icecast without using the init file, but by using it icecast is started and run under the correct user.
/etc/default/icecast2 start

You can now access the icecast web admin pages from the local server at http://localhost:8000/ or from a remote machine [within your network] at your server's IP address, as; http://yourserversIPadr:8000 [ example http://192.168.1.21:8000 ] Once logged on you will see global stats, but of course no stream or user info because there aren't either yet. Once run, icecast will create access.log and error.log files in /var/log/icecast2/.

To kill icecast enter;
/etc/default/icecast2 stop


The icecast streaming server is now installed, configured, and if you were able to access the web pages, running. But as is, by itself, it is not very usefull. To make it work, to make it useful you must feed it a stream with a stream source client.

The thing I always had trouble getting my head around was why a streaming server needed to be fed a stream. By my thinking it should just, you know, take a song and, you know, stream. But it doesn't work that way. You need a client for the stream source. The other thing I had great trouble getting and coming to terms with is the role of the listen-socket, port 8000. Does listen port mean where your clients, your listeners, listen? Or does it mean where your icecast server "listens" for the stream source?

It appears not only does it mean both, but it also means where your icecast server 'listens' for the web admin. I have a hard time accepting that multiple streams can go up, come down, and be administered through the same port, and that it all can be done with no collisions or adverse affects. But it can. So, if you are like me, suspend your disbelief and trust me; It will all work.

From here on, for "your server's IP address" I will use ; 192.168.1.21 and for passwords I'll use "my1pa55w0rd". Remember, you change these to reflect your setup.

stream source clients - page six

Stream source clients and what they do.

What are stream source clients?
Stream source clients take audio input or play lists and streams it to the streaming server. The streaming server then lets one or more listeners listen to the stream. With the streaming server and stream source client [program] split into two distinct programs the source client [and source stream] can be situated anywhere. The stream source does not need to be on the icecast server, it can be, but it also can be half the way around the world.



There are various stream source clients. We will look at three. The icecast project has two source clients, ices2 and ezstream. we will also look at using vlc as a source client.

Ices2, install, configure, use - page seven

Ices2
IceS is a source client that streams an audio stream from various possible sources into a stream that is fed to the Icecast streaming server. IceS v2 is a command line application that supports sending an Ogg Vorbis stream to an Icecast server. This can be live audio (e.g. from a sound card) or Ogg Vorbis files from a play list. We will be using a playlist.
Note, Ices2 will only stream ogg format files.

install ices2
apt-get install ices2

AS part of the configuration of Ices we need to create a few necessary directories
mkdir /var/log/ices
mkdir /etc/ices2
You can  do a mkdir /etc/ices2/music, but I prefer to create a music user and put all the music for all possible streaming clients in one spot. create a user 'music';
adduser music

 You can covert mp3 files to ogg with vlc,  VLC works on both linux and windows machines.

There are other free conversion tools available at Vorbis.com [http://www.vorbis.com].

In the music users home directory add an ogg and mp3 directory. Upload [or move] your *.ogg files to /home/music/ogg and your *.mp3 files to /home/music/mp3.

To make a playlist file install tree and use it to create the playlist file.
     apt-get install tree
     tree -if /home/music/ogg/ > /home/music/ogg/ogg-playlist.txt [note; the 'if' isn't a condition, but command switches, to not print lead characters, and print full path. for more info do tree --help]
and
     tree -if /home/music/mp3/ > /home/music/mp3/mp3-playlist.txt

Clean up your newly created playlist.txt files by deleting the lines not containing songs. [the first and last two lines]
nano /home/music/ogg/ogg-playlist.txt
and
nano /home/music/mp3/mp3-playlist.txt

Ices2 examples - page eight

Ices2 comes with a couple of example xml playlist files, which are located in /usr/share/doc/ices2/examples. The examples are;
ices-alsa.xml
ices-oss.xml
and
ices-playlist.xml


The first two examples use the 'oss' module and takes input from the OSS audio device (e.g. line-in), and processes it for live encoding.

The ices-playlist.xml example is what we are going to use. It has 'submodules' to support different types of playlist, however we'll use the basic simple file-based playlist.

We'll make a copy of the ices-playlist file and modify it for our installation.
cp /usr/share/doc/ices2/examples/ices-playlist.xml /etc/ices2

nano /etc/ices2/ices-playlist.xml

Make the following changes
 1. Locate ‹background› section and change value 0 to 1.
          <!-- run in background -->
              <background>1</background>

 2. Locate ‹metadata› section and change name, genre and description according to your desires.
           <metadata>
                 <name>Change this to your stream's name</name>
                 <genre>Change thias to your stream's genre</genre>
                 <description>Change this to a short description of your stream</description>
           </metadata>

 3. Locate ‹param name=”file”› and change it to the path to your playlist.
           <param name="file">/home/music/ogg/ogg-playlist.txt</param>

 4. Locate the <instance> section and change;
         the password from 'hackme' to the same source password you set in the icecast.xml file.
              <password>my1pa55w0rd</password>
         the mount name to something appropriate to your stream
            <mount>/countrystrm.ogg</mount>

The mount should end in .ogg because icecast streams in ogg and all receiving clients may not be able to figure out it is ogg without the mountpoint having the appropriate ending. [i.e: mycountrystream will work with 'most' ogg enabled clients, but mycountystream.ogg will work with all ogg enabled clients]

Start your stream - page nine

You can now start the stream!

To get everything working and running;

start the ices streaming server;
/etc/default/icecast2 start [ or /etc/default/icecast2 restart if you had it running]

start the ices2 source client;
  ices2 /etc/ices2/ices-playlist.xml

You can now;
     administer the streaming server at;     http://yourserversIPadr:8000
     listen to the stream at;                http://yourserversIPadr:8000/yourstream.ogg
                                             [my example; http://192.168.1.21:8000/countrystrm.ogg]

Ezstream - page ten

Ezstream

Ezstream is another command line source client for the Icecast streaming server.

In its basic mode of operation, ezstream will stream media files without reencoding, thus requiring very few CPU resources. However, it can use various external decoders and encoders to reencode from one format to another, and stream the result to an Icecast server. Supported media formats for streaming are MP3, Ogg Vorbis and Ogg Theora. All of its features, as well as the availability of a windows version, make ezstream a very flexible source client.

install ezstream
apt-get install ezstream

As with ices2, we need to make a few configuration directories;
mkdir /var/log/ezstream
mkdir /etc/ezstream
mkdir /etc/ezstream/music

Ezstream comes with a number of configuration file examples. They can be found at /usr/share/doc/ezstream/examples.

The example configuration files are;

ezstream-file_template.xml  ezstream_reencode_mp3.xml     ezstream_stdin_vorbis.xml  play.sh
ezstream_metadata.xml       ezstream_reencode_theora.xml  ezstream_vorbis.xml        playlist-logger.sh
ezstream_mp3.xml            ezstream_reencode_vorbis.xml  meta.sh


Again, as with ices2 we will use a copy of of one of the example files; ezstream_vorbis.xml. Make a copy of the file;
cp /usr/share/doc/ezstream/examples/ezstream_vorbis.xml /etc/ezstream

And then as with the ices2 config file set ezstreams ezstream_vorbis.xml config file to reflect your stream.

The whole ezxztream_vorbis.xml file set to reflect my stream with comments indented and items you should change in bold.

<!--
    EXAMPLE: Ogg Vorbis playlist stream WITHOUT reencoding

This example streams a playlist that contains only Ogg Vorbis files. No
    other file formats may be listed. Since ezstream will not be doing any
    reencoding, the resulting stream format (quality/bitrate, samplerate,
    channels) will be of the respective input files.
  -->
<ezstream>
    <url>http://localhost:8000/rocknroll.ogg</url>
    <!--      If a different user name than "source" should be used, set it in      <sourceuser/>:     -->
    <!-- <sourceuser>mr_stream</sourceuser> -->
    <sourcepassword>rstacey</sourcepassword>
    <format>VORBIS</format>
    <filename>/home/music/ogg/ogg-playlist.txt</filename>
    <!-- For demonstrational purposes, explicitly set continuous streaming: -->
    <stream_once>0</stream_once>
    <!--      The following settings are used to describe your stream to the server.
It's up to you to make sure that the bitrate/quality/samplerate/channels
      information matches up with your input stream files.
      -->
    <svrinfoname>My Rock and Roll Stream</svrinfoname>
    <svrinfourl>http://192.168.1.21</svrinfourl>
    <svrinfogenre>RockNRoll</svrinfogenre>
    <svrinfodescription>My Rock and  Roll stream, with a bit of country</svrinfodescription>
    <svrinfobitrate>96</svrinfobitrate>
    <svrinfoquality>2.0</svrinfoquality>
    <svrinfochannels>2</svrinfochannels>
    <svrinfosamplerate>44100</svrinfosamplerate>
    <!-- Allow the server to advertise the stream on a public YP directory: -->
    <svrinfopublic>1</svrinfopublic>
</ezstream>

Ezstream cont'd - page eleven

you can now start the ezstream streaming client with;

ezstream -c /etc/ezstream/ezstream_vorbis.xml


You should see the stream show up in your web admin panel at; http://yourserversIPadr:8000
And, you should be able to listen to the stream at http://yourserversIPadr:8000/rocknroll.ogg

To kill ezstream just hit ctrl/c in the ezstream command prompy window. Killing ices2 or other stream source clients on your streaming server, may not be that easy. We need to determine the process name or number and then kill that process. Become root then run;
ps aux

THE OUTPUT will be something like;

USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
...
root     11616  0.0  0.7  31424  1948 pts/0    S+   22:15   0:00 ezstream -c /etc/ezstream/ezstream_vorbis.xml
root     11618  0.0  0.3  14820  1024 pts/1    R+   22:15   0:00 ps aux
root     11776  6.1  1.3 113060  3412 pts/0    Sl+  22:29   0:00 ices2 /etc/ices2/ices-playlist.xml

To kill ices2 do;
pkill ices2

To kill ezstream do;
pkill ezstream

other stream sources - page twelve

Streaming from a different machine.
One of the really neat and powerful things about an icecast streaming server is the source client can be anywhere, on any machine. You can be half way around the world and stream to your icecast server with the appropriate source client.


Using VLC as a stream source from a windows machine
VLC is a terrific open source, cross platform, media player, that plays almost any media format. It can be installed on linux or windows as well as numerous other operating systems. VLC can do a lot other really neat things too, besides playing just about anything. You can use vlc to download youtube videos, convert media files to different format, and as a stream source client. If you don't have it installed you can get it at; http://www.videolan.org/vlc/

To stream a vlc playlist [randomly and continuosly] to your icecast server;
On your pc with your music library [in any vlc playable format] install vlc and start it. From within VLC
    click on; tools| preferences, tick show settings, all, select playlist, tick; play files randomly forever and auto start, then save.
    click on; view | playlist. Highlight playlist if its not highlighted. In the big white area right click, select add folder and navigate to your music folder, click select folder. You should now have a [blue] folder in the big white area under title.
    right click on the folder, click on stream. In the pop up box, click on next. In destinations, change new destination to IceCast, click add. Set the following;
        address:       yourserversIPaddress [in my example, withiun my home network its 192.168.1.21 ]
        mount point:   anything you want, but should end in .ogg [I'll use newstream.ogg]
        login:pass:    source:     [critical, must be exactly  source:harpchahal]
        tick activate transcoding, change profile to audio - vorbis (ogg). Click next then stream

VLC is a great program. We will now use it to download a youtube video and convert it to ogg theora. When doing this the first time, to eliminate all variables, download and convert the same video as I do. From your web browser, search youtube for " beverly hillbillies season 1 episode 1 ". Play the video in your browser and copy the link. It should be http://www.youtube.com/watch?v=uofJowqrk4M. Once you've copied the link you can close your browser, or just stop the video from playing. If you've still got vlc streaming, stop the stream.

In VLC click on media | open network stream, and paste the beverely hillbillies link into the space for network URL. Click the black downward pointin V next to the play button and click on convert. In the destination file box type in c:\temp\beverlyhillbillieses1e1.ogv
Change the profile to ' Video - Theora + Vorbis (OGG). Click start. The convert box will dissappear, but in the vlc main window you will see the blue played status bar progress as its being converted to ogv and downloaded. When complete, close vlc.

Ezstream from windows - page thirteen

Using Ezstream as a source from a windows machine.

Ezstream also has a windows version. From a windows machine, download [ from here; http://www.icecast.org/ezstream.php ] ezstream for windows. It is a commandline program in windows also, so put it somwhere so you can easily get to it from the command line. I downloaded it to a thumb drive, so it is in g:\ezstream.

http://v2v.cc/~j/ffmpeg2theora/download.html
Open ezstream_vorbis.xml and save it as theora.xml. Edit theora.xml and make the following changes


<ezstream>
    <url>http://192.168.1.21:8000/hillbillies.ogv</url>
    <!--
      If a different user name than "source" should be used, set it in
      <sourceuser/>:
     -->
    <!-- <sourceuser>mr_stream</sourceuser> -->
    <sourcepassword>my1pa55w0rd</sourcepassword>
    <format>THEORA</format>
    <filename>c:\temp\beverlyhillbillieses1e1.ogv</filename>
    <!-- For demonstrational purposes, explicitly set continuous streaming: -->
    <stream_once>0</stream_once>
    <!--
      The following settings are used to describe your stream to the server.
      It's up to you to make sure that the bitrate/quality/samplerate/channels
      information matches up with your input stream files.
     -->
    <svrinfoname>The Beverly Hillbillies!</svrinfoname>
    <svrinfourl>http://192.168.1.21</svrinfourl>
    <svrinfogenre>Beverly Hillbillies</svrinfogenre>
    <svrinfodescription>The Beverly Hillbillies; Season one, Epesode one.</svrinfodescription>
    <svrinfobitrate>96</svrinfobitrate>
    <svrinfoquality>2.0</svrinfoquality>
    <svrinfochannels>2</svrinfochannels>
    <svrinfosamplerate>44100</svrinfosamplerate>
    <!-- Allow the server to advertise the stream on a public YP directory: -->
    <svrinfopublic>0</svrinfopublic>
</ezstream>


To stream it to your streaming server run;

G:\ezstream ezstream -c g:\ezstream\examples\theora.xml


Use vlc to play the stream. Open vlc, select media | open network stream |  and in network URL enter http://192.168.1.21:8000/hillbillies.ogv


The video will be tiny, blurry, and the stream may stutter; but it will work!

Listening to you Stream - page fourteen

To listen to the stream from a windows machine I usually use vlc, but since you may be using it as a stream source, Foobar2000 is a good, lightweight, free, windows playback client. You can get if from; http://www.foobar2000.org/

And that  my friends, should be that!

References - page fifteen

References:
icecast.org
http://icecast.org/index.php/
Icecast 2 Documentation
http://icecast.org/docs/icecast-2.3.3/
ices2
http://icecast.org/docs/ices-2.0.2/
eazstream
http://www.icecast.org/ezstream.php/
vlc
http://www.videolan.org/
Foobar2000
http://www.foobar2000.org/
General
http://itblog.gr/630/create-your-own-online-radio-stream-in-ubuntu/">http://itblog.gr/630/create-your-own-online-radio-stream-in-ubuntu/


My Streams:
Ices information panel
http://www.eclectica.mx:8000/
     One of my streams is an all Neil Young stream.To see its listing on the Icecast Directory [at:  http://dir.xiph.org/ ] search for Neil.
The search results will be: Neil Young [x listeners] " All Neil Young, and only Neil Young."



My other blogs:
OpenVZ on Debian                -  http://openvzondeb.blogspot.ca/
Linux Server Hardening        -  http://linuxserverhardening.blogspot.ca/
Icecast on Debian                  -  http://icecastondebian.blogspot.ca/2013/10/page-one_31.html
SSHFS with rcync                 -  http://usingsshfs.blogspot.ca/
SOCKS Tunneling                 -  http://sockstunneling.blogspot.ca/ 
Kobo Arc 7", 64GB               -  http://koboarc.blogspot.ca/ [*new*]
and, a few works in progress:
Short Stories                          -  http://louisebridgewrites.blogspot.ca/
Android TV Sticks                -  http://tvsticks.blogspot.ca/


[all links in this article worked as of 2014/03/25 ]