Tuesday, 27 January 2026

Birdbox Camera Server on a Pi5 Using Motion and Icecast2

This guide shows how to create a Pi5 Birdbox Camera Server, which provides separate streaming servers for both audio and video.

It does not combine the two streams together - for that, motionplus or restreamer should be investigated.



Finding the Webcam Device

To ensure that the camera can always be found, even if devices are set-up in a different order, or the device is plugged into a different USB port, we use udev, so the webcam video will always be at /dev/webcam_video, instead of /dev/video0, /dev/video1 etc.

Similarly, the audio applications can find the device using hw:CARD=webcam_audio,DEV=0 instead of hw:0,0, hw:2,0 etc.

1. Find the USB webcam

# lsusb

Bus 003 Device 002: ID 1bcf:2cc9 Sunplus Innovation Technology Inc. USB 2.0 Camera

2. Create a webcam rule file for udev, using the USB vendor and product IDs from the lsusb.

# sudo vi /etc/udev/rules.d/99-webcam.rules

# Webcam USB Device: Audio

SUBSYSTEM=="sound", ATTRS{idVendor}=="1bcf", ATTRS{idProduct}=="2cc9", ATTR{id}="webcam_audio",  SYMLINK+="webcam_audio"

# Webcam USB Device: Video

SUBSYSTEM=="video4linux", ATTRS{idVendor}=="1bcf", ATTRS{idProduct}=="2cc9", ATTR{id}="webcam_video", SYMLINK+="webcam_video"

3. Now refresh the udev subsystem

# sudo udevadm control --reload-rules
# sudo udevadm trigger

4. Finally, unplug and re-plug the USB device (or reboot)

5. Check the device is correctly installed

# ls -la /dev/webcam*

lrwxrwxrwx 1 root root 13 Jan 27 12:43 /dev/webcam_audio -> snd/controlC2
lrwxrwxrwx 1 root root  6 Jan 27 12:43 /dev/webcam_video -> video0

# arecord -l

**** List of CAPTURE Hardware Devices ****
card 2: webcam_audio [USB 2.0 Camera], device 0: USB Audio [USB Audio]
  Subdevices: 0/1
  Subdevice #0: subdevice #0

Note that the two softlinks created in /dev point to the webcam video stream device and the audio control device, and the name reported for the capture card for audio is webcam_audio.

Tthe webcam video device can be referred to as: /dev/webcam_video

And the audio hardware card/port can be referred to as: hw:CARD=webcam_audio,DEV=0


Installing and Configuring the Video Server

1. Install the motion server

# sudo apt-get install motion 

2. Use a USB Device

It may be sensible to use a USB device for capturing video and photo sequences (if they are to be enabled).  If so, plug the device in, and check its name in /media/username.  Make sure that there is a folder on the USB device that can be written to by the 'motion' user.

# sudo mkdir /media/username/device/motion
# sudo chown motion:motion /media/username/device/motion
# sudo chmod 775 /media/username/device/motion

3. Configure the server, by editing the motion.conf in the /etc area, and ensuring the following adjustments are made:

# sudo vi /etc/motion/motion.conf

# Run in foreground (because we are going to manage this with systemd)
daemon off

# Adjust this if you wish (perhaps to point to a USB mounted device)
target_dir /var/lib/motion

# Set the video device to the udev-managed /dev/webcam_video (not /dev/video0 etc.)
video_device /dev/webcam_video

# Adjust the image capture size to one of the sizes supported by the webcam
width 1920
height 1080

# Adjust the framerate to something reasonable for the camera and USB interface
framerate 20

# Text to be overlayed in the lower left corner of images
text_left BIRDBOX

# Output pictures when motion is detected
picture_output off

# Create movies of motion events.
movie_output on
4. Start the video server
# sudo systemctl start motion
# sudo systemctl enable motion
# sudo systemctl status motion

motion.service - Motion detection video capture daemon
     Loaded: loaded (/usr/lib/systemd/system/motion.service; enabled; preset: enabled)
     Active: active (running) since Mon 2026-01-26 20:39:13 GMT; 16h ago
 Invocation: c3ff5f5b74554ee9afc7e079f63b98ef
       Docs: man:motion(1)
   Main PID: 647 (motion)
      Tasks: 4 (limit: 4762)
        CPU: 18min 3.364s
     CGroup: /system.slice/motion.service
             └─647 /usr/bin/motion

Installing and Configuring the Media Server

1. Install the media server

