[How To] OpenWrt - Icecast streaming server over local lan and/or internet

Tested on LEDE 17.01.6 and OpenWrt 18.06.2

note: USB /overlay extra space is needed to locally store the ".ogg" music files or else you might mount an external network storage for this (adapt music path in config files for this case).

  • install software:
opkg update
opkg install libshout ices libtheora libspeex alsa-lib kmod-sound-core kmod-input-core icecast libxslt libcurl libvorbisidec librt
opkg install wget openssl-util opkg install libustream-openssl ca-certificates
  • disable icecast autostart at boot:
/etc/init.d/icecast disable
/etc/init.d/icecast stop
  • create local user (icecast does not start as user root)
opkg install shadow-useradd
useradd pilovis
passwd pilovis
mkdir /home
mkdir /home/pilovis
chown pilovis /home/pilovis
  • remove icecast default configuration file:
cp /etc/icecast.xml /etc/icecast.xml.orig
rm  /etc/icecast.xml
  • edit new icecast configuration file:
nano /etc/icecast.xml
<icecast>

  <!-- LIMITS -->
  <limits>
    <clients>10</clients>
    <sources>10</sources>
    <threadpool>5</threadpool>
    <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>

  <!-- GENRIC -->
  <authentication>
    <source-password>changeme!</source-password>
    <admin-user>admin</admin-user>
    <admin-password>changeme!</admin-password>
  </authentication>
  <hostname>localhost</hostname>
  <listen-socket>
    <port>8000</port>
  </listen-socket>
  <fileserve>1</fileserve>

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

        <!-- Note that if <chroot> is turned on below, these paths must both
             be relative to the new root, not the original root -->
        <logdir>/tmp</logdir>
        <webroot>/usr/share/icecast/web</webroot>
        <adminroot>/usr/share/icecast/admin</adminroot>
        <!-- <pidfile>/usr/share/icecast/icecast.pid</pidfile> -->

        <!-- Aliases: treat requests for 'source' path as being for 'dest' path
             May be made specific to a port or bound address using the "port"
             and "bind-address" attributes.
          -->
        <!--
        <alias source="/foo" destination="/bar"/>
        -->
        <!-- Aliases: can also be used for simple redirections as well,
             this example will redirect all requests for http://server:port/ to
             the status page
        -->
        <alias source="/" destination="/status.xsl"/>
        <!-- The certificate file needs to contain both public and private part.
             Both should be PEM encoded.
        <ssl-certificate>/usr/share/icecast/icecast.pem</ssl-certificate>
        -->
    </paths>

  <!-- LOG -->
  <logging>
    <accesslog>access.log</accesslog>
    <errorlog>error.log</errorlog>
    <playlistlog>playlist.log</playlistlog>
    <loglevel>1</loglevel>
    <logsize>10000</logsize>
    <logarchive>1</logarchive>
  </logging>

  <!-- SECURITY -->
  <security>
    <chroot>0</chroot>
    <changeowner>
      <user>pilovis</user>
      <group>nogroup</group>
    </changeowner>
  </security>

</icecast>
  • create and edit ices configuration file:
nano /etc/ices.xml
<ices>

  <!-- GENERIC -->
  <background>1</background>
  <pidfile>/var/run/icecast/ices1.pid</pidfile>

  <!-- LOGGING -->
  <logpath>/tmp</logpath>
  <logfile>ices1.log</logfile>
  <logsize>2048</logsize>
  <loglevel>3</loglevel>
  <consolelog>0</consolelog>

  <!-- STREAM -->
  <stream>
    <metadata>
      <name>OpenWrt Radio</name>
      <genre>Varios</genre>
      <description>Local Test Radio</description>
      <url>http://openwrt:8000/</url>;
    </metadata>
    <input>
      <param name="type">basic</param>
      <param name="file">/root/playlist1.txt</param>
      <param name="random">1</param>
      <param name="once">0</param>
      <param name="restart-after-reread">1</param>
    </input>
    <instance>
      <hostname>localhost</hostname>
      <port>8000</port>
      <password>changeme!</password>
      <mount>/Radio88</mount>
    </instance>
  </stream>

</ices>
  • download some free .ogg music files in /root/music directory:

