Operating System BSD

Radio Streaming on FreeBSD 15 with Icecast and IceS

Install Icecast and the IceS source client on FreeBSD 15, run them as an unprivileged user and stream a playlist of Ogg Vorbis files to listeners.

This guide sets up an internet radio station on FreeBSD 15 (the same steps work on FreeBSD 14): an Icecast server that listeners connect to, and the IceS source client that plays a playlist of Ogg Vorbis files into it around the clock. At the end you will have a stream at http://example.com:8000/radio.ogg that opens in a browser, VLC or any other player, with both programs running as an unprivileged user and starting at boot.

Three pieces are involved, and it helps to keep them apart:

Source client (IceS)  -->  Icecast server  -->  Listeners (browser, VLC, ...)

Icecast is only the hub: it accepts audio from source clients on a mount point and relays it to everyone who connects. IceS reads files and feeds them to that mount point. Run all commands below as root.

Requirements

  • A FreeBSD 15 server with root access and an up-to-date package set (pkg update && pkg upgrade).
  • TCP port 8000 reachable from the internet. If you filter traffic with PF, add a rule such as pass in proto tcp to port 8000.
  • Audio you are allowed to broadcast. Public streaming of commercial music normally requires a licence in most countries.
  • Bandwidth: every listener receives the full stream. Fifty listeners on a 128 kbit/s stream use about 6.4 Mbit/s for as long as they stay connected, so check your monthly traffic allowance.

Install Icecast and IceS

Both programs are available as binary packages, so there is no need to build from ports:

pkg install icecast ices

At the time of writing the FreeBSD ports tree carries Icecast 2.5.0 and IceS 2.0.3. The ices package is IceS 2, which produces Ogg Vorbis streams only; MP3 is covered in the FAQ at the end.

Icecast refuses to run as root, so create one unprivileged account that both programs will use, plus the log directories:

pw useradd icecast -d /nonexistent -s /usr/sbin/nologin -c "Icecast streaming"
mkdir -p /var/log/icecast /var/log/ices
chown icecast:icecast /var/log/icecast /var/log/ices

Configure Icecast

The package installs a sample configuration. Copy it and restrict access, because it will contain passwords:

cp /usr/local/etc/icecast.xml.sample /usr/local/etc/icecast.xml
chown root:icecast /usr/local/etc/icecast.xml
chmod 640 /usr/local/etc/icecast.xml

Open /usr/local/etc/icecast.xml in an editor (ee is in the base system) and change the following. Everything else can stay at its default.

Host name and passwords

Set <hostname> to the name listeners use to reach the server; Icecast puts it into the playlist URLs it generates. Then replace every hackme in the <authentication> block with a different, long password:

<hostname>example.com</hostname>

<authentication>
    <source-password>CHANGE-source-password</source-password>
    <relay-password>CHANGE-relay-password</relay-password>
    <admin-user>admin</admin-user>
    <admin-password>CHANGE-admin-password</admin-password>
</authentication>

The source password is what IceS uses to send audio. The admin account protects the web interface under /admin/.

Log directory and user

In the <paths> block, make sure <logdir> points at the directory you created:

<logdir>/var/log/icecast</logdir>

Near the end of the file, inside <security>, the <changeowner> block is commented out. Remove the <!-- and --> around it and enter the account created above. The service will not start without this block:

<security>
    <chroot>false</chroot>
    <changeowner>
        <user>icecast</user>
        <group>icecast</group>
    </changeowner>
    ...
</security>

The <limits> block near the top allows 100 clients and 2 sources by default. Raise <clients> if you expect more listeners, and <sources> if you add more mount points.

Start the server

sysrc icecast_enable=YES
service icecast start

Check that it is listening and answering:

sockstat -4l | grep 8000
fetch -qo - http://127.0.0.1:8000/status-json.xsl

The second command prints a short JSON document describing the server. If the service does not stay up, read /var/log/icecast/error.log; a log directory the icecast user cannot write to and a still-commented <changeowner> block are the two usual causes.

Prepare the music and the playlist

Create a directory for the audio files and copy your tracks into it:

mkdir -p /usr/local/radio/music

IceS 2 reads Ogg Vorbis files. If your library is MP3 or FLAC, convert it first, either on your own computer or on the server with FFmpeg:

pkg install ffmpeg
cd /usr/local/radio/music
for f in *.mp3; do ffmpeg -i "$f" -vn -c:a libvorbis -q:a 4 -ar 44100 -ac 2 "${f%.mp3}.ogg"; done

Encoding every file with the same sample rate and channel count (44.1 kHz stereo here) matters: players handle a stream whose format never changes far more reliably.

The playlist is a plain text file with one path per line, played from top to bottom:

find /usr/local/radio/music -name '*.ogg' | sort > /usr/local/radio/playlist.txt
chown -R icecast:icecast /usr/local/radio

