OBS Streaming – Multi Stream Appliance – On AWS

obs rtmp aws amazon stream

Stream from OBS to Facebook, Google, Twitch simultaneously

  • Run on a free server on AWS using Nginx
  • Did I mention it’s free?
  • Only basic skills requreid

Overview of what’s ahead

If you ever wanted to stream to multiple platforms like Facebook, Twitch and YouTube at the same time and you wanted to do that for the lowest possible cost – like say free – then you are in the right place…. read on.

Live stream to YouTube Live, Facebook Live , Twitch, IBM Cloud Video/Ustream, Instagram Live Video, Vimeo Live/Livestream, Periscope, IRIS/Bambuser, YouNow, Meridix, Streamspot, DaCast, Tikilive

While clearly it is quite normal for a person new to AWS and the tools used in this tutorial to take a good bit of time to get things running.

Consider however that a person that has what are essentially basic guide following skills and some previous basic knowledge of the tools used can get an RTMP server up and running on AWS in about 10-15 minutes.

While vMix is not specifically covered in this tutorial, with just a few steps one can leverage this same appliance in any tool that handles streaming to the platforms mentioned above.

A not so well known fact is that rtmp streaming is essentially a routing story versus an encoding story.  So this reality translates into the fact that you don’t need that much of a server to run RTMP across the net!

In this article I will go through step by step on how to get up and running.

We will cover the following:

  • How to setup an account on Amazon AWS
  • How to install Putty (a ssh terminal client)
  • How to install WinSCP (used for file transfers and edits)
  • How to install the needed Nginx software and configure an RTMP server
  • Install stunnel which is needed to stream to Facebook with RTMPS
  • Setup OBS for streaming to the RTMP server
  • Finally, stream to Facebook, Twitch and YouTube as test case

Chip in for a beer? 🙂

Tools used in this tutorial

So here’s what we’re going to need to make this all happen.

  • A ssh client (command line) tool called Putty (free)
  • A file transfer tool called WinSCP (free)
  • An AWS account (free)
  • Ability to follow a basic recipe
  • We will be installing Nginx – a web server that can stream rtmp/s  – which are the protocols that Twitch, YouTube etc all use.
  • Also included is the installation of stunnel which is required to stream to Facebook via RTMPS.
  • It’s a given is that you have a moderate grasp on OBS

Configuration Files (nginx & stunnel)

 

Primary Skills needed to complete this successfully

There is no coding of anything in this exercise. However, if you cannot pass the test below then you may very well run into issues with this or baking a cake.

Step One: Download and install Tools

Putty

Okay so let’s first get putty downloaded and installed on the local machine

If you already have putty or another SSH client you can skip ahead.

You can download the file here or follow the instructions below

Of course you can always head over to the WinSCP website to do the download of the software.

Choose that one and choose the link where it says “you can download Putty here.”

Choose the link that matches your OS and if in doubt get the 32bit version as that should still work on a Windows 64bit machine anyway.

WinSCP

Next let’s get the tool – WinSCP -that allows you to access the files on the remote server, transfer files and edit them if needed.

Of course you can always head over to the Putty website to do the download of the software.  Look for the large green button.

Once the files are downloaded we can just install them. 

Then it will be ready to use in a future step to login to the machine we create and do the installs and configurations of nginx.

The links to the software here are directly from the respective tool’s sites and are placed here simply for the reader’s convenience.

You of course will need to have install rights on your machine so that is a given. How to install programs on Windows is way beyond the scope of this tutorial.

Step Two: Get an AWS account

 Of course it should go without saying – if you already are familiar with AWS and have an account you can again skip ahead to the next section.

As mentioned before the time stamps are in the description

Okay so let’s have a basic look at how to get a free account on AWS

Just head over to aws.amazon.com and click on “Get Started For Free” then a new screen will appear and you can then click on “Create a Free Account”

You will need a credit card to signup. This makes total sense since Amazon needs to make sure that people from around the world are just creating frivolous accounts. 

Now as long as you don’t use a different machine or hdd then you will not be charged for a full year.

Even after a year it’s not much at all to run a machine on AWS especially if you just run it when you are in need of streaming to multiple sites