https://patrickdearteaga.com/royalty-free-music/

mkdir /root/music
cd /root/music
wget https://patrickdearteaga.com/audio/Not%20Giving%20Up.ogg
wget https://patrickdearteaga.com/audio/Spring%20Village.ogg
wget https://patrickdearteaga.com/audio/La%20Llamada%20de%20Ile.ogg
wget https://patrickdearteaga.com/audio/Las%20Dos%20Fronteras.ogg
wget https://patrickdearteaga.com/audio/Vals%20de%20su%20jard%C3%ADn%20A.ogg
wget https://patrickdearteaga.com/audio/Voices%20From%20Heaven.ogg
wget https://patrickdearteaga.com/audio/No%20Place%20For%20Straw%20Cowboys.ogg
wget https://patrickdearteaga.com/audio/Lyonesse.ogg
wget https://patrickdearteaga.com/audio/Friends.ogg
wget https://patrickdearteaga.com/audio/I%20Miss%20You.ogg
wget https://patrickdearteaga.com/audio/Kiss%20And%20Goodbye.ogg
wget https://patrickdearteaga.com/audio/2nd%20Sonata%20-%20Malign%20Chords.ogg
wget https://patrickdearteaga.com/audio/Anguish.ogg
wget https://patrickdearteaga.com/audio/Blues.ogg
wget https://patrickdearteaga.com/audio/El%20Postre.ogg
wget https://patrickdearteaga.com/audio/My%20Memory%20Lane.ogg
wget https://patrickdearteaga.com/audio/Meitpower.ogg
wget https://patrickdearteaga.com/audio/Lord%20Mavras.ogg
wget https://patrickdearteaga.com/audio/La%20Verdad.ogg
wget https://patrickdearteaga.com/audio/Helplessness%20in%20Kowasni.ogg
wget https://patrickdearteaga.com/audio/Happy%20Ending.ogg

  • create playlist file (you need to regenerate it every time you add or remove files in music directory):
rm /root/playlist1.txt
find /root/music -name "*.ogg" > /root/playlist1.txt

  • reboot the router

  • start icecast and ices:
/usr/bin/icecast -b -c /etc/icecast.xml
/usr/bin/ices /etc/ices.xml
  • test icecast streaming server from your PC:

http://router-ipaddress:8000

cpu and memory usage - OpenWrt @300 Mhz CPU & 64 Mbytes RAM (32 is enough)

 PID  PPID USER     STAT   VSZ %VSZ %CPU COMMAND
 5479     1 pilovis  S     6904  11%   1% /usr/bin/icecast -b -c /etc/icecast.xml
 5489     1 root     S     6960  12%   1% /usr/bin/ices /etc/ices.xml

note that icecast runs as normal user "pilovis" and ices as user "root"

If you have a router with just 32 Mbytes of ram memory, I would suggest you to install zram-swap package to virtually increase the available ram:

opkg update
opkg install zram-swap

ZRAM is a script to activate swaping on a compressed zram partition.
This could be used to increase the available memory, by using compressed memory.

Streaming server autostart at boot

nano /etc/rc.local


# Put your custom commands here that should be executed once
# the system init finished. By default this file does nothing.
/usr/bin/icecast -b -c /etc/icecast.xml
/bin/sleep 3
/usr/bin/ices /etc/ices.xml
/bin/sleep 3
exit 0

note: icecast and ices need some delay when launched at startup by rc.local

beautiful OpenWrt embedded web player (using uhttpd) for your Streaming server,
no client required to listen to the music, just use Firefox browser on your PC/Smartphone/Tablet to open this page and enjoy listening to the music.
This web player page has integrated start/stop and volume controls.

note. it needs an internet connection to work since the skin and the player are hosted on an external site.

thanks to: https://sourceforge.net/projects/ffmp3/ and https://www.muses.org

note that the text at the bottom between the two bars is continuously scrolling from right to left.


Instructions:

cd /www
cp index.html luci.html
rm index.html
nano index.html
<html>
 <head>
  <title>OpenWrt Radio</title>
 </head>
<body>
<hr>
<h1><i>* You're listening to OpenWrt Radio *</i></h1>
<p>
<hr>

