Live video streaming is becoming increasingly popular, whether for personal projects, remote monitoring, or real-time communication applications. Raspberry Pi, combined with Janus WebRTC Gateway, offers a powerful yet cost-effective solution for streaming video locally and globally. This guide will walk you through the essential steps of a Raspberry Pi with Janus WebRTC Gateway to stream video live, either for personal use or for a more expansive application.
Getting started with the hardware and building the local streaming solution will also be covered, finally, ensuring you open your stream to the world securely. You will be able to stream live video from your Raspberry Pi to any device, anywhere, with extra measures to safeguard your setup by following this guide.
How does WebRTC work?
Before diving into the details of implementation, let’s take a step back and explain what is WebRTC and Janus and how they works.
WebRTC stands for Web Real-Time Communication. WebRTC is a free and open-source project, which allows for real-time communication. It is used for peer-to-peer communication between web browsers and mobile devices. Moreover, WebRTC simplifies video, text and sound without any additional plugins. Janus is a WebRTC server.
Before diving into the details of implementation, let’s take a step back and prepare the tools. These prerequisites apply both to local and global streaming.
Raspberry Pi
To stream with Raspberry Pi, a couple of things are needed:
- Raspberry Pi 3 model B or newer.
- Camera module or USB camera alternatively.
- 8 GB or bigger SD card.
- Raspberry Pi OS (formerly Raspbian) installed on the Raspberry.
Raspberry Pi OS, previously known as Raspbian, provides the operating system support necessary for effective streaming. To get the Raspberry Pi OS, download and install Raspberry Pi Imager from Raspberry Pi official website. Then, flash an SD card with Raspberry Pi OS. Once that’s done, plug the SD card into Raspberry.
Camera module
Now it’s time to check if the hardware works correctly. Power up Raspberry and connect it to WiFi. For convenience, one can connect to RPi using ssh protocol. Next, make sure the Raspberry Pi camera module is properly connected. Modern versions of Raspberry Pi OS use the libcamera stack by default. To validate if the camera is working, execute one of the following commands:
libcamera-jpeg -o test.jpg
libcamera-vid -t 5000 -o test.h264
Go to Interface Options > Camera and select Enable. To validate if the camera works, execute one of the following commands.
raspistill -o test.webp
raspivid -t 5000 -o test.h264
Lastly, install GStreamer which will be used to deliver video from Raspberry to Janus. GStreamer is an open-source, pipeline-based multimedia framework that enables the encoding and routing of audio and video streams by chaining together modular components.
sudo apt install gstreamer1.0-tools gstreamer1.0-plugins-base gstreamer1.0-plugins-good
Installing software prerequisites
Install Dependencies
Before installing Janus WebRTC Gateway, a couple of libraries should be installed in order for Janus to work properly.
sudo apt update
sudo apt install -y cmake git build-essential autotools-dev autoconf automake libtool pkg-config libmicrohttpd-dev libjansson-dev libssl-dev libsrtp2-dev libsofia-sip-ua-dev libglib2.0-dev libopus-dev libogg-dev libini-config-dev libcollection-dev libconfig-dev libnice-dev
Install Janus Gateway
Now, it’s time to install Janus WebRTC Gateway, a WebRTC Server Software. First, clone the janus-gateway repository and enter the created directory. Next, execute the sh autogen.sh command to generate the configuration file. Then, run the configuration script and proceed with the usual compilation steps to initiate the build process.
./autogen.sh
./configure –enable-plugin-streaming
make
sudo make install
sudo make configs
Configure Janus Gateway
When the installation is complete, one can move on to configuration. Update rpi-sample in janus.plugin.streaming.cfg (usually located in /usr/local/etc/janus) so it matches this configuration:
rpi-sample: { type = “rtp” id = 1 description = “RPi stream description – add what You want here” metadata = “RPi stream metadata – add what You want here” video = true videoport = 5004 videopt = 100 videocodec = “h264” }
Local Streaming Setup
Local streaming allows video from the Raspberry Pi’s camera to be viewed on devices connected to the same network. Open three terminal windows to start streaming.
Stream the video
To stream the video from the Raspberry Pi, execute this command:
gst-launch-1.0 libcamerasrc ! videoconvert ! x264enc ! rtph264pay config-interval=1 pt=100 ! udpsink host=127.0.0.1 port=5004
Start the Janus Server
In the second terminal window navigate to the Janus demos directory /home/user/janus-gateway/html/demos and start the server. This is mandatory to watch the stream. Do not use port 8088, as Janus uses this port for its own API. We will use port 8000 instead:
python3 -m http.server 8000
Launch Janus
In the third terminal window execute the command below to start Janus.
janus
Watching the stream
To watch the stream, open the browser on the end device (laptop, smartphone) in the same network. Then:
enter http://<raspberry_pi_ip>:8000.
Go to Streaming.
Press the Start button and select Your stream.
Important note on browser security: Modern browsers (e.g. Chrome or Safari) have strict security policies regarding WebRTC. If you see a black screen or connection errors, the browser might be blocking WebRTC over HTTP. To fix this locally, you can temporarily enable insecure origins in your browser settings (e.g., in Chrome, go to chrome://flags/#unsafely-treat-insecure-origin-as-secure and add your Raspberry Pi’s IP) or set up HTTPS using a reverse proxy.
Global Streaming Setup
On the other hand, global streaming allows video from the Raspberry Pi to be accessed over the internet, enabling remote monitoring from any location. On the other hand, the main concerns are NAT traversal and ensuring low latency for video streaming.
Set up port forwarding
Port forwarding refers to the process of redirecting communication requests from one address and port number combination to another. It is necessary to expose Raspberry Pi’s services to the internet. Access Your routers configuration page. Then, forward ports 8000 (Python HTTP web server) and 8088 (RTP streaming). Moreover, find Your public IP address, which will be then needed for accessing the stream.
Set Up a STUN Server
STUN Server is needed for NAT traversal, so external devices can establish a direct connection to Raspberry Pi. You can either use Public STUN Servers or set up Your own using coturn. In this tutorial, only the first option will be covered.
To setup STUN Server add the following line in /usr/local/etc/janus/janus.cfg
stun_server = stun.l.google.com:19302
Secure streaming setup
Before bringing the system back online, further configuration adjustments are required. To do so, enable authentication in Janus. Simply edit janus.plugin.streaming.cfg and add:
secret = “your_password_here”
NOTE: It’s a good idea to implement additional security measures, such as:
- Setting up a reverse proxy (e.g., Nginx) to enable HTTPS
- Changing default ports (e.g., 8088 to 9090)
- Using Dynamic DNS combined with IP whitelisting
- Utilizing a VPN for secure access
Global stream
If you want to make your Repeat the steps from Watching the stream chapter, but this time provide Your public IP address.
Insider pro-tips for optimizing Raspberry Pi streaming
Unleashing hardware encoding (v4l2h264enc)
Most WebRTC tutorials, including this one, suggest using x264enc for video encoding. Although it is compatible with a variety of devices, it uses only software encoding, which places a serious strain on the Raspberry Pi’s CPU. The ultimate insider secret to achieving ultra-low latency and keeping your CPU usage below 15% is using the RPi’s dedicated hardware video encoder. By replacing x264enc with v4l2h264enc (which stands for Video4Linux2 hardware encoder) in your GStreamer pipeline, you redirect the heavy lifting to the Pi’s GPU. Not only does this significantly drop power consumption, but it also eliminates the micro-stutters often associated with CPU spikes during WebRTC transmission.
Managing thermal throttling for stable streams
Another critical, yet often overlooked, aspect of continuous live streaming on a Raspberry Pi is thermal throttling. Video encoding is an intensive task. According to the Raspberry Pi datasheet, when the RPi’s SoC reaches 80°C, the firmware automatically throttles the CPU and GPU clock speeds to prevent thermal damage. This sudden throttling shows up in WebRTC as huge missed frames, glitchy video, and rapidly increasing latency.
To ensure your stream remains perfectly smooth during long sessions, you need to monitor temperatures and invest in active cooling. You can check the exact temperature of your processor at any time by running the built-in command vcgencmd measure_temp via SSH. If you see it creeping past 65°C, consider attaching a cheap PWM fan or a heatsink case. Your WebRTC pipeline will thank you with rock-solid stability.
Conclusion
Applications involving live video streaming from the Raspberry Pi using Janus WebRTC Gateway range from local to global. This tutorial has taken you through the basic setup, including hardware requirements, software installation, and security considerations necessary to ensure a safe and effective streaming experience. Whether you want to monitor something remotely or experiment with real-time communication, this setup provides a reliable and scalable foundation for your streaming needs.
Key Takeaways
Sub-Second Latency: If you want to build an ultra-low-latency video stream with Raspberry Pi, combining it with the Janus WebRTC Gateway offers a high-performance solution for both local and global broadcasting.
Hardware Acceleration is Essential: Switching from software encoding (
x264enc) to the hardware encoder (v4l2h264enc) in GStreamer drops CPU usage below 15% and prevents micro-stutters.Seamless Global Access: You can stream with Raspberry Pi over the internet by configuring port forwarding and setting up a STUN server (
stun.l.google.com:19302) for NAT traversal.Prevent Thermal Throttling: Continuous video encoding generates heat; monitoring SoC temperatures (
vcgencmd measure_temp) and using active cooling avoids thermal throttling at 80°C.Prioritize Stream Security: Protect your global setup by enabling Janus Gateway authentication secrets, configuring HTTPS via a reverse proxy (like Nginx), or using a private VPN.
Frequently Asked Questions
Why should I use Janus WebRTC Gateway for Raspberry Pi video streaming?
Janus WebRTC provides a lightweight, open-source server architecture designed for real-time, sub-second latency video communication. Unlike traditional HTTP live streaming (HLS) or RTMP protocols, Janus Gateway enables native peer-to-peer playback inside web browsers without requiring additional plugins.
How do I reduce CPU usage when streaming video from a Raspberry Pi?
To minimize CPU usage, use hardware-accelerated video encoding. Replace the default software encoder (x264enc) in your GStreamer pipeline with the native Video4Linux2 hardware encoder (v4l2h264enc). This offloads processing to the Raspberry Pi’s GPU and keeps CPU utilization under 15%.
Why is my WebRTC stream showing a black screen or connection error in the browser?
Modern browsers enforce strict WebRTC security policies and often block camera streams over unencrypted HTTP connections. To resolve this, either enable insecure origins temporarily in your browser flags (e.g., chrome://flags/#unsafely-treat-insecure-origin-as-secure) or set up a reverse proxy with an SSL/TLS certificate to serve the stream via HTTPS.
What is the purpose of a STUN server in global WebRTC streaming?
A STUN server allows devices located behind local routers and Firewalls (NAT) to discover their public IP address and port mapping. This enables external devices to establish a direct connection to your Raspberry Pi when attempting to stream with Raspberry Pi over the public internet.
How can I secure my Raspberry Pi WebRTC stream from unauthorized access?
You can secure your Janus WebRTC setup by enabling password authentication in the janus.plugin.streaming.cfg configuration file. Additionally, implementing a reverse proxy for HTTPS encryption, changing default ports (e.g., moving port 8088 to a custom port), using Dynamic DNS with IP whitelisting, or routing traffic through a private VPN will protect your stream globally.







