d4eebf79f6b79015025125749beaeb54b79e065c
- camera/capture.py: V4L2 mmap-based MJPEG frame capture with background thread - camera/mjpeg.py: MJPEG streaming server (multipart/x-mixed-replace) + minimal web UI - camera/app.py: Entry point with argument parsing and signal handling - pyproject.toml: uv project config (no external dependencies) - camera-webui.service: systemd unit for native Pi deployment - README.md: Updated for systemd-only direction with install instructions
usb-camera-webui
Live MJPEG video feed from a USB webcam, served through a minimal web UI, running on a Raspberry Pi 5.
Quick start
# Ensure the v4l2 Python bindings are installed
sudo apt install -y python3-v4l2
# Run directly
python3 -m camera.app --host 0.0.0.0 --port 8080
Open http://localhost:8080 in a browser.
Systemd service
The app runs natively on the Pi via a systemd unit.
Install
# Install the v4l2 Python bindings
sudo apt install -y python3-v4l2
# Copy the service unit
sudo cp camera-webui.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable --now camera-webui
Check status
sudo systemctl status camera-webui
journalctl -u camera-webui --follow
Uninstall
sudo systemctl disable --now camera-webui
sudo rm /etc/systemd/system/camera-webui.service
sudo systemctl daemon-reload
Architecture
┌──────────────┐ ┌──────────────┐ ┌──────────┐
│ V4L2 mmap │───▶│ capture.py │───▶│ MJPEG │
│ (V4L2 API) │ │ (frame loop)│ │ server │
└──────────────┘ └──────────────┘ │ :8080 │
└──────────┘
│
┌─────▼─────┐
│ Browser │
│ (MJPEG img)│
└───────────┘
capture.pyopens/dev/video0via V4L2 mmap buffers, dequeues frames in a background thread, and stores them in a shared variable.mjpeg.pyserves the MJPEG stream (multipart/x-mixed-replace) via Python's built-inhttp.serverwith threading. Each client gets its own thread, and only new frames are sent.app.pyis the entry point: argument parsing, signal handling, and server launch.
Hardware
| Item | Details |
|---|---|
| Camera | Logitech C505 HD Webcam (046d:08e3) |
| Device | /dev/video0 (USB/UVC) |
| Format | MJPEG 1280×720 |
| Board | Raspberry Pi 5, Debian 12 (bookworm) |
Dependencies
python3-v4l2— V4L2 Python bindings (system package,apt install python3-v4l2)- No pip packages needed — the server uses Python's standard library only
Description
USB/UVC webcam live feed + web UI on a Raspberry Pi 5. Deliberately separate from camera-webui (Orin/IMX219) so two Codex agents can work without colliding.
Languages
Python
100%