<!-- BEGINS: AUTO-GENERATED MUSES RADIO PLAYER CODE -->
<script type="text/javascript" src="https://hosted.muses.org/mrp.js"></script>
<script type="text/javascript">
MRP.insert({
'url':'http://192.168.1.1:8000/NetRadio',
'lang':'en',
'codec':'ogg',
'volume':75,
'autoplay':true,
'jsevents':true,
'buffering':0,
'title':'Openwrt Radio',
'welcome':'Welcome',
'wmode':'transparent',
'skin':'combat',
'width':675,
'height':247
});
</script>
<!-- ENDS: AUTO-GENERATED MUSES RADIO PLAYER CODE -->

<p>
<hr>
<marquee behavior="scroll" direction="left">OpenWrt Free Radio, only royalty free music ! </marquee>
<hr>

<iframe src="http://free.timeanddate.com/clock/i5zx8pk0/n254/tlit6/fs20/ftb/tt0/td2/th1" frameborder="0" width="369" height="24"></iframe>

</body></html>

Notes:
on the above code change http://192.168.1.1:8000/NetRadio with your OpenWrt streaming router IP address
to get access to luci control panel use : http://yourRouterIP/luci.html
to get access to this player page use: http://yourRouterIP!

if you prefere hosting all files, including skin and flash player directly on the router (eg. for local streaming without internet connection), here are the files and the modified html code you need:

https://downloads.sourceforge.net/project/ffmp3/Version%201.2/muses-1.2.zip
https://www.muses.org/skins/combat.zip

unzip the above two files and put all extracted files in the /www directory of your OpenWrt router

nano /www/index.html

<html>
 <head>
  <title>OpenWrt Free Radio</title>
 </head>
<body>

<hr>
<h1><i>* You're listening to OpenWrt Free Radio *</i></h1>

<p>
<hr>

<!-- BEGINS: AUTO-GENERATED MUSES RADIO PLAYER CODE -->
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="760" height="280">
<param name="movie" value="muses.swf" />
<param name="flashvars" value="url=http://192.168.1.1:8000/NetRadio&lang=auto&codec=ogg&volume=75&introurl=&autoplay=true&tracking=true&jsevents=true&skin=ffmp3-combat.xml&title=OpenWrt%20Radio&welcome=welcome" />
<param name="wmode" value="transparent" />
<param name="allowscriptaccess" value="always" />
<param name="scale" value="noscale" />
<embed src="muses.swf" flashvars="url=http://192.168.1.1:8000/NetRadio&lang=auto&codec=ogg&volume=75&introurl=&autoplay=true&tracking=true&jsevents=true&skin=ffmp3-combat.xml&title=OpenWrt%20Radio&welcome=welcome" width="760" scale="noscale" height="280" wmode="transparent" allowscriptaccess="always" type="application/x-shockwave-flash" />
</object>
<!-- ENDS: AUTO-GENERATED MUSES RADIO PLAYER CODE -->

<hr>
<marquee behavior="scroll" direction="left">OpenWrt Free Radio, only royalty free music ! </marquee>
<hr>

<iframe src="http://free.timeanddate.com/clock/i5zx8pk0/n254/tlit6/fs20/ftb/tt0/td2/th1" frameborder="0" width="369" height="24"></iframe>
</body></html>

hello,
could you help?

set up the icecast and running but songs not showing up

<ices>

  <!-- GENERIC -->
  <background>1</background>
  <pidfile>/var/run/icecast/ices1.pid</pidfile>

  <!-- LOGGING -->
  <logpath>/tmp</logpath>
  <logfile>ices1.log</logfile>
  <logsize>2048</logsize>
  <loglevel>3</loglevel>
  <consolelog>0</consolelog>

  <!-- STREAM -->
  <stream>
    <metadata>
      <name>Vicinity Radio</name>
      <genre>Various</genre>
      <description>Local Vicinity Music</description>
      <url>http://freeaccess.vicinity:8000/mizik/songs</url>;
    </metadata>
    <input>
      <param name="type">basic</param>
      <param name="file">/mnt/sda1/vicinityweb/mizik/songs/playlist1.txt</param>
      <param name="random">1</param>
      <param name="once">0</param>
      <param name="restart-after-reread">1</param>
    </input>
    <instance>
      <hostname>FreeAccess.Vicinity</hostname>
      <port>8000</port>
      <password>lololo</password>
      <mount>/Radio88</mount>
    </instance>
  </stream>

