arut / nginx-rtmp-module

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

Disconnect loop during live streaming with on_publish callback #1330

Open jskebo opened 5 years ago

jskebo commented 5 years ago

Hello,

I'm experiencing a disconnect loop while live streaming with an on_publish callback. When viewing the stream, however, there does not seem to be any problems. Even with multiple bitrate variants being produced, viewing the stream seems to work as it should (there are no interrupts or choppiness).

The following is the section of logs which gets repeated:

| 127.0.0.1 [09/Nov/2018:20:31:32 +0000] PUBLISH "show" "e56bb3e4c325f3df362c5a5aa8dec398_240p" "" - 424 553 "" "FMLE/3.0 (compatible; Lavf58.12" (0s)
| 127.0.0.1 [09/Nov/2018:20:31:32 +0000] PLAY "local" "e56bb3e4c325f3df362c5a5aa8dec398" "" - 468 623668 "" "LNX 9,0,124,2" (2s)
| 2018/11/09 20:31:32 [notice] 22#22: signal 17 (SIGCHLD) received
| 2018/11/09 20:31:32 [notice] 22#22: unknown process 227 exited with code 1
| 2018/11/09 20:31:32 [info] 22#22: *102 exec: child 227 exited; ignoring, client: 172.18.0.1, server: 0.0.0.0:1935
| 2018/11/09 20:31:32 [info] 22#22: *102 exec: terminating child 227, client: 172.18.0.1, server: 0.0.0.0:1935
| 2018/11/09 20:31:37 [info] 22#22: *102 exec: starting managed child '/opt/ffmpeg/bin/ffmpeg', client: 172.18.0.1, server: 0.0.0.0:1935
| 2018/11/09 20:31:37 [info] 22#22: *172 client connected '127.0.0.1'
| 2018/11/09 20:31:37 [info] 22#22: *172 connect: app='local' args='' flashver='LNX 9,0,124,2' swf_url='' tc_url='rtmp://localhost:1935/local' page_url='' acodecs=4071 vcodecs=252 object_encoding=0, client: 127.0.0.1, server: 0.0.0.0:1935
| 2018/11/09 20:31:37 [info] 22#22: *172 createStream, client: 127.0.0.1, server: 0.0.0.0:1935
| 2018/11/09 20:31:37 [info] 22#22: *172 play: name='e56bb3e4c325f3df362c5a5aa8dec398' args='' start=-2000 duration=0 reset=0 silent=0, client: 127.0.0.1, server: 0.0.0.0:1935
| 2018/11/09 20:31:40 [info] 22#22: *173 client connected '127.0.0.1'
| 2018/11/09 20:31:40 [info] 22#22: *173 connect: app='show' args='' flashver='FMLE/3.0 (compatible; Lavf58.12' swf_url='' tc_url='rtmp://localhost:1935/show' page_url='' acodecs=0 vcodecs=0 object_encoding=0, client: 127.0.0.1, server: 0.0.0.0:1935
| 2018/11/09 20:31:40 [info] 22#22: *173 createStream, client: 127.0.0.1, server: 0.0.0.0:1935
| 2018/11/09 20:31:40 [info] 22#22: *173 publish: name='e56bb3e4c325f3df362c5a5aa8dec398_240p' args='' type=live silent=0, client: 127.0.0.1, server: 0.0.0.0:1935
| 2018/11/09 20:31:40 [error] 22#22: *173 live: already publishing, client: 127.0.0.1, server: 0.0.0.0:1935
| 2018/11/09 20:31:40 [info] 22#22: *173 disconnect, client: 127.0.0.1, server: 0.0.0.0:1935
| 2018/11/09 20:31:40 [info] 22#22: *173 deleteStream, client: 127.0.0.1, server: 0.0.0.0:1935
| 2018/11/09 20:31:40 [info] 22#22: *172 recv() failed (104: Connection reset by peer), client: 127.0.0.1, server: 0.0.0.0:1935
| 2018/11/09 20:31:40 [info] 22#22: *172 disconnect, client: 127.0.0.1, server: 0.0.0.0:1935
| 2018/11/09 20:31:40 [info] 22#22: *172 deleteStream, client: 127.0.0.1, server: 0.0.0.0:1935
| 127.0.0.1 [09/Nov/2018:20:31:40 +0000] PUBLISH "show" "e56bb3e4c325f3df362c5a5aa8dec398_240p" "" - 424 553 "" "FMLE/3.0 (compatible; Lavf58.12" (0s)
| 127.0.0.1 [09/Nov/2018:20:31:40 +0000] PLAY "local" "e56bb3e4c325f3df362c5a5aa8dec398" "" - 434 550080 "" "LNX 9,0,124,2" (2s)
| 2018/11/09 20:31:40 [notice] 22#22: signal 17 (SIGCHLD) received
| 2018/11/09 20:31:40 [notice] 22#22: unknown process 228 exited with code 1
| 2018/11/09 20:31:40 [info] 22#22: *102 exec: child 228 exited; ignoring, client: 172.18.0.1, server: 0.0.0.0:1935
| 2018/11/09 20:31:40 [info] 22#22: *102 exec: terminating child 228, client: 172.18.0.1, server: 0.0.0.0:1935
| 2018/11/09 20:31:45 [info] 22#22: *102 exec: starting managed child '/opt/ffmpeg/bin/ffmpeg', client: 172.18.0.1, server: 0.0.0.0:1935
| 2018/11/09 20:31:45 [info] 22#22: *174 client connected '127.0.0.1'
| 2018/11/09 20:31:45 [info] 22#22: *174 connect: app='local' args='' flashver='LNX 9,0,124,2' swf_url='' tc_url='rtmp://localhost:1935/local' page_url='' acodecs=4071 vcodecs=252 object_encoding=0, client: 127.0.0.1, server: 0.0.0.0:1935
| 2018/11/09 20:31:45 [info] 22#22: *174 createStream, client: 127.0.0.1, server: 0.0.0.0:1935
| 2018/11/09 20:31:45 [info] 22#22: *174 play: name='e56bb3e4c325f3df362c5a5aa8dec398' args='' start=-2000 duration=0 reset=0 silent=0, client: 127.0.0.1, server: 0.0.0.0:1935
| 2018/11/09 20:31:48 [info] 22#22: *175 client connected '127.0.0.1'
| 2018/11/09 20:31:48 [info] 22#22: *175 connect: app='show' args='' flashver='FMLE/3.0 (compatible; Lavf58.12' swf_url='' tc_url='rtmp://localhost:1935/show' page_url='' acodecs=0 vcodecs=0 object_encoding=0, client: 127.0.0.1, server: 0.0.0.0:1935
| 2018/11/09 20:31:48 [info] 22#22: *175 createStream, client: 127.0.0.1, server: 0.0.0.0:1935
| 2018/11/09 20:31:48 [info] 22#22: *175 publish: name='e56bb3e4c325f3df362c5a5aa8dec398_240p' args='' type=live silent=0, client: 127.0.0.1, server: 0.0.0.0:1935
| 2018/11/09 20:31:48 [error] 22#22: *175 live: already publishing, client: 127.0.0.1, server: 0.0.0.0:1935
| 2018/11/09 20:31:48 [info] 22#22: *175 disconnect, client: 127.0.0.1, server: 0.0.0.0:1935
| 2018/11/09 20:31:48 [info] 22#22: *175 deleteStream, client: 127.0.0.1, server: 0.0.0.0:1935
| 127.0.0.1 [09/Nov/2018:20:31:48 +0000] PUBLISH "show" "e56bb3e4c325f3df362c5a5aa8dec398_240p" "" - 424 553 "" "FMLE/3.0 (compatible; Lavf58.12" (0s)
| 127.0.0.1 [09/Nov/2018:20:31:48 +0000] PLAY "local" "e56bb3e4c325f3df362c5a5aa8dec398" "" - 426 627322 "" "LNX 9,0,124,2" (2s)