# sudo apt-get install icecast2

2. Setup the username / password etc.

Edit the configuration file, and set a source, relay and admin username and password:

# sudo vi /etc/icecast2/icecast.xml

    <authentication>
        <!-- Sources log in with username 'source' -->
        <source-password>source</source-password>
        <!-- Relays log in with username 'relay' -->
        <relay-password>relay</relay-password>
        <!-- Admin logs in with the username given below -->
        <admin-user>admin</admin-user>
        <admin-password>admin</admin-password>
    </authentication>

3. Start the media server

# sudo systemctl start icecast2
# sudo systemctl enable icecast2
# sudo systemctl status icecast2

icecast2.service - LSB: Icecast2 streaming media server
     Loaded: loaded (/etc/init.d/icecast2; generated)
     Active: active (running) since Mon 2026-01-26 20:39:21 GMT; 16h ago
 Invocation: efcae9e49e66447385f159ac01a307db
       Docs: man:systemd-sysv-generator(8)
      Tasks: 5 (limit: 4762)
        CPU: 25.175s
     CGroup: /system.slice/icecast2.service
             └─875 /usr/bin/icecast2 -b -c /etc/icecast2/icecast.xml

 

Transferring Audio from the Webcam to the Media Servier

1. Install darkice

# sudo apt-get install darkice

2. Configure darkice

Create a new configuration file (the installation may not do this for you).  Ensure that the device matches the device configured in (udev) above.  Set the sample rates etc. to something supported by the camera, and optionally set a low pass (highest cut-off frequency) and high pass (lowest cut-off frequency) filter.

Ensure that the password listed matches the 'source' password in the icecast.xml file.

# sudo vi /etc/icecast2/darkice.cfg

[general]
duration = 0
bufferSecs = 3
reconnect = yes

[input]
device = hw:CARD=webcam_audio,DEV=0
sampleRate = 48000
bitsPerSample = 16
channel = 1

[icecast2-0]
bitrateMode = cbr
format = mp3
bitrate = 384
quality = 0.8
channel = 1
lowpass = -1
highpass = 1500
sampleRate = 48000
server = 127.0.0.1
port = 8000
password = source
mountPoint = stream
name = Birdbox Webcam

3. Ensure that the webcam microphone gain is set to 0, and it is not muted

# alsamixer

Select device with F6

Select microphone with F4

4. Configure darkice to be launched with systemd

# sudo vi /etc/systemd/system/darkice.service

[Unit]
Description=Darkice Live Audio Streamer
After=network.target
StartLimitIntervalSec=0
StartLimitBurst=1


[Service]
ExecStart=/usr/bin/darkice -c /etc/icecast2/darkice.cfg
Restart=always
RestartSec=15s
User=root

[Install]
WantedBy=multi-user.target

The StartIntervalSec=0 means that the service restart will be re-tried indefinately.

Restart attempts will be every 15 seconds until successful.  As no dependency is specified, the first start will fail (until the icecast2 server comes online), but this is automatically resolved by the restart attempt.

5. Start darkice 

# sudo systemctl start darkice
# sudo systemctl enable darkice
# sudo systemctl status darkice

darkice.service - Darkice Live Audio Streamer
     Loaded: loaded (/etc/systemd/system/darkice.service; enabled; preset: enabled)
     Active: active (running) since Mon 2026-01-26 20:46:09 GMT; 16h ago
 Invocation: 86117aad9e3c45dcb2b40c561a8aa0b2
   Main PID: 1297 (darkice)
      Tasks: 2 (limit: 4762)
        CPU: 31min 49.791s
     CGroup: /system.slice/darkice.service

             └─1297 /usr/bin/darkice -c /etc/icecast2/darkice.cfg

Check Everything is OK

Visit http://your-camera-server:8081
You should see a shot from the camera itself

Visit: http://your-camera-server:8000
Log-in as admin/admin (match the setting in icecast.xml)
You should see 2 sections:
Global Server Stats - check that "sources" = 1
Mountpoint /stream - check that it exists, and the "server_name" matches the name set in darkice.cfg

Click on the M3U file on the Mountpoint /stream section, and open it in a media player such as VLC
You should hear the audio from the microphone

Editing and Tweaking


If you edit the darkice configuration:
# sudo systemctl restart darkice

If you edit the icecast2 configuration
# sudo systemctl restart icecast2

If you edit the motion configuration
# sudo systemctl restart motion




No comments:

Post a Comment