arut / nginx-rtmp-module

NGINX-based Media Streaming Server
http://nginx-rtmp.blogspot.com
BSD 2-Clause "Simplified" License
13.35k stars 3.51k forks source link

Not an Issue, but looking for Suggest to setup Nginx-rtmp #675

Open nurwin opened 9 years ago

nurwin commented 9 years ago

Hello All, I'm beginner for nginx-rtmp and I wonder what is the best configuration that fits for my system.

Now I want to setup nginx-rtmp for broadcast live video from webcam. Server could receive 500+ publisher and allow anyone to play/stream to publisher they want. Client can access from web and mobile (android and iOS). Here is my cloud server spec: 4 CPU 9 GB of RAM 150 GB Storage

is it enough? Anyone has suggest for the best configuration server? I try to setup, but it's really lag and always freeze. and when I use exec ffmpeg, it is not working. For publishing live webcam to server, I use OBS.

Thanks for your suggest.

Here is my conf:

worker_processes  1;
error_log  logs/error.log debug;

events {
    worker_connections  1024;
}
rtmp {
    server {
            listen 1935;
            allow play all;

            application live {
                    allow play all;
                    live on;
                    hls on;
                    hls_path /HLS/live;
                    hls_fragment 10s;

                    exec /usr/bin/ffmpeg -i rtmp://localhost:1935/live/$name -c:v libx264 -c:a libfaac -ar 44100 -ac 1 -f flv rtmp://localhost:1935/mobile/$name;
            }

            application mobile {
                    allow play all;
                    live on;
                    hls on;
                    hls_path /HLS/mobile;
                    hls_fragment 10s;
            }
    }
}
http {
    include       mime.types;
    default_type  application/octet-stream;

    server {
            listen 8000;
            server_name localhost;

            location /live {
                    types {
                            application/vnd.apple.mpegurl m3u8;
                            video/mp2t ts;
                    }
                    alias /HLS/live;
                    add_header Cache-Control no-cache;
                    add_header Access-Control-Allow-Origin *;
            }

            location /mobile {
                    types {
                            application/vnd.apple.mpegurl m3u8;
                            video/mp2t ts;
                    }
                    alias /HLS/mobile;
                    add_header Cache-Control no-cache;
                    add_header Access-Control-Allow-Origin *;
            }
            #allows us to see how stats on viewers on our Nginx site using a URL like: "http://my-ip/stats"
            location /stats {
                    rtmp_stat all;
            }

            #allows us to host some webpages which can show our videos: "http://my-ip/my-page.html"
            location / {
                    root   html;
                    index  index.html index.htm;
            }
    }
}
chriswiggins commented 9 years ago

Highly recommend you look at putting your HLS fragments on a RAM-based mount. Look into ramfs/tmpfs for this. The reason you'll be finding it lags is because the server has to write each HLS segment to disk and then subsequently read this back from disk for each client you have connected