Keep an eye on your pets while you're away. A lightweight streaming server for Raspberry Pi cameras.
Petcam captures video from a CSI camera (Raspberry Pi Camera Module) and streams it over HTTP using HLS (HTTP Live Streaming). It automatically starts streaming when someone connects and stops after a period of inactivity. Can run as a standalone process or as a systemd service for automatic startup and crash recovery.
- On-demand streaming: Stream starts only when a viewer connects
- Auto-stop: Automatically stops after 30 seconds of inactivity
- HLS delivery: Compatible with any browser or HLS player
- Hardware acceleration: Uses
rpicam-vidwith built-in hardware acceleration on Pi - Systemd service: Includes systemd service template for automatic startup at boot and crash recovery
- LED indicator: Built-in LED lights up when camera is active (Raspberry Pi ACT LED by default)
- Raspberry Pi:
rpicam-vid(libcamera), FFmpeg - Local dev: Go 1.25+, FFmpeg, Webcam (V4L2 on Linux, AVFoundation on macOS)
- Raspberry Pi Zero 2 W
Builds for local development using your webcam (V4L2 on Linux, AVFoundation on macOS) and starts the server:
make runThis compiles the binary and immediately starts the server on port 8080.
Prerequisites on the Pi:
sudo apt install ffmpegDeploys to mk@rpi by default:
# Builds and deploys to rpi:~/petcam/
makeDeploy to a different host or with a different LED:
make REMOTE_HOST=raspberrypi.local REMOTE_USER=pi
make LED_NAME=led0 # Use a different LED (default: ACT)After deploying, SSH into the Pi and run the install script (one-time setup):
~/petcam/scripts/install.shThis script will:
- Disable default built-in LED behavior in config.txt file
- Create service that sets up LED permissions on system startup (so petcam can control the LED without root)
- Install and enable the petcam as a service
- Reboot Pi to apply changes from the config.txt file
The petcam service will start automatically after reboot.
View logs:
journalctl -u petcam -f # Live logs
journalctl -u petcam --since today # Today's logs
journalctl -u petcam -n 50 # Last 50 linesManage the service:
sudo systemctl stop petcam # Stop service
sudo systemctl restart petcam # Restart service
sudo systemctl disable petcam # Disable auto-start
~/petcam/scripts/uninstall.sh # Remove services completelyThe Raspberry Pi ACT LED can indicate when the camera is streaming. The install script automatically sets this up. The LED lights up when streaming starts and turns off when it stops.
Disable LED control:
To deploy without LED control (skips LED permissions setup):
make LED_NAME=""Or run manually without LED control:
~/petcam/petcam # LED control disabled (default)Using a different LED:
To use a different LED (from /sys/class/leds/):
make LED_NAME=led0The Makefile will automatically replace ACT with your LED name in both the service file and the LED permissions script.
Once running, open http://localhost:8080/ to get the HLS playlist, or use with any HLS player:
ffplay http://localhost:8080/The easy and secure way to access the camera from outside your network is using Tailscale:
- Install Tailscale on the Pi:
curl -fsSL https://tailscale.com/install.sh | sh - Start Tailscale:
sudo tailscale up - Install Tailscale on your phone/laptop
- Access using the Pi's Tailscale machine name or IP:
http://rpi:8080orhttp://<tailscale-ip>:8080
Benefits: No port forwarding, automatic encryption, works behind NAT.
| Command | Description |
|---|---|
make run |
Build and run locally |
make dev |
Build for local development |
make |
Build and deploy (binary + service file) to Raspberry Pi |
make LED_NAME=led0 |
Deploy using a different LED (default: ACT) |
make LED_NAME="" |
Deploy without LED control |
make test |
Run tests with race detection |
make clean |
Remove build artifacts |
├── main.go # HTTP server
├── streamer/ # Streaming logic
│ ├── streamer.go # Stream lifecycle management
│ ├── process.go # FFmpeg wrapper
│ ├── settings.go # Configuration struct
│ └── led.go # LED control
├── scripts/ # Streaming shell scripts and systemd service
│ ├── stream_pi.sh # Raspberry Pi streaming
│ ├── stream_dev.sh # Development streaming
│ ├── install.sh.template # Installation script template
│ ├── petcam.service.template # Systemd service template
└── Makefile # Build automation
MIT