Step Three: Create an Ubuntu Linux instance on AWS

Create Instance and save key pair

Okay so first off let’s have a quick look around and dial in on the two key areas we will need to use. Specifically – Instances and Security Groups

There is an image gallery below that you can click through to see the screen shots step by step for clarity.

That said let’s get into setting up the instance by going over to instances and click on “Launch Instances”

Next is to select what’s essentially your install disk called an AMI

Input “ami-0121ef35996ede438” in the search field and press enter

You should then see “Ubuntu Server 18.04 LTS (HVM), SSD Volume”. Next just press the “Select” Button

On the next screen leave everything as it is on the next screen and click on the “Review and Launch” button

Now scroll down and look for “Edit Security Groups” and click on it.

In the field enter “RTMP-Instance Security Group” or something similar you will recognize easily.

Then look at the first line where is shows “0.0.0.0/0” and click on the word “Custom” and select “My Ip”

Now click on “Add Rule” and in the first field where it says Custom and in the third field (Port Range) enter

1935 then look for the fourth field click and accept “Anywhere”

Then click on “Review and Launch”

On the next screen click on “Launch”

On the popup screen click where it says “Choose and existing pair” and select “create a new pair”

In the open field enter a name you will recognize for the key pair and then click on “Download Key Pair” over to the right.

Take a moment to read the screen for details about Key Pairs.

 

Stop, Start, Reboot and Terminate an AWS Instance

Follow the steps in the screen shot gallery below to change the state of an AWS Instance

Step Four: Configure and Connect to your Linux machine using Puttygen, Putty and WinSCP

Process Key Pair

Okay time to fire up Putty and login to the instance you just created.

First we need to convert the Private Key downloaded in the previous step into some thing Putty can use.

Putty comes with a tool called PuTTYgen that we use to take the Amazon Key and convert it.

Go to your Apps in Windows and search for PuTYYgen and run the program.

Next up is to locate the key that we downloaded when setting up the Amazon AWS Instace.

Follow the steps in the screen shots in the gallery below to configure the Key for use in both Putty and WinSCP.

Check out this article on just how to Setup Putty for AWS if you need even more details.

Always be sure to take note where you store the files. Perhaps create a folder where you store all of these assets.

Putty Config

Now it is time to setup a Putty session that is used to install, configure and start and stop services on the AWS machine.

Check out this article on just how to Setup Putty for AWS if you need even more details.

Follow the steps in the screen shots below to configure Putty.

WinSCP Config

Now will set up a session to use to connect to the remote instance via WinSCP so we can edit and transfer files.

You will need to have already setup Putty as we are just going to import the Putty session as it has almost everything we need.

We have to make one specific update so that we are given sufficient privileges to edit and transfer files.

We will need to enter “sudo su -c /usr/lib/sftp-server” as will be shown in the screen shot gallery of the setup below.

Follow the steps in the screenshots below to configure WinSCP

Step Five: Install/Configure Nginx & Stunnel

In the first section above I included two “conf” files. One for nginx and the other for stunnel.  You can either follow the edit method shown further down this page in this same section or use the WinSCP method I will show first to simply copy these files across into your AWS instance in the appropriate directories as is shown here.

Putty Command Line Install of nginx and stunnel

So first we need to run Putty and connect to the AWS machine. Follow the instructions below to install nginx with the rtmp module and install stunnel that is needed to stream to rtmps at Facebook.

Just press enter on any prompts 

Prepare and Install nginx with the RTMP module and install stunnel

sudo add-apt-repository ppa:nginx/stable -y
sudo apt-get update -y
sudo apt-get install nginx libnginx-mod-rtmp stunnel4 -y

Set nginx to start at boot

sudo systemctl enable nginx.service

Start nginx (if no error outputs it is running) 

sudo systemctl start nginx

Edit stunnel auto boot configuration (Ctrl-O then Ctrl-X to exit)

sudo nano /etc/default/stunnel4

Change ENABLED from 0 to 1

ENABLED=1

Enable enable after boot and then restart stunnel

1
2
3
sudo systemctl enable stunnel4.service

sudo systemctl restart stunnel4.service

Transfer “conf” configuration files

Either transfer the files using WinSCP or edit them directly as shown in the coding sections

WinSCP

Review the screen shots in the gallery that follows for a visual idea of the steps to take.

Locate and run WinSCP. 

The Manual way for conf files

If you transferred the conf files as shown above then you can move on.

If you are more inclined to do the conf files via Putty then by all means. 

The details as to what needs to be updated follows.

Edit nginx configuration

sudo nano /etc/nginx/nginx.conf
Paste the text below in the nginx.conf file that just opened in nano
rtmp {  
server {
                listen 1935;
                chunk_size 4096;
                application live {
                        live on;
                        record off;
#			 push rtmp://127.0.0.1:19350/rtmp/<>
#			 push rtmp://a.rtmp.youtube.com/live2/<>;
                }
        }
}
Test the nginx conf file (needs to come back successful)

sudo nginx -t

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Start nginx (if no error outputs it is running) 

sudo systemctl stop nginx
sudo systemctl start nginx

Edit stunnel configuration

sudo nano /etc/stunnel/stunnel.conf
Paste the text below in the stunnel.conf file that just opened in nano
pid = /var/run/stunnel4/stunnel.pid

output = /var/log/stunnel4/stunnel.log

setuid = stunnel4

setgid = stunnel4

socket = r:TCP_NODELAY=1

socket = l:TCP_NODELAY=1

debug = 4

[fb-live]

client = yes

accept = 19350  connect = live-api-s.facebook.com:443

verifyChain = no

Enable enable after boot and then restart stunnel

1
2
3
sudo systemctl enable stunnel4.service

sudo systemctl restart stunnel4.service

With AWS server ready it is time to get the respective stream keys used in the next step.

Step Six: Setup the Stream keys for Facebook, Twitch & YouTube

Use/Test Case

Okay now that we have everything installed it’s time to take it out for a spin.

Let’s set things up to Stream from OBS to the RTMP server (that was just configured) and then view it on Facebook and YouTube.

First up we have to get the stream key from Facebook

The image slider below shows the steps to set the stream key to persistent and to locate your stream key. Clicking on the image will enlarge it.

Click the link below (login if presented) to go directly to the area where you will be able to find the Facebook Key

Be sure to check the box for “Use Persistent Key” else your key will change for each stream and therefore would need to then be updated on the RTMP push line.

https://www.facebook.com/live/producer/

Next up we get the stream key from YouTube

The image slider below shows the steps to set the stream key to locate your stream key over at youtube.com

Use the link below to get started (again login if needed)

https://studio.youtube.com/channel/

Next up we get the stream key from Twitch

The image slider below shows the steps to set the stream key to locate your stream key.

Use the link below to get into the right place

https://dashboard.twitch.tv/

Now place Stream Keys in the nginx.conf file

Now we have to place the stream keys in the nginx.conf file back on the server. To do this open up WinSCP and navigate back to the “/etc/nginx/nginx.conf” file and open it to edit.

Take note as before in the screen shot gallery below as a guide.

For those confortable in going into the remote instance using putty simply update each of the lines for Facebook, YouTube and Twitch with their respective Stream Keys.

Reminder, remove the “#” for any service you want to include as an outgoing stream.

Caution for Twitch streaming as Twich is live as soon as it is receiving the feed i.e. there is no “Live” button for Twitch.

Commands to stop/start nginx (for reference)

sudo systemctl stop nginx
sudo systemctl start nginx

In Closing

Hopefully, you either already had the command line skills and WinSCP skills or developed them during this exercise.  You will need those skills going forward to be able to either use PuTTY or WinSCP to edit the nginx.conf file on the remote server.

Using a service like restream.io has fees that can add up. However, if you are generally doing low volume and don’t mind finding the old “ah no that’s not available in the free plan” after you’ve invested time into that service the restream.io might be an option.

If you’re looking for full control at a price of free essentially, then by all means take the time to master this spin up since you can spin up an RTMP appliance in a matter of say 15 minutes.

You can build the instance and run it when you need it and have it turned off at AWS when you don’t.  For the first year you can run it for 24 hours a day at no charge. After that the cost would be pennies if only run when doing restreaming.

Bitcoin 1BjXDe4pKUhqsZomyp9ZQNHc9jVpitHu1o