https://github.com/TzuHuanTai/RaspberryPi-WebRTC
Turn your Raspberry Pi into a low-latency home security camera by using native WebRTC with the v4l2 hardware H.264 encoder and the software-based OpenH264 encoder for live video stream.
https://github.com/TzuHuanTai/RaspberryPi-WebRTC
cpp encoding ffmpeg h264 libcamera raspberry-pi security-camera v4l2 video webrtc webrtc-video
Last synced: 10 days ago
JSON representation
Turn your Raspberry Pi into a low-latency home security camera by using native WebRTC with the v4l2 hardware H.264 encoder and the software-based OpenH264 encoder for live video stream.
- Host: GitHub
- URL: https://github.com/TzuHuanTai/RaspberryPi-WebRTC
- Owner: TzuHuanTai
- License: apache-2.0
- Created: 2022-05-09T06:06:35.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2025-04-08T03:34:43.000Z (26 days ago)
- Last Synced: 2025-04-09T11:05:09.655Z (24 days ago)
- Topics: cpp, encoding, ffmpeg, h264, libcamera, raspberry-pi, security-camera, v4l2, video, webrtc, webrtc-video
- Language: C++
- Homepage:
- Size: 27.5 MB
- Stars: 857
- Watchers: 3
- Forks: 37
- Open Issues: 19
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
- awesome-repositories - TzuHuanTai/RaspberryPi-WebRTC - Turn your Raspberry Pi into a low-latency home security camera by using native WebRTC with the v4l2 hardware H.264 encoder and the software-based OpenH264 encoder for live video stream. (C++)
README
Raspberry Pi WebRTC
![]()
Turn your Raspberry Pi into a low-latency security camera using the hardware encoder and WebRTC.
- Supports real-time adjustment of camera parameters and video recording download.
- Support [multiple users](doc/pi_4b_users_demo.gif) for simultaneous live streaming.
- Support signaling**MQTT**
* [picamera.js](https://www.npmjs.com/package/picamera.js)
* [picamera-react-nadive](https://www.npmjs.com/package/picamera-react-native)
* [picamera-app](https://github.com/TzuHuanTai/picamera-app) *(demo application)*
* [picamera-web](https://picamera.live) *(demo application)***[WHEP](https://www.ietf.org/archive/id/draft-ietf-wish-whep-02.html)**
* [Home Assistant](https://www.home-assistant.io)
* [eyevinn/webrtc-player](https://www.npmjs.com/package/@eyevinn/webrtc-player)
- 🎥 [Watch demo](https://www.youtube.com/watch?v=JZ5bcSAsXog)# Quick Start
To set up the environment, please check out the [tutorial video](https://youtu.be/g5Npb6DsO-0) or the steps below.
## Hardware Requirements
* Raspberry Pi (Zero 2W/3B/3B+/4B/5).
* CSI or USB Camera Module.## Environment Setup
### 1. Install Raspberry Pi OS
Use the [Raspberry Pi Imager](https://www.raspberrypi.com/software/) to install Raspberry Pi Lite OS on your microSD card.
💡 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.
### 2. Install Dependencies
```bash
sudo apt update
sudo apt full-upgrade
sudo apt install libmosquitto1 pulseaudio libavformat59 libswscale6
```### 3. Download & Unpack
Prepare the binary file from [Releases](https://github.com/TzuHuanTai/RaspberryPi_WebRTC/releases).
```bash
wget https://github.com/TzuHuanTai/RaspberryPi_WebRTC/releases/latest/download/pi_webrtc-v1.0.6-rc.3_raspios-bookworm-arm64.tar.gz
tar -xzf pi_webrtc-v1.0.6-rc.3_raspios-bookworm-arm64.tar.gz
```### 4. Set Up MQTT
You can use a free cloud MQTT service like [HiveMQ](https://www.hivemq.com) or [EMQX](https://www.emqx.com/en), or set up your own self-hosted broker.
💡 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](doc/SETUP_MOSQUITTO.md)) and need to access the signaling server remotely via mobile data, you may need to set up DDNS, port forwarding, and SSL/TLS.
## Running the Application
* Set up the MQTT settings on your [Pi Camera App](https://github.com/TzuHuanTai/Pi-Camera-App) or [Pi Camera Web](https://picamera.live), and create a new device in the **Settings** page to get a `UID`.
* Run the command based on your network settings and `UID` on the Raspberry Pi:
```bash
./pi_webrtc \
--camera=libcamera:0 \
--fps=30 \
--width=1280 \
--height=960 \
--use_mqtt \
--mqtt_host=your.mqtt.cloud \
--mqtt_port=8883 \
--mqtt_username=hakunamatata \
--mqtt_password=Wonderful \
--uid=your-custom-uid \
--no_audio \
--hw_accel # Only Pi Zero 2W, 3B, 4B support hw encoding
```> [!IMPORTANT]
> Use `--hw_accel` for Pi Zero 2W, 3B, 3B+, and 4B. Remove for Pi 5 or devices without hardware encoding.* Go to the Live page to enjoy real-time streaming!
![]()
# [Advance](https://github.com/TzuHuanTai/RaspberryPi_WebRTC/wiki/Advanced-Settings)
- [Using the V4L2 Driver](https://github.com/TzuHuanTai/RaspberryPi-WebRTC/wiki/Advanced-Settings#using-the-legacy-v4l2-driver) (for usb camera)
- [Run as Linux Service](https://github.com/TzuHuanTai/RaspberryPi-WebRTC/wiki/Advanced-Settings#run-as-linux-service)
- [Recording](https://github.com/TzuHuanTai/RaspberryPi-WebRTC/wiki/Advanced-Settings#recording)
- [Two-way communication](https://github.com/TzuHuanTai/RaspberryPi-WebRTC/wiki/Advanced-Settings#two-way-communication)
- [Virtual Camera](https://github.com/TzuHuanTai/RaspberryPi-WebRTC/wiki/Advanced-Settings##virtual-camera)
- [WHEP with Nginx proxy](https://github.com/TzuHuanTai/RaspberryPi-WebRTC/wiki/Advanced-Settings#whep-with-nginx-proxy)
- [Use WebRTC Camera in Home Assistant](https://github.com/TzuHuanTai/RaspberryPi-WebRTC/wiki/Advanced-Settings#use-webrtc-camera-in-home-assistant)