Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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: 1 day 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 (over 2 years ago)
- Default Branch: main
- Last Pushed: 2025-01-13T08:52:25.000Z (9 days ago)
- Last Synced: 2025-01-14T00:08:15.548Z (9 days ago)
- Topics: cpp, encoding, ffmpeg, h264, libcamera, raspberry-pi, security-camera, v4l2, video, webrtc, webrtc-video
- Language: C++
- Homepage:
- Size: 27.3 MB
- Stars: 807
- Watchers: 4
- Forks: 33
- Open Issues: 14
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
Raspberry Pi WebRTC
Turn your Raspberry Pi into a low-latency home security camera using the V4L2 DMA hardware encoder and WebRTC. [[demo video](https://www.youtube.com/watch?v=JZ5bcSAsXog)]
- Pure P2P-based camera allows video playback and download without a media server.
- Support [multiple users](doc/pi_4b_users_demo.gif) for simultaneous live streaming.
- Support signaling via [WHEP](https://www.ietf.org/archive/id/draft-ietf-wish-whep-02.html) or MQTT.# How to use
To set up the environment, please check out the [tutorial video](https://youtu.be/g5Npb6DsO-0) or the steps below.
* Download and run the binary file from [Releases](https://github.com/TzuHuanTai/RaspberryPi_WebRTC/releases).
* Set up the network configuration and create a new client using one of the following options:
* [Pi Camera](https://github.com/TzuHuanTai/Pi-Camera) app (Android).
* [Pi Camera Web](https://picamera.live).
* Javascript client
* [PiCamera.js](https://www.npmjs.com/package/picamera.js) (For MQTT).
* [eyevinn/webrtc-player](https://www.npmjs.com/package/@eyevinn/webrtc-player) (For WHEP).## Hardware Requirements
* Raspberry Pi (Zero 2W/3/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.
> [!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.### 2. Install essential libraries
```bash
sudo apt install libmosquitto1 pulseaudio libavformat59 libswscale6
```### 3. Download and unzip the binary file
```bash
wget https://github.com/TzuHuanTai/RaspberryPi_WebRTC/releases/latest/download/pi_webrtc-1.0.4_pi-os-bookworm.tar.gz
tar -xzf pi_webrtc-1.0.4_pi-os-bookworm.tar.gz
```### 4. Setup MQTT
An MQTT server is required for communication between devices. For remote access, free cloud options include [HiveMQ](https://www.hivemq.com) and [EMQX](https://www.emqx.com/en).
> [!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](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) or [Pi Camera Web](https://picamera.live), 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:
```bash
./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!
# [Advance](https://github.com/TzuHuanTai/RaspberryPi_WebRTC/wiki/Advanced-Settings)
- [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)
- [Legacy V4L2 driver](https://github.com/TzuHuanTai/RaspberryPi-WebRTC/wiki/Advanced-Settings#using-the-legacy-v4l2-driver) for usb camera
- [Run as a background service](https://github.com/TzuHuanTai/RaspberryPi-WebRTC/wiki/Advanced-Settings#run-as-linux-service)
- [WHEP with Nginx proxy](https://github.com/TzuHuanTai/RaspberryPi-WebRTC/wiki/Advanced-Settings#whep-with-nginx-proxy)# License
This project is licensed under the Apache License, Version 2.0. See the [LICENSE](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 athttp://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.
```