Raspberry Pi or Ubuntu RTMP Server Installation:


What is an RTMP server?

One of the most frustrating difficulties of IRL streaming to both the content creator and the viewer is loss of signal, and disconnecting means starting your stream over. Streamers are shown offline, their following gets maybe auto-hosted elsewhere...It can be a mess. Twitch has added a feature known as "Disconnect Protection" but that still only works for up to 90 seconds and is not customizable.

One of the ways around this is to use what's called an RTMP server. An RTMP server is basically a "data handler" over TCP, which maintains a constant connection to the server even if a disconnect event occurs. To sum this up even easier: You send your outgoing video to an RTMP server, and let that server dictate what the viewers see, instead of sending your outgoing video directly to any streaming service. If there's a loss between your IRL camera and the RTMP server, the RTMP server takes over and will show a custom scene in its place. This keeps the stream alive even if there's loss of connection from the IRL streamer to whatever platform they're streaming to.

How do I set up a personal RTMP server?

This article will discuss how to get this set up using a Linux environment. This can be accomplished using Ubunbtu (natively or in a Virtual Machine) or using a Raspberry Pi (in this case a Pi 4b 2GB) and both have been tested and work. The screenshots were taken from the Pi in this instance, using older software, but the setup is the same in both instances. Keep in mind, versions of applications have changed (and will change) so some of the screenshots are already outdated, but the newest versions of nginx have been tested and so long as you stick to the commands, using the screenshots as references (and changing said commands to fit the newest software updates), you should be fine.

The first thing you'll need is...you guessed it...a server. A Raspberry Pi running Debian works well, so will an Ubuntu installation, in a virtual image or natively. You can plug your server in and forget about it. So long as you keep your RTMP server running while you're out in the field, it doesn't have to be something that stays on 24/7. NOTE: These instructions are for a Linux installation and are not the same as Windows.
If you're looking to learn how to run an RTMP server in Windows, there are other resources available. This tutorial should be similar, but untested.

Amazon Referral code to a decked out Rasp Pi kit!

Once you've established what you're going to run, make sure the Operating System you're using supports nginx. This is basically a tiny little web server that contains a module called appropriately: nginx-rtmp-module. Now onto the actual configuration!

Open a terminal

SSH into your server, OR open a terminal window

Obtain the required files

Run the following commands to ensure you have all the prerequisites
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install build-essential libpcre3 libpcre3-dev libssl-dev


Type Y then press enter to continue


Make a new workspace

Make sure you're in a clean directory, as you're going to be downloading and installing some applications. The easiest way is from the home directory (~) just make a new directory called rtmp
mkdir rtmp then change to it cd rtmp and if you ls you should now see it empty

Download and install nginx

You will most likely want to obtain the latest version from the official website but if you are unsure or just want it to work, feel free to use version 1.19.1 as it's the most recent release at the latest update. Run the following command to download nginx
wget http://nginx.org/download/nginx-1.19.1.tar.gz

You can also check: here (https://nginx.org/download/) for the latest version. This has been tested through version 1.19.1

Run the following command to download the rtmp module direct from github
wget https://github.com/sergey-dryabzhinsky/nginx-rtmp-module/archive/dev.zip

In case it's never updated again you can also:
wget https://thelivewell.net/misc/nginx-rtmp.zip
This zip is from version 1.1.7.9.

Now let's unzip the two files
tar -zxvf nginx-1.19.1.tar.gz
unzip dev.zip (or) unzip nginx-rtmp.zip
And browse to the newly created folder cd nginx-1.19.1
(Note: The screenshots show an older version 1.17.9, adjust your commands for the updated version)



Next let's compile nginx to include RTMP!
Run the following to merge configurations
./configure --with-http_ssl_module --add-module=../nginx-rtmp-module-dev
Then run the following to compile the nginx server
make (this takes a little while)
Then run this command to install the nginx server
sudo make install

This is basically "building" the nginx server and adding the module that you downloaded to the previous directory
When it's done it should look something like:


Then lastly to get the server started run the following
sudo /usr/local/nginx/sbin/nginx
and that's it! Feel free to open a web browser, go to http://(IP of your server)/ (localhost) and you should see a "Welcome to nginx" page!


Obtaining your Ingest Server and Stream Key

NOTE: This might not be necessary but is still important to note
The next steps are necessary to "reflect" the video from your RTMP server to Twitch. First, head on over to: the Twitch Ingest Server list. This will allow you to pick a server nearest you for minimal latency. Write this down, it should look something like
rtmp://live-jfk.twitch.tv/app/{stream_key}
Note that's for NYC, but there are dozens of servers around the world so make sure you grab Twitch's suggestion

Next obtain your stream key. THIS IS HIGHLY IMPORTANT TO KEEP SECRET! So don't share this anywhere! You can find that on Twitch itself under: https://dashboard.twitch.tv/u/YOUR_USER_NAME/settings/channel and it should look something like
live_12345678_ThirtyCharacterCodeFollowing

Configuring RTMP

Next, we'll have to configure the nginx server to use RTMP. You can use any text editor really but here's how to use nano to make the additions
sudo nano /usr/local/nginx/conf/nginx.conf

This will bring up a text editor that might look a bit daunting at first, but all you really need to know is use your arrow keys, and when you want to quit type CTRL-X and choose whether you want to save. Feel free to explore in here as well, there are MANY settings you can give to nginx that make it very useful.


Scroll to the bottom and add the following lines (as new lines) into the config file


It should look like this


Press CTRL-X to save and you'll be prompted at the bottom to "Save modified buffer?" Just press Y and hit enter and you're set!


All that's left is to stop and restart the server to reflect the new changes made
sudo /usr/local/nginx/sbin/nginx -s stop
sudo /usr/local/nginx/sbin/nginx


More links:
The OBS Project.com
JobinBasani.com

Last Updated: Aug 5, 2020
Contact:
(If you don't see any contact information, enable javascript)