This page covers setting up self-hosted multicamera backyard surveillance system.
The system consists of multiple Raspberry Pi devices connected to a common local network. One device called the hub receives video streams and produces seekable HLS streams and at the same time saves video segments to disk. Other devices called camera devices transmit video streams from a camera to the hub device. The idea is that the hub device is installed inside and camera devices are mounted outside in electrical boxes with Ethernet and PoE.
Repeat the following steps for every camera device.
Parts:
Tools:
Wiring: TODO
We will use the firmware interface for communication with the Raspberry Pi camera. It's because the new blob-free libcamera interface is still experimental and I wasn't able to get it to work on Alpine Linux.
Download files with firmware blobs that contain camera drivers and codecs. But first, to edit OS files, the partition needs to be remounted read-write.
mount /media/mmcblk0p1 -o rw,remount
apk add curl
curl 'https://raw.githubusercontent.com/raspberrypi/firmware/master/boot/start_x.elf' > /media/mmcblk0p1/start_x.elf
curl 'https://raw.githubusercontent.com/raspberrypi/firmware/master/boot/fixup_x.dat' > /media/mmcblk0p1/fixup_x.dat
Instruct to load firmware to the VideoCore GPU before boot.
echo "start_file=start_x.elf" >> /media/mmcblk0p1/config.txt
echo "fixup_file=fixup_x.dat" >> /media/mmcblk0p1/config.txt
If your camera is already connected, just reboot
.
Of not, poweroff
, disconnect power, connect camera and connect power.
After reboot, verify if you are able to obtain images from the camera.
apk add raspberrypi
/opt/vc/bin/raspivid -t 0
You should be able to see a video feed via Pi's HDMI.
We will use raspivid's tcp output to send live video to the camera hub device.
Create /etc/init.d/raspivid
with the following contents.
#!/sbin/openrc-run
name=raspivid
command="/opt/vc/bin/$name"
command_args="$raspivid_opts"
command_user="raspivid:raspivid"
supervisor=supervise-daemon
respawn_delay=1
respawn_max=0
depend() {
need net
after firewall
}
start_pre() {
[ -n "$output_log" ] && checkpath -f "$output_log" \
-m 644 -o raspivid:raspivid
[ -n "$error_log" ] && checkpath -f "$error_log" \
-m 644 -o raspivid:raspivid
}
Make it executable and add this file to LBU.
chmod +x /etc/init.d/raspivid
lbu add /etc/init.d/raspivid
Create /etc/conf.d/raspivid
with the following contents.
These parameters can be tuned.
Set the --output
to the address of your hub device and adjust the
--annotate
option to reflect the name of the camera.
raspivid_opts=" \
--nopreview \
--output tcp://192.168.1.10:8083 \
--timeout 0 \
--flush \
--codec H264 \
--rotation 180 \
--mode 4 \
--annotate $(( 1024 | 8 | 4 )) \
--annotate '%Y-%m-%d %X ROAD' \
--bitrate 0 \
--width 1640 \
--height 1232 \
--qp 25 \
--framerate 15 \
"
output_log=/var/log/raspivid.log
error_log=/var/log/raspivid.log
Add required raspivid user and add it to video
group.
addgroup -S raspivid
adduser -SDh/dev/null -s/sbin/nologin -Graspivid -graspivid raspivid raspivid
adduser raspivid video
Start the service, enable starting it on boot and save changes.
rc-service raspivid start
rc-update add raspivid
lbu commit -d
TODO
commit 8bdf3a5d5e337a801660bceb0913cbcd427596ba Author: Krystian ChachuĊa <krystian@krystianch.com> Date: 2023-11-22T20:13:32+01:00 Add chrony makestep