arut / nginx-rtmp-module

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

ffmpeg configuration #914

Open zareefhasan opened 7 years ago

zareefhasan commented 7 years ago

ffmpeg isn't working right. Here is my nging.config file. How to properly install ffmpeg for nginx-rtmp module. I have compiled from source from ffmpeg documentation.

#user  nobody;
worker_processes  1;

error_log  logs/error.log;
error_log  logs/error.log debug;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;

events {
    worker_connections  1024;
}

rtmp {
    server {
        listen 1935;

        application live {
             allow publish all;
             allow play all;
             live on;

             exec /root/bin/ffmpeg -i rtmp://localhost/live/$name
                        -c:v libx264 -c:a libfdk_aac -b:v 256k -b:a 32k
                        -f flv rtmp://localhost/hls/$name_low
                        -c:v libx264 -c:a libfdk_aac -b:v 768k -b:a 96k
                        -f flv rtmp://localhost/hls/$name_mid
                        -c:v libx264 -c:a libfdk_aac -b:v 1024k -b:a 128k
                        -f flv rtmp://localhost/hls/$name_hi;
        }

        application hls {
            live on;
            hls on;
            hls_path /mnt/hls;
            hls_fragment 15s;

            hls_variant _low BANDWIDTH=320000;
            hls_variant _mid BANDWIDTH=640000;
            hls_variant _hi  BANDWIDTH=960000;

        }

    }
}

http {

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

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {

        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        error_page  404              /404.html;
        error_page  500 502 503 504  /50x.html;

        location / {
            root   html;
            index  index.html index.htm;
        }

        location /hls {
            # Serve HLS fragments
            types {
                application/vnd.apple.mpegurl m3u8;
                video/mp2t ts;
            }
            root /mnt;
            add_header Cache-Control no-cache;
            add_header 'Access-Control-Allow-Origin' '*';
        }

        location /stat {
            rtmp_stat all;
            rtmp_stat_stylesheet stat.xsl;
        }

        location /stat.xsl {
            root html;
        }
    }
}
coditori commented 7 years ago

Have you installed FFMPEG with all it's own plugins?

zareefhasan commented 7 years ago

@massoudAfrashteh Yes, I have done it with this guide https://trac.ffmpeg.org/wiki/CompilationGuide/Ubuntu.

With normal apt-get installation there was a codec issue with libfdk_aac and then i rebuild it from source.

somosmultimedia commented 7 years ago

I recommend you testing first separately ffmpeg directly from terminal. and test only nginx rtmp alone. sometimes is about permissions of nginx to execute ffmpeg, but first needs to make shure both awork correctly intependtly

zareefhasan commented 7 years ago

@Somosmultimedia So much thanks for reply. Actually i have tested that command in terminal and ffmpeg successfully encoded and saved livestream into file. Streaming to application 'live' broadcast RTMP and streaming to application 'hls' broadcast single bitrate m3u8 file but there is no multibitrate m3u8. I think nginx is not able to execute ffmpeg. Please let me know can i set nginx permission to execute ffmpeg binary.

Thanks again

somosmultimedia commented 7 years ago

in the nginx.conf uncomment and set

user nobody;

to: user root;

somosmultimedia commented 7 years ago

then restart nginx

zareefhasan commented 7 years ago

The problem o found is ffmpeg was exiting continuously and find this soluition.

hls_continuous on;

Thanks everybody.