Using a VPS for streaming.

A Lot of people now a days enjoy using services as twitch or youtube to deliver videos to there viewers. This works great if you have a strong computer with a good internet conection but what if you don’t have those things?  Well thats where a private RTPM VPS comes in to play, the RTMP servers allows you to push your streams to multiple website’s.

this will decrease CPU use and bandwidth use on your own computer which results in better streams. This guide will cover the very basics of setting up a simple RTMP server on a Linux computer. Don’t worry, it’s not too complicated, but having familiarity with Linux will certainly help

Step 1: Get a VPS
if your going to choose Hostslim as your VPS provider we recommend using the popular package for optimal performance. In this guide where using Ubuntu 14.04 for the sake of ease. But you can also use other linux distro’s if you want.

Step 2: Installing nginx with RTMP module

Log into your VPS, and make sure you have the necessary tools to build nginx using the following command:
$ sudo apt-get install build-essential libpcre3 libpcre3-dev libssl-dev

Now a bit of info about nginx (pronounced “engine-X”). nginx is an extremely lightweight web server, but someone wrote a RTMP module for it, so it can host RTMP streams too. However, to add the RTMP module, we have to compile nginx from source rather than use the apt package.

From your home directory, download the nginx source code:
$ wget http://nginx.org/download/nginx-1.9.15.tar.gz

As of this writing, the latest stable version of nginx is 1.9.15. You can find the latest version on the nginx download page.

Next, get the RTMP module source code from git:
$ wget https://github.com/arut/nginx-rtmp-module/archive/master.zip
Unpack/unzip them both, and enter the nginx directory:
$ tar -zxvf nginx-1.9.15.tar.gz
$ unzip master.zip
$ cd nginx-1.9.15
Now we build nginx:
$ ./configure –with-http_ssl_module –add-module=../nginx-rtmp-module-master
$ make
$ sudo make install
And nginx is installed! By default it installs to /usr/local/nginx, so to start the server run the following command:
$ sudo /usr/local/nginx/sbin/nginx

And to test to make sure nginx is running, point your browser to
http://<your server ip>/ and you should get the “Welcome to nginx!” page.

Step 3: Configuring nginx to use RTMP
Open your config file, located by default at /usr/local/nginx/conf/nginx.conf and add the following at the very end of the file:
rtmp {
server {
listen 1935;
chunk_size 4096;

application live {
live on;
record off;
}
}
}

This is an extremely basic configuration with a “live” application that simply forwards the RTMP stream on to whoever requests it.
Restart nginx with:
$ sudo /usr/local/nginx/sbin/nginx -s stop
$ sudo /usr/local/nginx/sbin/nginx
Step 4: Testing & pusing to other streaming services

Your server should now be ready to accept RTMP streams. In the broadcasting settings of your streaming software for instance https://obsproject.com/ place the following settings:

Streaming Service: Custom
Server: rtmp://<your server ip>/live
Play Path/Stream Key: test
You may be wondering where that play path “test” came from. Well, we just made it up, just now. You can basically make up any play path and stream to it, and put that path into an RTMP player, and it will play back.
You should now be able to start streaming to your server. If you hit “Start Streaming” and don’t get an error, that’s a good sign.
What now?
To forward to other streaming services you can add multiple “pushes” to the stream to multiple locations. Below is a example for pushing the rtpm to your Twitch & Youtube:
rtmp {
server {
listen 1935;
chunk_size 4096;

application live {
live on;
record off;
push rtmp://rtmp://live-ams.twitch.tv/app/stream key>;
push rtmp://a.rtmp.youtube.com/live2/[streamkeyfromyoutube];
}
}
}
And any stream streamed to that application will be forwarded on to the other service, as well as being served up from the server!

Share This Post

Leave a Reply

Your email address will not be published. Required fields are marked *