arut / nginx-rtmp-module

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

Stream publishing reconnect issue #415

Open gregoryking opened 10 years ago

gregoryking commented 10 years ago

I'm having a problem whereby a stream published to ustream.tv terminates and does not restart again automatically. When I restart nginx, the stream resumes publishing no problem. Streams are staying up 1 to 2 days before dying.

Within my nginx.conf I am calling a shell script as follows:

exec_static /root/rtmp-nginx.sh;

And the relevant ffmpeg line from my script is publishing from a webcam to both a local RTMP stream and ustream:

/opt/vc/bin/raspivid -vf -n -mm spot -w 1280 -h 720 -fps 25 -g 100 -t 0 -b 750000 -o - | ffmpeg -loglevel debug -y -f h264 -i - -c:v copy -an -metadata title="My title" -f flv $RTMP_URL/$STREAM_KEY -c:v copy -f flv -rtmp_buffer 100 -rtmp_live live rtmp://localhost/rtmp/live &

This is the message I receive in my ffmepg log after the stream stops:

[AVIOContext @ 0x1a08920] Statistics: 0 seeks, 1472067 writeouts
[rtmp @ 0x1a0bd20] UnPublishing stream...
[rtmp @ 0x1a0bd20] Deleting stream...
[AVIOContext @ 0x1a0a6e0] Statistics: 0 seeks, 1472066 writeouts
[rtmp @ 0x1a0a2b0] UnPublishing stream...
[rtmp @ 0x1a0a2b0] Deleting stream...
[AVIOContext @ 0x197c550] Statistics: 5398827008 bytes read, 0 seeks

So why is my stream not restarting publishing automatically? And is it reaching some sort of limit that forces the publishing to be terminated?

Apologies if this question better belongs in a forum....I couldn't find one.

Greg

ghost commented 10 years ago

have a similiar problem. couldnt solved it yet. rtmp module is killing my source connection about every 19-20 hours

misiek08 commented 10 years ago

Simple

while true do
"your command here"
done; 

Should do the thing.

ghost commented 10 years ago

not using raspberry pi, i have my own transcoding software (libav based), seems like rtmp module disconnects source after 14-15gb of received data. i have applied fmle byte reset branch testing again

gregoryking commented 10 years ago

I've compiled a build of nginx-rtmp-module (1.1.4) on nginx 1.4.1 with debug flag set. Seems to run much the same as before and this is the debug message I am getting in the nginx error log when streaming stops:

2014/06/13 18:52:56 [info] 24006#0: *1 deleteStream, client: 127.0.0.1, server: 0.0.0.0:1935
2014/06/13 18:52:56 [info] 24006#0: *1 disconnect, client: 127.0.0.1, server: 0.0.0.0:1935
2014/06/13 18:52:56 [info] 24006#0: *1 recv() failed (104: Connection reset by peer), client: 127.0.0.1, server: 0.0.0.0:1935
2014/06/13 18:52:56 [info] 24006#0: *1 deleteStream, client: 127.0.0.1, server: 0.0.0.0:1935

I'm guessing that ustream may be dropping the connection and nginx-rtmp not restarting after a failure. Should it be restarting? This is only a guess. As a dirty hack I'm considering watching the ffmpeg logs for "Deleting stream..." messages and rebooting nginx on observing them.

ghost commented 10 years ago

fmle byte reset branch solved my problem. I had 25 hours uptime without disconnection (before, it was 19 hours max) and about 17GB input (btw; i was using nginx mainline, i recompiled the stable version).

arut commented 10 years ago

Looks like the remote end closes the connection. That can happen if an rtmp endpoint does not reply with an acknowledgement packet when a certain amount of bytes are received. I had this issue with fmle, however it's fixed long ago.