https://github.com/TzuHuanTai/RaspberryPi_WebRTC Skip to content Navigation Menu Toggle navigation Sign in * Product + Actions Automate any workflow + Packages Host and manage packages + Security Find and fix vulnerabilities + Codespaces Instant dev environments + GitHub Copilot Write better code with AI + Code review Manage code changes + Issues Plan and track work + Discussions Collaborate outside of code Explore + All features + Documentation + GitHub Skills + Blog * Solutions By size + Enterprise + Teams + Startups By industry + Healthcare + Financial services + Manufacturing By use case + CI/CD & Automation + DevOps + DevSecOps * Resources Topics + AI + DevOps + Security + Software Development + View all Explore + Learning Pathways + White papers, Ebooks, Webinars + Customer Stories + Partners * Open Source + GitHub Sponsors Fund open source developers + The ReadME Project GitHub community articles Repositories + Topics + Trending + Collections * Enterprise + Enterprise platform AI-powered developer platform Available add-ons + Advanced Security Enterprise-grade security features + GitHub Copilot Enterprise-grade AI features + Premium Support Enterprise-grade 24/7 support * Pricing Search or jump to... Search code, repositories, users, issues, pull requests... Search [ ] Clear Search syntax tips Provide feedback We read every piece of feedback, and take your input very seriously. [ ] [ ] Include my email address so I can be contacted Cancel Submit feedback Saved searches Use saved searches to filter your results more quickly Name [ ] Query [ ] To see all available qualifiers, see our documentation. Cancel Create saved search Sign in Sign up Reseting focus You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session. Dismiss alert {{ message }} TzuHuanTai / RaspberryPi_WebRTC Public * * Notifications You must be signed in to change notification settings * Fork 9 * Star 337 Native WebRTC uses v4l2 hardware h264 and software openh264 encoder for live streaming on Raspberry Pi. License Apache-2.0 license 337 stars 9 forks Branches Tags Activity Star Notifications You must be signed in to change notification settings * Code * Issues 3 * Pull requests 0 * Actions * Security * Insights Additional navigation options * Code * Issues * Pull requests * Actions * Security * Insights TzuHuanTai/RaspberryPi_WebRTC This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository. main BranchesTags Go to file Code Folders and files Name Name Last commit message Last commit date Latest commit History 289 Commits .github .github .vscode .vscode doc doc src src test test .clang-format .clang-format .gitignore .gitignore CMakeLists.txt CMakeLists.txt LICENSE LICENSE README.md README.md View all files Repository files navigation * README * Apache-2.0 license RaspberryPi_WebRTC License 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] * It's designed as a pure P2P-based camera that allows video playback and download without needing a media server. * Support multiple users to watch the live stream simultaneously. * Raspberry Pi 5 or other SBCs do not support v4l2 hardware encoding, please run this project in software encoding mode. How to use * Download the latest binary file from Releases. * Install the Pi Camera app and follow the instructions. Hardware Requirements [6874747073] * Raspberry Pi (Zero 2W or better). * CSI Camera Module. * At least 4GB micro sd card. * A USB disk and a Micro-USB Male to USB-A Female adaptor. Environment Setup 1. Use the Raspberry Pi Imager to write the Lite OS (Bookworm 64-bit) to the micro SD card. 2. Install essential libs sudo apt install libmosquitto1 pulseaudio libavformat59 libswscale6 3. Enable Raspberry Pi Hardware by adding below in /boot/firmware/ config.txt camera_auto_detect=0 start_x=1 gpu_mem=16 Set camera_auto_detect=0 in order to read camera by v4l2. 4. Mount USB disk [ref] + Skip this step if you don't want to record videos. Don't set the record_path flag while running. + When the disk drive is detected, it will automatically mount to /mnt/ext_disk. sudo apt-get install autofs echo '/- /etc/auto.usb --timeout=5' | sudo tee -a /etc/auto.master > /dev/null echo '/mnt/ext_disk -fstype=auto,nofail,nodev,nosuid,noatime,umask=000 :/dev/sda1' | sudo tee -a /etc/auto.usb > /dev/null sudo systemctl restart autofs Running the Application MQTT is currently the only signaling mechanism used, so ensure that your MQTT server is ready before starting the application. It is recommended to use a cloud-based MQTT server. Free plans include, but are not limited to, HiveMQ and EXMQ. If you're self-hosting and you want to access the signaling server remotely via mobile data, you may need to set up DDNS and port forwarding if your ISP provides a dynamic IP. Run * Running the binary file pi_webrtc with the -h flag will display all available options. * To start the application, use your settings and apply them to the following example command below. The SDP/ICE data will be transferred under the MQTT topic specified by your uid setting. # run the PulseAudio service if it is not started. pulseaudio --start # run main program with your settings /path/to/pi_webrtc --device=/dev/video0 --fps=30 --width=1280 --height=960 --v4l2_format=h264 --hw_accel --mqtt_host=example.s1.eu.hivemq.cloud --mqtt_port=8883 --mqtt_username=hakunamatata --mqtt_password=Wonderful --uid=home-pi-zero2w --record_path=/mnt/ext_disk/video/ Hint 1: Since the Pi 5 does not support hardware encoding, please remove the --hw_accel flag and set --v4l2_format to mjpeg. Video encoding will be handled by OpenH264. Hint 2: I noticed that when I set 1920x1080, the hardware decoder firmware changes it to 1920x1088, but the isp/encoder does not adjust in the 6.6.31 kernel. This leads to memory being out of range. However, if I set 1920x1088, all works fine. Run as Linux Service 1. Run pulseaudio as system-wide daemon [ref]: * create a file /etc/systemd/system/pulseaudio.service [Unit] Description= Pulseaudio Daemon After=rtkit-daemon.service systemd-udevd.service dbus.service [Service] Type=simple ExecStart=/usr/bin/pulseaudio --system --disallow-exit --disallow-module-loading Restart=always RestartSec=10 [Install] WantedBy=multi-user.target * Run the cmd to add a autospawn = no in the client conf echo 'autospawn = no' | sudo tee -a /etc/pulse/client.conf > /dev/null * Add root to pulse group sudo adduser root pulse-access * Enable and Start the Service sudo systemctl daemon-reload sudo systemctl enable pulseaudio.service sudo systemctl start pulseaudio.service 2. In order to run pi_webrtc and ensure it starts automatically on reboot: * Create a service file /etc/systemd/system/pi-webrtc.service with the following content: [Unit] Description= The p2p camera via webrtc. After=systemd-networkd.service [Service] Type=simple WorkingDirectory=/path/to ExecStart=/path/to/pi_webrtc --device=/dev/video0 --fps=30 --width=1280 --height=960 --v4l2_format=h264 --hw_accel --mqtt_host=example.s1.eu.hivemq.cloud --mqtt_port=8883 --mqtt_username=hakunamatata --mqtt_password=wonderful --record_path=/mnt/ext_disk/video/ Restart=always RestartSec=10 [Install] WantedBy=multi-user.target * Enable and Start the Service sudo systemctl daemon-reload sudo systemctl enable pi-webrtc.service sudo systemctl start pi-webrtc.service Advance To enable two-way communication, a microphone and speaker need to be added to the Pi. Microphone Please see this link for instructions on wiring and testing your Pi. Speaker You can use the link for instructions on setting up a speaker on your Pi. 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 Native WebRTC uses v4l2 hardware h264 and software openh264 encoder for live streaming on Raspberry Pi. Topics raspberry-pi encoding h264 video ffmpeg cpp webrtc p2p v4l2 signalr video-streaming hardware-acceleration 64-bit openh264 Resources Readme License Apache-2.0 license Activity Stars 337 stars Watchers 7 watching Forks 9 forks Report repository Releases 1 v1.0.0 Latest Sep 5, 2024 Sponsor this project * https://paypal.me/TzuHuanTai Languages * C++ 96.5% * CMake 3.5% Footer (c) 2024 GitHub, Inc. Footer navigation * Terms * Privacy * Security * Status * Docs * Contact * Manage cookies * Do not share my personal information You can't perform that action at this time.