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/1Subdevice #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
# sudo systemctl start motion# sudo systemctl enable motion# sudo systemctl status motionmotion.service - Motion detection video capture daemonLoaded: loaded (/usr/lib/systemd/system/motion.service; enabled; preset: enabled)Active: active (running) since Mon 2026-01-26 20:39:13 GMT; 16h agoInvocation: c3ff5f5b74554ee9afc7e079f63b98efDocs: man:motion(1)Main PID: 647 (motion)Tasks: 4 (limit: 4762)CPU: 18min 3.364sCGroup: /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 icecast2icecast2.service - LSB: Icecast2 streaming media serverLoaded: loaded (/etc/init.d/icecast2; generated)Active: active (running) since Mon 2026-01-26 20:39:21 GMT; 16h agoInvocation: efcae9e49e66447385f159ac01a307dbDocs: man:systemd-sysv-generator(8)Tasks: 5 (limit: 4762)CPU: 25.175sCGroup: /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 darkicedarkice.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
Editing and Tweaking
# sudo systemctl restart darkice
# sudo systemctl restart icecast2
# sudo systemctl restart motion



No comments:
Post a Comment