Skip to content

Instantly share code, notes, and snippets.

@33Fraise33
Created April 25, 2018 13:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 33Fraise33/e3b61788041676f853a65fd34f622725 to your computer and use it in GitHub Desktop.
Save 33Fraise33/e3b61788041676f853a65fd34f622725 to your computer and use it in GitHub Desktop.

RTMP Nginx Setup

Commands needed to install

mkdir nginx
cd nginx
sudo apt install build-essential libpcre3 libpcre3-dev libssl-dev
sudo git clone git://github.com/arut/nginx-rtmp-module.git
sudo wget http://nginx.org/download/nginx-1.13.4.tar.gz
sudo tar xzf nginx-1.13.4.tar.gz
cd nginx-1.13.4/
sudo ./configure --with-http_ssl_module --add-module=../nginx-rtmp-module
sudo make
sudo make install
sudo /usr/local/nginx/sbin/nginx (-s reload)

mkdir /tmp/hls
mkdir /tmp/dash
mkdir /tmp/rec
sudo chmod 777 /tmp/hls
sudo chmod 777 /tmp/dash
sudo chmod 777 /tmp/rec

Used config for initial testing

#user  nobody;
worker_processes  1;

error_log  logs/error.log debug;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;
    keepalive_timeout  65;

    server {
        listen       80;
        server_name  localhost;

        location /stat {
            rtmp_stat all;
            rtmp_stat_stylesheet stat.xsl;
        }
        location /stat.xsl {
            root /home/besports/nginx/nginx-rtmp-module;
        }

        location /control {
            rtmp_control all;
        }

        location /dash {
            alias /tmp/dash;
        }

        location /hls {
            root /tmp;
            types {
                application/vnd.apple.mpegurl m3u8;
                video/mp2t ts;
            }
            add_header Cache-Control no-cache;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

rtmp {
    server {
        listen 1935;
        chunk_size 4096;

        allow publish 127.0.0.1;
        deny publish all;

        application myapp {
            live on;
            record all;
            record_suffix _%Y-%m-%d-%H-%M-%S.flv;
            record_path /mnt/d/Recordings/;

            push rtmp://live-ams.twitch.tv/app/<key-here>;
            #push rtmp://rtmp-api.facebook.com:80/rtmp/<key-here>;

            #hls on;
            #hls_path /tmp/hls;

            #dash on;
            #dash_path /tmp/dash;
        }
    }
}

stream to: rtmp://servername/myapp/
key: test

Playing RTMP: rtmp://servername/myapp/test (no - 3s delay)
Playing HLS: http://servername/hls/test.m3u8 (1 min delay)
Playing Dash: http://servername/dash/test.mpd (1 min delay)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment