Build a RTMP Restreaming Server on a Raspberry Pi

Sometimes you want to livestream video from a device like an ATEM MINI PRO or OBS to multiple destinations. Many devices and software like this will let you push video to just one RTMP destination at a time.

To stream to multiple destinations, you need to use a restream server so that the device can stream the one stream to the server, and the restream server pushes to multiple destinations

There are paid services you can use to restream for you, restream.io being one of the most well-known ones. This is a great solution too, and if you’re just looking for a quick way to restream to multiple platforms, this is the easiest way to go.
But, sometimes you want to do this yourself, avoid paying third party services, or you might need to restream to local devices that something on the public internet can’t reach. That’s what the rest of this blog post is about. I’ll show you how to set up a Raspberry Pi (or really any other Linux computer) to restream your livestreams to multiple destinations.
Getting Started
You should start with a Raspberry Pi running the latest Raspbian, connected to screen, mouse and keyboard.
Install NGINX
On your Pi, open a terminal window and enter the following to install NGINX and the RTMP extension for NGINX
sudo apt update
sudo apt install nginx libnginx-mod-rtmp
Enable RTMP
Now we need to set up an RTMP server in nginx. Edit the main nginx config file:
sudo nano /etc/nginx/nginx.conf
Scroll all the way to the bottom and copy the below text into the config file:
rtmp {
server {
listen 1935;
application restream {
# Enable livestreaming
live on;
# Disable recording
record off;
# Allow only this machine to play back the stream
allow play 127.0.0.1;
deny play all;
# Push your stream to one or more RTMP destinations
push rtmp://a.rtmp.youtube.com/live2/XXXX-XXXX-XXXX-XXXX-XXXX;
push rtmp://a.rtmp.youtube.com/live2/XXXX-XXXX-XXXX-XXXX-XXXX;
push rtmp://live-cdg.twitch.tv/app/live_XXXXXXXX;
}
}
}
Save this file by pressing ctrl+X, then Y, then enter.
Start NGINX with RTMP
In Terminal enter:
sudo systemctl start nginx.service
sudo systemctl status nginx.service
You should now have NGINX up and running. You can check it by opening a browser window on your Pi and pointing it to your Pi’s Ip address.
Setting up auto-boot
sudo systemctl daemon-reload
sudo systemctl enable nginx
sudo systemctl restart nginx.service
Start Streaming
At this point the Raspberry Pi is ready! You can now stream to this box and it will send a copy to each configured destination! Any stream key will work, and you can stream using any sort of device or software like OBS. You’ll need to find the IP address of the Raspberry Pi which you can do by typing:
ifconfig
To stream to the Raspberry Pi, use the RTMP URL: rtmp://YOUR_IP_ADDRESS/restream
and anything as the stream key.
NOTE: The way this is set up, anyone can stream to this if they know the IP address since it will accept any stream key. If you want to restrict this, you can use a long random string in place of restream
in the config. For example:
...
application restream-ABCD-EFGH-IJKL-MNOP {
...
Now you are ready to stream! Start pushing an RTMP feed to your server and it will send a copy to each of your configured destinations!
Configure OBS
On your host computer, download and install OBS.
In Preferences>Stream, enter the following:
rtmp://YOUR_IP_ADDRESS:1935/restream
Key: test
“test” is our unique stream key, we just made it up by entering it in the preferences. You can basically make up any stream key and stream to it. For simple purposes, authentication isn’t necessary in my experience.
Set up a test source in OBS, this could be a webcam, a video source…
Press Start Streaming in OBS