Saturday, March 25, 2017

configure streaming media server using icecast2

1- install necessary packages
$ sudo apt-get install icecast2 dir2ogg oggfwd

2- the icecast2 config file /etc/icecast2/icecast.xml should look like below
<icecast>
    <location>Earth</location>
    <admin>icemaster@localhost</admin>
    <limits>
        <clients>100</clients>
        <sources>2</sources>
        <queue-size>524288</queue-size>
        <client-timeout>30</client-timeout>
        <header-timeout>15</header-timeout>
        <source-timeout>10</source-timeout>
        <burst-on-connect>1</burst-on-connect>
        <burst-size>65535</burst-size>
    </limits>

    <authentication>
        <!-- Sources log in with username 'source' -->
        <source-password>hackme</source-password>
        <!-- Relays log in with 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>


    <hostname>localhost</hostname>

    <!-- 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>

    <http-headers>
        <header name="Access-Control-Allow-Origin" value="*" />
    </http-headers>

    <fileserve>1</fileserve>

    <paths>
        <!-- basedir is only used if chroot is enabled -->
        <basedir>/usr/share/icecast2</basedir>


        <logdir>/var/log/icecast2</logdir>
        <webroot>/usr/share/icecast2/web</webroot>
        <adminroot>/usr/share/icecast2/admin</adminroot>

        <alias source="/" destination="/status.xsl"/>

    </paths>

    <logging>
        <accesslog>access.log</accesslog>
        <errorlog>error.log</errorlog>
        <loglevel>3</loglevel> <!-- 4 Debug, 3 Info, 2 Warn, 1 Error -->
        <logsize>10000</logsize> <!-- Max size of a logfile -->

    <security>
        <chroot>0</chroot>
    </security>
</icecast>


with above configuration, we have administrator user is admin, password hackme, and password hackme to add mount point

3- restart icecast2 service
$ sudo /etc/init.d/icecast2 restart

4- for example you have a mp3 or more mp3 files in a directory call mp3, so to stream it we have to convert it to ogg format, so use the following command to convert all the file to ogg format
$ dir2ogg -d mp3

5- now we can use oggfwd to add the stream mount point with the following command
$  cat mp3/el-perdon.ogg | oggfwd localhost 8000 hackme /stream.ogg


6- after that we can see it in the mount point menu of icecast2 web admin interface
http://192.168.58.23:8000/admin/listmounts.xsl

to play it we can access
http://192.168.58.23:8000/stream.ogg with browser such as firefox

or use below command to open with vlc
$ vlc http://192.168.58.23:8000/stream.ogg

No comments:

Post a Comment