Skip to content

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.

License

Notifications You must be signed in to change notification settings

thomergil/RaspberryPi-WebRTC

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Raspberry Pi WebRTC

WebRTC Version Download Release License Apache

Pi 4b latency demo

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.

How to use

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:

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 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

sudo apt install libmosquitto1 pulseaudio libavformat59 libswscale6

3. Download and unzip the binary file

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

4. Setup MQTT

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?
Yes, MQTT is required for signaling P2P connection info between your camera and the client UI. 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.

Running the Application

  • 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!

Pi 5 live demo on web

Advance

For recording video, two-way communication, legacy V4L2 driver, or running as a background service, please refer to the wiki page.

Frontend Development with PiCamera.js

If you are building a frontend application that needs to connect to and stream video, check out the JavaScript package picamera.js.

License

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.

About

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.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 96.5%
  • CMake 3.5%