Local and global streaming in a few simple steps
In a previous blog article, we covered the topic of streaming with Raspberry Pi using AWS Kinesis. This time, we will focus on local and global streaming using WebRTC.
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 or 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 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 it work?
Before diving into the details of implementation, let’s take a step back and explain what WebRTC, Janus and how it works. WebRTC stands for Web Real-Time Communication. It is a free and open-source project, which allows for real-time communication. WebRTC 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.
Prerequisites
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.
RaspberryPi
To stream video from Raspberry Pi a couple of things are needed. To get the things working we need:
- Raspberry Pi 3 model B or newer.
- Camera module or USB camera alternatively.
- 8 GB or bigger SD card.
- The Raspbian OS is installed on the Raspberry.
To get the Raspbian 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. Then, enable the camera in the Raspberry Pi configuration with this command:
sudo raspi-config
Go to Interface Options > Camera and select Enable. To validate if the camera works, execute one of the following commands.
raspistill -o test.jpg
raspivid -t 5000 -o test.h264
Lastly, install GStreamer which will be used to deliver video from Raspberry to Janus.
sudo apt install gstreamer1.0-tools gstreamer1.0-plugins-base gstreamer1.0-plugins-good
Contact us for a free estimate for your project!
Install 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.
./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 rtp-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=96 ! 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.
python3 -m http.server 8088
Launch Janus
In the third terminal window execute the command below to start Janus.
janus
Watch 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>:8088.
- Go to Streaming.
- Press the Start button and select Your stream.
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. The main concerns are NAT traversal and ensuring low latency for video streaming.
Set up port forwarding
Port forwarding is necessary to expose Raspberry Pi’s services to the internet. Access Your routers configuration page. Then, forward ports 8088 (Janus’ HTTP server) and 5004 (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
Watch global stream
Repeat the steps from Watch the stream chapter, but this time provide Your public IP address.
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.