Saturday, May 16, 2015

Setting up a NGINX RTMP Streaming Server

ESports, or non-technically the broadcasting of computer games for others to watch, has moved to the spotlight recently and is gathering a larger following than expected. Who would have thought that just watching video games would be more popular than actually playing them? As I have been playing Internet multiplayer games since purchasing Quake as a pre-release, the notion that others might be interested in my game was somewhat fascinating. I began streaming a few months ago on Twitch, but began to see more networks pop up and wondered how I could stream to more than one.


Introducing Real Time Messaging Protocol (RTMP), a service that was developed by Macromedia but released as open source after Adobe’s acquisition. One feature of RTMP allows you to stream video, from video-on-demand to direct broadcasting to pushing to other streaming carriers. The pushing to other carriers is what got me moving on RTMP as a viable solution, as I am using Open Broadcaster which is also open source.


Setting up an RTMP server took under an hour, and all feeds were pushing live in that same time frame. This tutorial is for CentOS or other similar varieties; RHEL, Scientific, etc. If you are looking for Ubuntu or LUbuntu, please visit here. Credit to OBS site for providing the baseline instructions, which I ported over to CentOS


Install CentOS 6 32bit minimal with 512mb RAM and 20GB drive space. The minimal install is highly recommended to eliminate the cleanup of Apache, etc. The system requirements were more than enough after testing 4 external feeds.


Install yum updates, GCC and GZIP; mlocate and nano which are optional.


yum update -y
yum install unzip gcc mlocate nano

Create a subdirectory for the installer stuff, so it can be easily deleted later. Downloaded the required applications and extract them. You can get the latest nginx download here, and the RTMP module always has the latest available using the link below.


mkdir install
cd install

wget http://nginx.org/download/nginx-1.9.0.tar.gz
wget https://github.com/arut/nginx-rtmp-module/archive/master.zip

tar -zxvf nginx*.gz
unzip master.zip

cd nginx*

Now configure, make and make install. You should not receive any errors or missing dependencies.


./configure --with-http_ssl_module --add-module=../nginx-rtmp-module-master
make
make install

Now start the service


/usr/local/nginx/sbin/nginx

To see if NGINX is working, visit you servers homepage and you will see an NGINX start page. Now we move on to added RTMP to NGINX’s config files. The files are located in these directories:


/usr/local/nginx/conf/nginx.conf

/usr/local/nginx/conf/nginx.conf.default


Open the file, scroll to the end and insert the text.


nano -w /usr/local/nginx/conf/nginx.conf

rtmp 
server
listen 1935;
chunk_size 4096;
application live
live on;
record off;




Now restart the service.


/usr/local/nginx/sbin/nginx -s stop
/usr/local/nginx/sbin/nginx

This part ends the standard install of NGINX and RTMP. Below goes into detail on how to configure the various services you can push your gaming stream to.


First we need to edit OBS (on your PC) for streaming to your custom server. Go to Settings -> Broadcast Settings and change the Streaming Service to “Custom”. Add the server we recently configured in the FMS URL box. The Play Path/Stream Key can be any variable, as it is not used in this tutorial.


Open Broadcaster custom server settings


Now add your external sources to push your feed when you go live. Some services only use one server (or smart routing), although Twitch has multiple servers. You can find a list of nearby Twitch servers here. It is suggested you pick one that is closest to your server if your PC is located in a different city.


All feeds follow the same basics: push rtmp://server_source.tld/streaming_key;


Edit NGINX config.


nano -w /usr/local/nginx/conf/nginx.conf

Insert your stream, example below.



rtmp
server
listen 1935;
chunk_size 4096;

application live
live on;
record off;
push rtmp://service.one.here/your_stream_key;
push rtmp://service.two.here/your_stream_key;




Restart NGINX, start your stream on your PC and open any streaming provider you placed in the config. Your streams are now being pushed to multiple sources.


Other minor settings to thing about is preventing someone else from using the streaming serverand deny local play. Add the following lines to your configuration. I suggest using a /24 range for your IP, as most ISP’s do not statically assign them.



rtmp
server
listen 1935;
chunk_size 4096;

application live
live on;
record off;
push rtmp://service.one.here/your_stream_key;
push rtmp://service.two.here/your_stream_key;
allow publish 123.45.67.89/24;
deny play all;




Restart NGINX.


If you found this tutorial helpful, please subscribe to my Twitch feed to show your support. Thanks!



Setting up a NGINX RTMP Streaming Server

#Centos, #Gaming, #GibTv, #HitboxTv, #Nginx, #OpenBroadcaster, #Rtmp, #Streaming, #Tutorial, #TwitchTv

5 comments:

  1. I have a 64 bit version of centos 6.7 how do i compile?

    ReplyDelete
  2. The steps for compiling are the same for 32bit and 64bit. The help was done using 32bit as it required fewer resources and drive space. Since the server only receives and re-broadcasts, there was no need to build a full blown 64bit system.

    ReplyDelete
  3. need help please add my skype

    skype > zorrohd

    thank

    ReplyDelete
  4. Hello,

    How would you add a custom stream key?

    ReplyDelete
    Replies
    1. Edit the file

      nano -w /usr/local/nginx/conf/nginx.conf

      Insert your stream, example below.

      rtmp
      server
      listen 1935;
      chunk_size 4096;

      application live
      live on;
      record off;
      push rtmp://service.one.here/your_stream_key;
      push rtmp://service.two.here/your_stream_key;

      Delete