Configure IceS

The package ships example configurations in /usr/local/share/ices. Start from the playlist example:

cp /usr/local/share/ices/ices-playlist.xml /usr/local/etc/ices.xml
chown root:icecast /usr/local/etc/ices.xml
chmod 640 /usr/local/etc/ices.xml

Edit /usr/local/etc/ices.xml. The values to change are:

<logpath>/var/log/ices</logpath>
<loglevel>3</loglevel>

<metadata>
    <name>Example Radio</name>
    <genre>Various</genre>
    <description>Music from example.com</description>
</metadata>

<input>
    <module>playlist</module>
    <param name="type">basic</param>
    <param name="file">/usr/local/radio/playlist.txt</param>
    <param name="random">1</param>
    <param name="restart-after-reread">0</param>
    <param name="once">0</param>
</input>

<instance>
    <hostname>localhost</hostname>
    <port>8000</port>
    <password>CHANGE-source-password</password>
    <mount>/radio.ogg</mount>
    <yp>0</yp>
    <reconnectdelay>10</reconnectdelay>
    <reconnectattempts>-1</reconnectattempts>
    <maxqueuelength>80</maxqueuelength>
</instance>
  • password must match <source-password> in icecast.xml.
  • mount is the path listeners will open. It must start with /, and ending it in .ogg helps players recognise the format.
  • random set to 1 shuffles the playlist; leave it at 0 to play in file order.
  • reconnectattempts set to -1 makes IceS keep retrying if Icecast restarts.
  • The example file also contains an <encode> block inside <instance>. Delete it to send your files as they are, which costs almost no CPU. Keep it only if you want IceS to re-encode to a lower bitrate; its samplerate and channels must then match the files exactly.

Start streaming

IceS takes the configuration file as its only argument. Launch it as the icecast user, detached from your terminal, with daemon(8):

daemon -u icecast /usr/local/bin/ices /usr/local/etc/ices.xml

Confirm that it connected:

tail /var/log/ices/ices.log
fetch -qo - http://127.0.0.1:8000/status-json.xsl

The status output now lists a source with /radio.ogg as its mount. Open http://example.com:8000/ in a browser to see the Icecast status page, and http://example.com:8000/radio.ogg in a browser or media player to listen. To stop the source client:

pkill -u icecast -x ices

The package does not include an rc script for IceS. The simplest way to start it at boot is an @reboot entry in root's crontab (crontab -e), delayed a little so Icecast is up first:

@reboot sleep 20 && /usr/sbin/daemon -u icecast /usr/local/bin/ices /usr/local/etc/ices.xml

Day-to-day maintenance

  • Adding tracks: copy the new .ogg files into /usr/local/radio/music, rerun the find command to rebuild playlist.txt, then restart IceS (pkill, then the daemon command) so it loads the new list.
  • Listener statistics: log in at http://example.com:8000/admin/ with the admin account to see current listeners per mount and to disconnect clients or sources.
  • Configuration changes: service icecast reload rereads icecast.xml without dropping listeners for most settings; use service icecast restart after changing ports or the user.
  • Logs: Icecast writes access.log and error.log to /var/log/icecast; IceS writes ices.log to /var/log/ices.
  • Updates: pkg upgrade followed by a restart of both programs. Your edited configuration files are not overwritten; compare them with the new .sample file after a major Icecast upgrade.

The full list of server options is in the Icecast documentation.

Frequently asked questions

Can I stream MP3 instead of Ogg Vorbis?

Icecast itself relays MP3, AAC, Opus and Ogg Vorbis, but IceS 2 only produces Ogg Vorbis. For other formats, replace IceS with a different source client. FFmpeg can send to an Icecast mount directly through its icecast:// output protocol, and Liquidsoap is a common choice when you need scheduling, jingles or live handover.

Why does IceS exit with a "bad password" or connection error?

The <password> in ices.xml does not match <source-password> in icecast.xml, Icecast is not running yet, or the source limit has been reached. Check /var/log/icecast/error.log; it records every rejected source connection with the reason.

How do I broadcast a live input instead of files?

IceS can read from a sound card through OSS: start from /usr/local/share/ices/ices-oss.xml instead of the playlist example. A VPS has no sound card, so for live shows the usual arrangement is a source client on the presenter's computer that connects to your Icecast server with the source password, on its own mount point.

Should listeners connect over HTTPS?

If the player is embedded in an HTTPS website, browsers block a plain HTTP stream as mixed content. Icecast can serve TLS itself: add a second <listen-socket> with a <tls> setting and point <tls-certificate> in the <security> block at a PEM file containing your certificate and key. The commented examples in icecast.xml.sample show the syntax.

Share story:

Continue reading other guides on How VPS.