arut / nginx-rtmp-module

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

ffmpeg randomly not starting #1634

Open HarryG3 opened 3 years ago

HarryG3 commented 3 years ago

We am using ffmpeg with nginx rtmp module to simply remux the rtmp stream and push to another application in the same nginx.conf. Running on: Ubuntu 20.04 LTS (GNU/Linux 5.4.0-26-generic x86_64)

We are getting random errors logged in the nginx debug log like this (due to which ffmpeg does not push the stream because ffmpeg could not start): 2021/09/18 15:58:52 [info] 2324903#0: 25319 exec: starting managed child '/usr/local/bin/dash.sh', client: xxx.xxx.4.34, server: 0.0.0.0:1935 2021/09/18 15:58:52 [info] 2324903#0: 25319 exec: fork failed (12: Cannot allocate memory), client: xxx.xxx.4.34, server: 0.0.0.0:1935

Note that this does not happen every time we give an input stream to nginx rtmp on port 1935. This happens randomly - and as ffmpeg does not start due to the memory error - the stream does not get pushed.

The RAM / Swap files etc are more than 90% FREE when this error occurs, so this does not appear to be memory related.

Our nginx.conf is as follows, we are using ffmpeg to just remux the rtmp stream and push it from live_abc application to dashout_xyz:

user root;

user nginx root;

user ffmpeg root;

user nobody;

worker_processes 1;

worker_processes auto;

error_log logs/error_error.log error; error_log logs/error_debug.log debug; error_log logs/error_notice.log notice; error_log logs/error_warn.log warn;

error_log logs/error.log info;

worker_rlimit_nofile 65536;

pid logs/nginx.pid;

events { use epoll; worker_connections 4096; multi_accept on; }

rtmp_auto_push on; rtmp_auto_push_reconnect 1s; rtmp_socket_dir /tmp/sock;

rtmp { server { listen 1935;

application live_abc
    { 
                   live on;
        record off;

        allow publish all;

        allow play all;

        interleave on;

        drop_idle_publisher 10s;

        exec_push /usr/bin/ffmpeg -i rtmp://localhost:1935/live_abc/$name -codec copy -f flv rtmp://localhost:1935/dashout_xyz/$name ;         

    }

application dashout_xyz 
    {
      live on;
      record off;
      dash on;
      #dash_nested on; 
      #dash_repetition on;
      dash_path /tmp/dash;
      #drop_idle_publisher 10s;
      dash_fragment 2; # 4 second is generaly a good choice for live
      dash_playlist_length 6; # keep 120s of tail
      dash_cleanup on;

      dash_cenc on;
      dash_cenc_kid abbaxxxxxxxxxxxxxxxxxxxxx4a9a5d9;
      dash_cenc_key 69eaaxxxxxxxxxxxxxxxxxxxxfb88390;

    } # application dashout_b6Zr9LQXJ3 

} # server

} #rtmp

http {

default_type  application/octet-stream;

# to boost I/O on HDD we can disable access logs
access_log off;

sendfile        on;
 tcp_nopush on;
 tcp_nodelay on;

output_buffers          5  200k;

keepalive_requests 1000;

keepalive_timeout  65;

#gzip  on;

server 
{
    listen       80;
    server_name  localhost;

    #charset koi8-r;

    #access_log  logs/host.access.log  main;

    location / {
        #root   /tmp/stream123;
        root  /tmp/dash;

        add_header Cache-Control no-cache;
        add_header 'Access-Control-Allow-Origin' '*';
    }

    types 
    {
        text/html html;
        application/dash+xml mpd;
     }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }

} # server

} # http

Request any help/hints as to what the issue is or how do we go about finding out what the issue is.

laureen71 commented 3 years ago

Had a similar issue, I added the following arguments to ffmpeg command line:

ffmpeg -re -hide_banner ...

maybe that helps you as well!