Skip to content

Instantly share code, notes, and snippets.

@m-wild
Last active May 8, 2024 17:57
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save m-wild/5df9046c5f6875a06cce8ffff27beac2 to your computer and use it in GitHub Desktop.
Save m-wild/5df9046c5f6875a06cce8ffff27beac2 to your computer and use it in GitHub Desktop.
Darkice + Icecast Docker on ARM64 Raspberry Pi
# this section describes general aspects of the live streaming session
[general]
duration = 0 # duration of encoding, in seconds. 0 means forever
bufferSecs = 1 # size of internal slip buffer, in seconds
reconnect = yes # reconnect to the server(s) if disconnected
realtime = yes # run the encoder with POSIX realtime priority
rtprio = 4 # scheduling priority for the realtime threads
# this section describes the audio input that will be streamed
[input]
device = hw:1,0 # OSS DSP soundcard device for the audio input
sampleRate = 44100 # sample rate Hz
bitsPerSample = 16 # bits per sample. try 16
channel = 2 # 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]
[icecast2-0]
bitrateMode = vbr
format = mp3
# bitrate = 320 # only with cbr and abr bitrateMode
quality = 1.0 # 0.0 lowest -> 1.0 heighest
server = localhost
port = 8000
password = hackme
mountPoint = example.mp3
name = Example Radio Station
url = https://your_fqdn_here/example.mp3
FROM debian:latest as builder
WORKDIR /app
RUN apt-get update \
&& apt-get --no-install-recommends --yes install \
ca-certificates curl wget build-essential tar pkg-config \
alsa-utils lame libmp3lame-dev libpulse-dev libjack-jackd2-dev \
libaudio-dev libasound2-dev libshout3-dev libmp3lame-dev
RUN wget https://github.com/rafael2k/darkice/releases/download/v1.4/darkice-1.4.tar.gz
RUN tar -xf darkice-1.4.tar.gz
WORKDIR /app/darkice-1.4
RUN ./configure \
CXXFLAGS="-std=c++11" \
--with-pulseaudio \
--with-lame --with-lame-prefix=/usr/lib/aarch64-linux-gnu \
--with-alsa \
--with-jack
RUN make
RUN make install
ENTRYPOINT [ "/usr/local/bin/darkice" ]
version: '3'
services:
darkice:
container_name: darkice
build: ./darkice.Dockerfile
network_mode: host # allows sending to icecast at localhost:8000
devices:
- /dev/snd:/dev/snd # alsa sound devices
cap_add:
- SYS_NICE # enables setting realtime priority
volumes:
- ./darkice.cfg:/etc/darkice.cfg
- /usr/share/alsa:/usr/share/alsa
group_add:
- '29' # ${AUDIO_GRP} permission to audio devices
icecast:
container_name: icecast
build: ./icecast.Dockerfile
ports:
- 8000:8000
volumes:
- ./icecast.xml:/etc/icecast2/icecast.xml
restart: unless-stopped
FROM debian:latest as builder
WORKDIR /app
RUN apt-get update \
&& apt-get install --yes icecast2
RUN useradd radio
RUN chown -R radio:radio /etc/icecast2 /var/log/icecast2
USER radio
EXPOSE 8000
ENTRYPOINT [ "icecast2", "-c", "/etc/icecast2/icecast.xml" ]
<icecast>
<!-- location and admin are two arbitrary strings that are e.g. visible
on the server info page of the icecast web interface
(server_version.xsl). -->
<location>Earth</location>
<admin>example@example.net</admin>
<!-- IMPORTANT!
Especially for inexperienced users:
Start out by ONLY changing all passwords and restarting Icecast.
For detailed setup instructions please refer to the documentation.
It's also available here: http://icecast.org/docs/
-->
<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>
<!-- 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>
<authentication>
<source-password>hackme</source-password>
<relay-password>hackme</relay-password>
<admin-user>admin</admin-user>
<admin-password>hackme</admin-password>
</authentication>
<!-- This is the hostname other people will use to connect to your server.
It affects mainly the urls generated by Icecast for playlists and yp
listings. You MUST configure it properly for YP listings to work!
-->
<hostname>your_fqdn_here</hostname>
<!-- You may have multiple <listen-socket> elements -->
<listen-socket>
<port>8000</port>
<!-- <bind-address>127.0.0.1</bind-address> -->
<!-- <shoutcast-mount>/stream</shoutcast-mount> -->
</listen-socket>
<!-- Global header settings
Headers defined here will be returned for every HTTP request to Icecast.
The ACAO header makes Icecast public content/API by default
This will make streams easier embeddable (some HTML5 functionality needs it).
Also it allows direct access to e.g. /status-json.xsl from other sites.
If you don't want this, comment out the following line or read up on CORS.
-->
<http-headers>
<header name="Access-Control-Allow-Origin" value="*" />
</http-headers>
<fileserve>1</fileserve>
<paths>
<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>
<!-- <playlistlog>playlist.log</playlistlog> -->
<loglevel>3</loglevel> <!-- 4 Debug, 3 Info, 2 Warn, 1 Error -->
<logsize>10000</logsize> <!-- Max size of a logfile -->
<!-- If logarchive is enabled (1), then when logsize is reached
the logfile will be moved to [error|access|playlist].log.DATESTAMP,
otherwise it will be moved to [error|access|playlist].log.old.
Default is non-archive mode (i.e. overwrite)
-->
<!-- <logarchive>1</logarchive> -->
</logging>
<security>
<chroot>0</chroot>
</security>
</icecast>
@m-wild
Copy link
Author

m-wild commented Aug 6, 2023

You may want to install alsa-utils to get the input device id

$ sudo apt-get install alsa-utils -y

$ arecord --list-devices
**** List of CAPTURE Hardware Devices ****
card 0: CODEC [USB AUDIO  CODEC], device 0: USB Audio [USB Audio]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

In this case card 0, device 0 would be hw:0,0

You can view a quick VU meter of the input

$ arecord --duration=10 --device=hw:0,0 --format=cd --vumeter=stereo /dev/null
Recording WAVE '/dev/null' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo
                                  +00%|00%+

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment