First of all, what is a restreaming server? Sometimes you want to livestream video from a device like an ATEM Mini 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.
(Note: the YoloBox does let you publish to multiple destinations with no extra setup, so if you're using that device, you can just ignore this whole tutorial!)
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
Before we get into the details, you'll need to start with a Raspberry Pi or an Ubuntu server that's already set up and running. That should be as easy as following the official setup guide for Raspberry Pi. Also note that if you're comfortable with SSH, you can install the Raspberry Pi OS "Lite" without the desktop environment.
Install nginx
The magic that makes this all work is the nginx web server with a custom module that supports RTMP.
Install nginx and the rtmp module by running the following commands on the command line, either over SSH or by opening the Terminal on the desktop.
sudo apt update
sudo apt install nginx libnginx-mod-rtmp
Configure your Restream Server
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.
To test the config file for errors, type:
sudo nginx -t
If that worked, you can reload nginx to make your changes take effect:
sudo nginx -s reload
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:
hostname -I
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!
If you want to stream to this from an ATEM Mini, you'll need to create a custom streaming config and load that in to the software control app. You can use this XML generator to create the configuration.
Fill out your server's IP address, and use either restream
or restream-ABCD-EFGH-IJKL-MNOP
as the path.
Further Reading
Now that you have the nginx RTMP module installed, there's a lot more things you can do! You can read the official documentation for a full list of other commands you can use. You can do things like:
- Record a local copy of anything your RTMP server receives
- Create multiple resolutions of your video and push different resolutions to different platforms
- Create a vertical cropped version of your feed and send it to another RTMP destination
- Notify external services when you start or stop streaming
Leave a comment below if you're interested in a tutorial on any of these other interesting features!
@aaronpk the #raspberrypi does not actually have the horsepower to “Create multiple resolutions of your video and push different resolutions to different platforms”, right? It has trouble encodingone stream at 720p.