Here is part of the nginx.conf:

rtmp {
    server {
        listen 1935;
        chunk_size 4096;

        application local {
            live on;
            record all;
            record_path /tmp/vod/;
            allow publish all;
            allow play all;
            meta copy;
            sync 100ms;
            interleave on;
            wait_key on;
            wait_video on;
            drop_idle_publisher 15s;
            notify_method get;
            publish_notify on;
            idle_streams off;
            notify_relay_redirect on;

            exec_record_done /opt/ffmpeg/bin/ffmpeg -y -i $path -c copy /mnt/vod/$basename.mp4;

            exec /opt/ffmpeg/bin/ffmpeg -i rtmp://localhost:1935/local/$name
              -c:a libfdk_aac -b:a 64k  -c:v libx264 -b:v 500K  -vf "scale='if(gt(iw,ih),426,trunc(oh*a/2)*2)':'if(gt(iw,ih),trunc(ow/a/2)*2,426)'"   -tune zerolatency -preset ultrafast -crf 23 -g 60 -keyint_min 60 -sc_threshold 0 -maxrate 3000k -bufsize 4000k -f flv rtmp://localhost/show/$name_240p;

            exec_publish /opt/ffmpeg/bin/ffmpeg -i rtmp://localhost:1935/local/$name
              -frames:v 1 -ss 5 -y /mnt/thumbnails/$name.jpg;

            # Callbacks
            on_publish http://web:9000/streams/hooks/nxrtmp/on_publish;
            on_update http://web:9000/streams/hooks/nxrtmp/on_update;
            on_publish_done http://web:9000/streams/hooks/nxrtmp/on_publish_done;
        }

        application show {
            live on;
            hls on;
            allow publish all;
            allow play all;
            hls_path /tmp/hls;
            hls_fragment_slicing aligned;
            hls_fragment 5s;
            hls_playlist_length 15s;
            hls_sync 100ms;
            hls_nested off;
            meta copy;
            hls_type live;
            hls_base_url http://localhost/show/;
            hls_variant _240p BANDWIDTH=564000 RESOLUTION=426x240;
        }
    }
}

http {
    ...

    server {
        listen 80 default_server;
        server_name localhost;

        location /show {
            types {
                application/vnd.apple.mpegurl m3u8;
                video/mp2t ts;
                text/x-cross-domain-policy xml;
                image/png png;
                video/mp4 mp4;
            }

            alias /tmp/hls;
            add_header X-Cache-Status $upstream_cache_status;
            add_header 'Access-Control-Allow-Origin' '*';
        }

        ...
    }
}

Thanks.

winshining commented 5 years ago

The log showed that the grandchild process exited because of 'live: already publishing'. Maybe you need specify drop_idle_publisher in 'show' block. Hope that will work for you. Good luck!