Thursday, January 29, 2015

Icecasting From Home: Part 1

This is how to run a minimalistic internet radio service. It uses the well known and free icecast server to serve the audio streams. Theoretically, there is no limit to the number of streams of audio you can serve. You are limited only by your hardware and bandwidth.

In this example, the backend uses the ices0 server to serve mp3 songs to icecast. The newer ices server serves only Ogg streams. This is largely an open source issue since mp3 is not open source. As I already have a ton of mp3 sitting on my drives, I went for ices0 instead.

First off, note that I'm on OpenSuse 12.2.

To install icecast I had to fulfill some dependencies.

These were:

libxml
libxslt
libogg
libvorbis


Build the dependencies for icecast:

libxml

Download the source files- libxml2-2.9.1.tar.gz
Untar:
tar -xvzf libxml2-2.9.1.tar.gz

cd to the extracted folder:
cd libxml2-2.9.1

In the usual manner run the configure, make and installation commands:
./configure
make
sudo make install

libxslt

For libxslt, download the source files- libxslt-git-snapshot.tar.gz

Untar:
tar -xvzf libxslt-git-snapshot.tar.gz

cd to the extracted folder:
cd libxslt-1.1.28

In the usual manner run the configure, make and installation commands:
./configure
make
sudo make install

libogg

For libogg, download the source files- libogg-1.3.2.tar.gz

Untar:
tar -xvzf libogg-1.3.2.tar.gz

cd to the extracted folder:
cd libogg-1.3.2

In the usual manner run the configure, make and installation commands:
./configure
make
sudo make install

libvorbis

For libvorbis, download the source files- libvorbis-1.3.4.tar.gz

Untar:
tar -xvzf libvorbis-1.3.4.tar.gz


cd to the extracted folder:
cd libvorbis-1.3.4


In the usual manner run the configure, make and installation commands:
./configure

make

sudo make install



icecast

download the source files: icecast-2.4.1.tar.gz

Untar:
tar -xvzf icecast-2.4.1.tar.gz


cd to the extracted folder:
cd icecast-2.4.1


In the usual manner run the configure, make and installation commands:
./configure

make

sudo make install



BACKEND CLIENT- ices0 for mp3:

There is at least one dependency- libshout2.

Build the dependency for ices0:

Download the source files: libshout-2.3.1.tar.gz

Untar:
tar -xvzf libshout-2.3.1.tar.gz


cd to the extracted folder:
cd libshout-2.3.1


In the usual manner run the configure, make and installation commands:
./configure

make

sudo make install



ices0

Download the source files: ices-0.4.tar.gz

Untar:
tar -xvzf ices-0.4.tar.gz


cd to the extracted folder:
cd ices-0.4.tar.gz


In the usual manner run the configure, make and installation commands:
./configure

make

sudo make install


Now we are set up minimally.


Run ice cast server with :

icecast -c /usr/local/etc/icecast.xml


go to http://localhost:8000 to see default icecast in action.

You should this if all has gone well.


You should now edit icecast.xml to suit your purposes.

Running multiple instances of ices and multiple radio stations:

First, edit the icecast.xml to allow more sources and listening ports.
In this example we edited to add port 8443, and increased sources to 6.

Note that you need su priviledges. So use :

gnomesu gedit


SECTION TO EDIT- "limits":

    <limits>

        <clients>100</clients>

        <sources>6</sources>

        <queue-size>524288</queue-size>

        <client-timeout>30</client-timeout>

        <header-timeout>15</header-timeout>

        <source-timeout>10</source-timeout>

        <!-- If enabled, this will provide a burst of data when a client 

             first connects, thereby significantly reducing the startup 

             time for listeners that do substantial buffering. However,

             it also significantly increases latency between the source

             client and listening client.  For low-latency setups, you

             might want to disable this. -->

        <burst-on-connect>1</burst-on-connect>

        <!-- same as burst-on-connect, but this allows for being more

             specific on how much to burst. Most people won't need to

             change from the default 64k. Applies to all mountpoints  -->

        <burst-size>65535</burst-size>

    </limits>


Here sources are set to 6.

Then edit to open more ports:
SECTION TO EDIT - "listen-socket":

    <!-- You may have multiple <listener> elements -->

    <listen-socket>

        <port>8000</port>

        <!-- <bind-address>127.0.0.1</bind-address> -->

        <!-- <shoutcast-mount>/stream</shoutcast-mount> -->

    </listen-socket>

    <!--

    <listen-socket>

        <port>8080</port>

    </listen-socket>

    -->

    

    <listen-socket>

        <port>8443</port>

        <!--ssl>1</ssl-->

    </listen-socket>


An added port 8443 has been opened up.
Next, make a copy of the ices.conf. Name this to say "jazz.conf".
Edit the jazz.conf to point to the relevant playlist.
SECTION TO EDIT- "Playlist"

