Turn your Raspberry Pi into a low-latency home security camera using the V4L2 DMA hardware encoder and WebRTC. [demo video]
- Pure P2P-based camera allows video playback and download without a media server.
- Support multiple users for simultaneous live streaming.
- Support signaling via WHEP or MQTT.
To set up the environment, please check out the tutorial video or the steps below.
- Download and run the binary file from Releases.
- Set up the network configuration and create a new client using one of the following options:
- Pi Camera app (Android).
- Pi Camera Web.
- Javascript client
- PiCamera.js (For MQTT).
- eyevinn/webrtc-player (For WHEP).
- Raspberry Pi (Zero 2W/3/3B+/4B/5).
- CSI or USB Camera Module.
Use the Raspberry Pi Imager to install Raspberry Pi Lite OS on your microSD card.
Tip
Can I use a regular Raspberry Pi OS, or does it have to be Lite?
You can use either the Lite or full Raspberry Pi OS (the official recommended versions), but Lite OS is generally more efficient.
sudo apt install libmosquitto1 pulseaudio libavformat59 libswscale6
wget https://github.com/TzuHuanTai/RaspberryPi_WebRTC/releases/download/v1.0.2/pi_webrtc-1.0.2_pi-os-bookworm.tar.gz
tar -xzf pi_webrtc-1.0.2_pi-os-bookworm.tar.gz
An MQTT server is required for communication between devices. For remote access, free cloud options include HiveMQ and EMQX.
Tip
Is MQTT registration necessary, and why is MQTT needed?
MQTT is one option for signaling P2P connection information between your camera and the client UI. WHEP, on the other hand, runs an HTTP service locally and does not require a third-party server. It is only suitable for devices with a public hostname. If you choose to self-host an MQTT server (e.g., Mosquitto) and need to access the signaling server remotely via mobile data, you may need to set up DDNS, port forwarding, and SSL/TLS.
- Set up the MQTT settings on your Pi Camera App or Pi Camera Web, and create a new device in the settings to get a
UID
. - Run the command based on your network settings and
UID
on the Raspberry Pi:./pi_webrtc \ --use_libcamera \ --fps=30 \ --width=1280 \ --height=960 \ --hw_accel \ --no_audio \ --mqtt_host=your.mqtt.cloud \ --mqtt_port=8883 \ --mqtt_username=hakunamatata \ --mqtt_password=Wonderful \ --uid=your-custom-uid
Important
The --hw_accel
flag is used for Pi Zero 2W, 3, 3B+, and 4B. For Pi 5 or other SBCs without a hardware encoder, run this command in software encoding mode by removing the --hw_accel
flag.
- Go to the Live page to enjoy real-time streaming!
- Recording
- Two-way communication
- Legacy V4L2 driver for usb camera
- Run as a background service
- WHEP with Nginx proxy
This project is licensed under the Apache License, Version 2.0. See the LICENSE file for details.
Copyright 2022 Tzu Huan Tai (Author)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.