Introduction

In this tutorial, you will learn how to stream on multiple platforms at once using the Nginx webserver. This will be done using the Nginx RTMP plugin.

Essentials

  1. Ubuntu 18.04 operating system.
  2. Docker engine installed. If you don’t have it installed, follow this guide.
  3. Nginx server compiled with the Nginx RTMP module.

The easiest way to have Nginx with the RTMP module up and running is using this docker image. All you have to do to download the image is to execute:

docker pull admintuts/nginx:1.19.6-rtmp-geoip2-alpine

Youtube-Twitch Nginx Configuration

rtmp {
    server {
        # port to listen on, I've left this as a default
        listen 1935;
        chunk_size 8192;

        # this is what you will stream to
        application live {
            live on;

            # record off means no vod saving
            record off;

            # allow publishing from all (change this to your ip if you wish to lock to ip address)
            allow publish all;

            # uncomment this if you are going to deny every ip other than yours
            # deny publish all;

            # push to all sub applications we will create (one each for each application)
            push rtmp://localhost/youtube;
            push rtmp://localhost/twitch;

            # for twitch I'm being more specific so I can define how my stream looks on twitch
            #exec ffmpeg -i rtmp://localhost/$app/$name -c:v libx264 -preset veryfast -c:a copy -b:v 6000k -bufsize 6000k -maxrate 3500k -s 1920x1080 -r 50 -f flv rtmp://localhost/twitch/$name;
        }

        # example youtube app
        application youtube {
            live on;
            record off;

            # only allow this machine to publish
            allow publish 127.0.0.1;
            deny publish all;

            # push url, this will be your stream url and stream key together
            push rtmp://a.rtmp.youtube.com/live2/youtube-stream-key;
        }

        # example twitch app
        application twitch {
            live on;
            record off;

            # only allow this machine to publish
            allow publish 127.0.0.1;
            deny publish all;

            # push url, this will be your stream url and stream key together
            push rtmp://live-ams.twitch.tv/app/twitch-stream-key;
        }
    }
}

What really happens under the hood is that Nginx is copying your own stream data, and republishing it to the locations we stated. In our case those are rtmp://localhost/youtube and rtmp://localhost/twitch.

These locations are utilizing the push command, in order to publish the incoming data stream (the one you are streaming on your server).

1 reply

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

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