Rust-based door camera system with motion detection, capture, live streaming, and display/touch integration. This project is designed for a Raspberry Pi 4 running Raspbian OS with a HyperPixel 4.0 screen.
- Motion detection on a rolling ring buffer (pre/post-roll recording).
- MJPEG streaming server with a simple HTML viewer.
- Motion-triggered capture to WAL, optional JPEG frames, MP4 encoding, and metadata.
- Display output for HyperPixel-style framebuffers with backlight control.
- Touch input to wake/keep the display active.
- Event bus + orchestrator to coordinate components.
- CLI modes for config printing, validation, and dry runs.
- Complete the Raspberry Pi setup steps below.
- Review or copy
doorcam.toml. - Build and run:
cargo build --release
./target/release/doorcam --config doorcam.toml
Common CLI options:
./target/release/doorcam --print-config
./target/release/doorcam --validate-config --config doorcam.toml
./target/release/doorcam --debug --enable-keyboard
Keyboard debug mode (optional):
SPACEtriggers a motion eventQorESCshuts down
The MJPEG server exposes:
- Viewer:
http://<ip>:8080/ - Stream:
http://<ip>:8080/stream.mjpg - Health:
http://<ip>:8080/health
The bind address and port are controlled by stream.ip and stream.port.
By default, captures go to ./captures.
Typical outputs:
- WAL files:
./captures/wal/<event_id>.wal - MP4 files:
./captures/<event_id>.mp4(whencapture.video_encoding = true) - JPEG frames:
./captures/<event_id>/frames/*.jpg(whencapture.keep_images = true) - Metadata:
./captures/metadata/<event_id>.json(whencapture.save_metadata = true)
waltool converts WAL files into images/video/metadata.
cargo run --bin waltool -- --input ./captures/wal
cargo run --bin waltool -- --input ./captures/wal/20240101_120000_123.wal --video --images --metadata
Configuration is loaded from doorcam.toml (optional) and environment variables with the DOORCAM_ prefix.
Examples:
DOORCAM_CAMERA_INDEX=1
DOORCAM_CAMERA_RESOLUTION="[1280, 720]"
DOORCAM_STREAM_PORT=9090
DOORCAM_CAPTURE_PATH="/var/lib/doorcam/captures"
DOORCAM_EVENT_PREROLL_SECONDS=3
DOORCAM_EVENT_POSTROLL_SECONDS=8
Key sections:
camera: device index, resolution, fps, format.analyzer: motion detection fps and thresholds.event: pre/post-roll timing.capture: output path, timestamp overlay, encoding options.stream: bind ip/port and optional rotation.display: framebuffer/backlight/touch devices and activation period.system: retention and cleanup options.
Run --print-config for the built-in defaults.
An example service file is provided at systemd/doorcam.service.
Typical setup:
- Install the binary (example):
sudo install -m 755 ./target/release/doorcam /usr/local/bin/doorcam
- Create config + data directories:
sudo install -d -m 755 /etc/doorcam /var/lib/doorcam
sudo cp doorcam.toml /etc/doorcam/doorcam.toml
- Create a service user and grant device access:
sudo useradd --system --home /var/lib/doorcam --shell /usr/sbin/nologin doorcam
sudo usermod -aG video,input doorcam
- Install the service file and start it:
sudo cp systemd/doorcam.service /etc/systemd/system/doorcam.service
sudo systemctl daemon-reload
sudo systemctl enable --now doorcam.service
Edit the service file if your binary or config paths differ.
- Start from Raspberry Pi OS (Bullseye or newer) and run system updates:
sudo apt update
sudo apt upgrade -y
- Install build and runtime dependencies:
sudo apt install -y \
build-essential pkg-config git \
gstreamer1.0-tools gstreamer1.0-plugins-base \
gstreamer1.0-plugins-good gstreamer1.0-plugins-bad \
gstreamer1.0-plugins-ugly gstreamer1.0-libav \
libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev \
ffmpeg v4l-utils
- Enable the HyperPixel 4.0 overlay in
/boot/config.txt:
sudo sed -i '$a dtoverlay=hyperpixel4' /boot/config.txt
Reboot after adding the overlay:
sudo reboot
- Verify devices:
ls /dev/video0
ls /dev/fb0
ls /dev/input/event0
Note: the camera should appear as a USB V4L2 device (e.g., /dev/video0).
5. Adjust doorcam.toml for device paths if they differ:
display.framebuffer_device(default/dev/fb0)display.backlight_devicedisplay.touch_device
- Build and run Doorcam (see Quick start).
Target platform:
- Raspberry Pi 4 running Raspbian OS.
- HyperPixel 4.0 display (framebuffer + touch input).
- USB V4L2 camera device (e.g.,
/dev/video0). - GStreamer and FFmpeg with
h264_v4l2m2mfor hardware-accelerated encoding.
cargo test
Logging:
RUST_LOG=doorcam=debug ./target/release/doorcam --config doorcam.toml
MIT. See LICENSE.
This project was created with the assistance of agentic AI.