Rabarar's Blog

A blogging framework for mild hackers.

DarkIce and IceCast

| Comments

So you want to livestream audio from your Pi to the web? Take a look at these two packages: Darkice, and IceCast. Darkice lets you select a sound input to encode and stream to an IceCast server. The server will wrap the audio stream with a nice web-appropriate display to make selecting and playing content easily.


DarkIce: Audio Encoding software

First, take a look at this link describing how to compile DarkIce with mp3 support which is likely what you’re going to want.

Here’s the config file to setup DarkIce on

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# see the darkice.cfg man page for details

# this section describes general aspects of the live streaming session
[general]
duration      = 0                # duration of encoding, in seconds. 0 means forever
bufferSecs    = 5                # size of internal slip buffer, in seconds
reconnect     = yes              # reconnect to the server(s) if disconnected

# this section describes the audio input that will be streamed
[input]
device        = hw:1,0           # Alsa soundcard device for the audio input
sampleRate    = 44100            # sample rate in Hz. try 11025, 22050 or 44100
bitsPerSample = 16               # bits per sample. try 16
channel       = 1                # channels. 1 = mono, 2 = stereo

# this section describes a streaming connection to an IceCast2 server
# there may be up to 8 of these sections, named [icecast2-0] ... [icecast2-7]
# these can be mixed with [icecast-x] and [shoutcast-x] sections
[icecast2-0]
bitrateMode   = vbr              # variable bit rate
format        = mp3              # format of the stream: mp3
quality       = 0.6              # quality of the stream sent to the server
server        = localhost        # host name of the server
port          = 8000             # port of the IceCast2 server, usually 8000
password      = SOURCE_PASSWORD  # source password to the IceCast2 server
mountPoint    = raspi         # mount point of this stream on the IceCast2 server
name          = RasPi            # name of the stream
description   = DarkIce on RasPi # description of the stream
url           = http://localhost # URL related to the stream
genre         = my genre         # genre of the stream
public        = no               # advertise this stream?
localDumpFile = recording.mp3    # Record also to a file

The key element here is the [input] section. Here we specify the Alsa device from which to source audio for capturing and encoding.

The other element in the config file that you need to configure is the [icecast-2]. Set the address (server and port) as well as the password to the icecast-2 server. Note that the default configuration for the icecast-2 server is only two (2) streams. Be sure to increase that if you’re attempting to stream more than that to the server.

If you want to encode more than one stream on your Pi, you can run multiple instances of DarkIce and use the -c flag to specify a unique configuration file for each instance.

To configure Icecast, start here. The Docs are also a good starting point too. For the impatient you can just use apt-get.

1
apt-get install icecast

Comments