</ices>
<icecast>

  <!-- LIMITS -->
  <limits>
    <clients>10</clients>
    <sources>10</sources>
    <threadpool>5</threadpool>
    <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>

  <!-- GENRIC -->
  <authentication>
    <source-password>lololo</source-password>
    <admin-user>admin</admin-user>
    <admin-password>lololo</admin-password>
  </authentication>
  <hostname>freeaccess.vicinity</hostname>
  <listen-socket>
    <port>8000</port>
  </listen-socket>
  <fileserve>1</fileserve>

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

        <!-- Note that if <chroot> is turned on below, these paths must both
             be relative to the new root, not the original root -->
        <logdir>/tmp</logdir>
        <webroot>/usr/share/icecast/web</webroot>
        <adminroot>/usr/share/icecast/admin</adminroot>
        <!-- <pidfile>/usr/share/icecast/icecast.pid</pidfile> -->

        <!-- Aliases: treat requests for 'source' path as being for 'dest' path
             May be made specific to a port or bound address using the "port"
             and "bind-address" attributes.
          -->
        <!--
        <alias source="/foo" destination="/bar"/>
        -->
        <!-- Aliases: can also be used for simple redirections as well,
             this example will redirect all requests for http://server:port/ to
             the status page
        -->
        <alias source="/" destination="/status.xsl"/>
        <!-- The certificate file needs to contain both public and private part.
             Both should be PEM encoded.
        <ssl-certificate>/usr/share/icecast/icecast.pem</ssl-certificate>
        -->
    </paths>

  <!-- LOG -->
  <logging>
    <accesslog>access.log</accesslog>
    <errorlog>error.log</errorlog>
    <playlistlog>playlist.log</playlistlog>
    <loglevel>1</loglevel>
    <logsize>10000</logsize>
    <logarchive>1</logarchive>
  </logging>

  <!-- SECURITY -->
  <security>
    <chroot>0</chroot>
    <changeowner>
      <user>music</user>
      <group>nogroup</group>
    </changeowner>
  </security>

</icecast>
/mnt/sda1/vicinityweb/mizik/songs/06. Something Human.mp3
/mnt/sda1/vicinityweb/mizik/songs/14. Propaganda (Acoustic Version).mp3
/mnt/sda1/vicinityweb/mizik/songs/09. Blockades.mp3
/mnt/sda1/vicinityweb/mizik/songs/15. Something Human (Acoustic Version).mp3
/mnt/sda1/vicinityweb/mizik/songs/10. Dig Down.mp3
/mnt/sda1/vicinityweb/mizik/songs/04. Propaganda.mp3
/mnt/sda1/vicinityweb/mizik/songs/03. Pressure.mp3
/mnt/sda1/vicinityweb/mizik/songs/13. The Dark Side (Alternate Reality Version).mp3
/mnt/sda1/vicinityweb/mizik/songs/16. Dig Down (Acoustic Gospel Version).mp3
/mnt/sda1/vicinityweb/mizik/songs/11. The Void.mp3
/mnt/sda1/vicinityweb/mizik/songs/05. Break it to Me.mp3
/mnt/sda1/vicinityweb/mizik/songs/02. The Dark Side.mp3
/mnt/sda1/vicinityweb/mizik/songs/08. Get Up and Fight.mp3
/mnt/sda1/vicinityweb/mizik/songs/01.Algorithm.mp3
/mnt/sda1/vicinityweb/mizik/songs/07. Thought Contagion.mp3
/mnt/sda1/vicinityweb/mizik/songs/12. Algorithm (Alternate Reality Version).mp3

have you created the playlist file?

Also note that the new IceS 2.x supports sending only Ogg Vorbis stream to an Icecast server, unfortunately it does not support MP3 streams anymore :frowning:

Yes, thats what ive found while documenting the issue.
thanks.

must amend the title
how-to-openwrt-icecast-oggfiles-streaming-server-over-local-lan-and-or-internet