arut / nginx-rtmp-module

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

FFMPEG sometime can not convert RTMP to HLS stream #1602

Open Hauham opened 3 years ago

Hauham commented 3 years ago

Hi team, thank you for your useful module but an issue was appeared when I using it, plz help me.

We have used nginx-rtmp-module and ffmpeg to convert rtmp to hls Everything works fine until a day .ts files are not created

The first, I guess may be nginx crash by something, I do reload nginx and everything is back to the way it was.

After that, I realized that nginx do not crash because at least nginx log work fine during the time the problem occurred

To use ngx_rtmp_module i have to add command load_module modules/ngx_rtmp_module.so; Is there any possibility that the error is caused by that module ?

What the happen in here ? What should I do to fix it ?

Here is my config _Ubuntu 18.04.5 LTS (GNU/Linux 5.4.0-1029-aws x8664) I use ffmpeg as a command line with format like : ffmpeg -i [input_rtmp] -f flv rtmp://localhost/hls/channelName

My nginx config

**load_module modules/ngx_rtmp_module.so;
pid        /var/run/nginx.pid;
error_log /opt/data/error.log info;
worker_processes 4;
worker_rlimit_nofile 16384;
events {
    worker_connections 4096;
}

rtmp {
    server {
        listen 1935;
        chunk_size 4096;
        max_message 1M;
        buflen 500ms;
        #live
        wait_key on;
        wait_video on;
        sync 200ms;
       application hls {
            live on;
            hls on;
            hls_fragment 1s;
            hls_type live;
            hls_playlist_length 60s;
            hls_path /opt/data/hls;
            hls_nested on;
            hls_continuous off;
            hls_cleanup on;

            hls_fragment_naming timestamp;
            hls_variant _720 BANDWIDTH=2628000,RESOLUTION=1280x720;
            hls_variant _480 BANDWIDTH=1128000,RESOLUTION=854x480;
            hls_variant _360 BANDWIDTH=878000,RESOLUTION=640x360;
            hls_variant _240 BANDWIDTH=528000,RESOLUTION=426x240;

            #IP Publish
            allow publish all;
            allow play all;
       }

    }
}

http {
    access_log /opt/data/access.log combined;
    sendfile        on;
    include       mime.types;
    keepalive_timeout  600;
    keepalive_requests 1000;
    ssl_ciphers         HIGH:!aNULL:!MD5;
    ssl_protocols       TLSv1 TLSv1.1 TLSv1.2;
    ssl_session_cache   shared:SSL:10m;
    ssl_session_timeout 10m;
    server {
        listen 8080;
        server_name localhost;
        # Uncomment these lines to enable SSL.
        # Update the ssl paths with your own certificate and private key.
        #listen 443 ssl;
        #ssl_certificate     /home/ubuntu/Transcode-to-HLS/certs/example.com.crt;
        #ssl_certificate_key /home/ubuntu/Transcode-to-HLS/certs/example.com.key;

        location /hls {
            types {
                application/vnd.apple.mpegurl m3u8;
                video/mp2t ts;
            }
            root /opt/data;
            #add_header Cache-Control no-cache;
            add_header Access-Control-Allow-Origin *;
            add_header Cache-Control "max-age=1";
            add_header X-Cache-Status *;
        }
        location /live {
          alias /opt/data/hls;
          types {
              application/vnd.apple.mpegurl m3u8;
              video/mp2t ts;
          }
          #add_header Cache-Control no-cache;
          add_header Access-Control-Allow-Origin *;
          add_header Cache-Control "max-age=1";
          add_header X-Cache-Status *;
        }
        location /stat {
            rtmp_stat all;
            rtmp_stat_stylesheet static/stat.xsl;
        }
        location /static {
            alias /www/static;
        }
        location = /crossdomain.xml {
            root /www/static;
            default_type text/xml;
            expires 24h;
        }
    }
}**
ZAX6 commented 3 years ago

I think the issue is that when you are using multi nginx worker " worker_processes 4; " , you have to set : "rtmp_auto_push on;" either set rtmp_auto_push or set the worket_processes to 1.

Hauham commented 3 years ago

Oh, thank for your response, I know process do not share stream, In order to share stream with another process, we need enable rtmp_auto_push. but this issue appeared before I used the 4 process (previous is 1 process). initillal I have just used 4 process for delivery media segment with hls.

I refer a same issue in Chinese community that is https://blog.csdn.net/ragecat/article/details/109385410?utm_medium=distribute.pc_relevant.none-task-blog-baidujs_title-1&spm=1001.2101.3001.4242

This indicated that the reason is missing option encode audio acc and I should add this option -v:a acc to convert, but it sometime so I don't know the way to reproduce issue. Do you think it okay ? Like this : ffmpeg -c:v h264_cuvid -v:a acc -i $link_rtmp -c:a aac -an -rc cbr -preset llhq -gpu any -delay 0 -b_ref_mode disabled -c:v h264_nvenc -b:v 1200K -g 15 -r 30 -vf scale_npp=1280:720 -hls_time 1 -hls_list_size 6 -f flv rtmp://localhost/hls/channel"$table"_720 ;