<Playlist>

    <!-- This is the filename used as a playlist when using the builtin 

     playlist handler. -->

    <File>/home/rnx/jazz.txt</File>

    <!-- Set this to 0 if you don't want to randomize your playlist, and to

     1 if you do. -->

    <Randomize>0</Randomize>

    <!-- One of builtin, perl, or python. -->

    <Type>builtin</Type>

    <!-- Module name to pass to the playlist handler if using  perl or python.

     If you use the builtin playlist handler then this is ignored -->

    <Module>ices</Module>

    <!-- Set this to the number of seconds to crossfade between tracks.

         Leave out or set to zero to disable crossfading (the default).

    <Crossfade>0</Crossfade>

    -->

  </Playlist>

Edit the mountpoint, stream name and genre to reflect jazz:
SECTIONS TO EDIT- "mountpoint", "Name" and "Genre":

    <!-- The name of the mountpoint on the icecast server -->

    <Mountpoint>/jazz</Mountpoint>

    <!-- The name of the dumpfile on the server for your stream. DO NOT set

     this unless you know what you're doing.

    <Dumpfile>ices.dump</Dumpfile>

    -->

    <!-- The name of you stream, not the name of the song! -->

    <Name>Jazz</Name>

    <!-- Genre of your stream, be it rock or pop or whatever -->

    <Genre>Jazz</Genre>

This will operate on port 8000 because we left that unchanged. Note that it is better to change the port to another, because 8000 is icecast's default display port, which shows a webpage.
Make another copy of the ices.conf file and name it to say bollywood.conf.
Edit this to point to the relevant playlist.
SECTIONS TO EDIT- "Playlist", "mountpoint",and "Crossfade":

<Playlist>

    <!-- This is the filename used as a playlist when using the builtin 

     playlist handler. -->

    <File>/home/rnx/bollywood.txt</File>

    <!-- Set this to 0 if you don't want to randomize your playlist, and to

     1 if you do. -->

    <Randomize>0</Randomize>

    <!-- One of builtin, perl, or python. -->

    <Type>builtin</Type>

    <!-- Module name to pass to the playlist handler if using  perl or python.

     If you use the builtin playlist handler then this is ignored -->

    <Module>ices</Module>

    <!-- Set this to the number of seconds to crossfade between tracks.

         Leave out or set to zero to disable crossfading (the default).

    <Crossfade>5</Crossfade>

    -->

  </Playlist>

Edit the port to connect to the other open port in icecast (8443).
Edit the mountpoint name, stream name, and genre.
SECTIONS TO EDIT- "Server", "mountpoint", "Name" and "Genre":

    <Server>

      <!-- Hostname or ip of the icecast server you want to connect to -->

      <Hostname>localhost</Hostname>

      <!-- Port of the same -->

      <Port>8443</Port>

      <!-- Encoder password on the icecast server -->

      <Password>hackme</Password>

      <!-- Header protocol to use when communicating with the server.

           Shoutcast servers need "icy", icecast 1.x needs "xaudiocast", and

       icecast 2.x needs "http". -->

      <Protocol>http</Protocol>

    </Server>



    <!-- The name of the mountpoint on the icecast server -->

    <Mountpoint>/bollywood</Mountpoint>

    <!-- The name of the dumpfile on the server for your stream. DO NOT set

     this unless you know what you're doing.

    <Dumpfile>ices.dump</Dumpfile>

    -->

    <!-- The name of you stream, not the name of the song! -->

    <Name>Bollywood</Name>

    <!-- Genre of your stream, be it rock or pop or whatever -->

    <Genre>Bollywood</Genre>

    <!-- Longer description of your stream -->

    <Description>Default description</Description>

    <!-- URL to a page describing your stream -->

    <URL>http://localhost/</URL>

Start icecast:
icecast -c /usr/local/etc/icecast.xml

Start the two instances of ices in two separate terminals:
ices -c /usr/local/etc/jazz.conf

ices -c /usr/local/etc/bollywood.conf

Connect VLC to the two streams:
http://localhost:8000/jazz

and then
http://localhost:8443/bollywood

You should be able to hear both stations and they should get saved on the playlist.
To open up to other comps in your network, remember to use yast>firewall to open the ports. Click the advanced button and open the ports, using http as protocol.

Wednesday, January 28, 2015

How to Make a Title Card Movie out of a static image: Part 1

You can make a movie out of a static frame. This is useful for title cards, disclaimers, announcements and so on.

To make a 5 second movie with the Animation codec in a quicktime wrapper, run this command:

ffmpeg -loop 1 -r 25 -i inputcard.png -t 00:00:05 -c:v qtrle output.mov


If you want to join this later to another movie which has sound, you need to add sound tracks to this title-card movie, else the two files will not join (concatenate). You can create a silent audio track through ffmpeg and mux that into the output.mov just created.

The silent track is created through the "lavfi" format.

ffmpeg -f lavfi -i aevalsrc=0 -i output.mov -shortest -c:v copy -c:a aac -strict -2 title.mov


Now you can concatenate the "title.mov" file to the body film.