sistason / rtmp_stream_delayer

Uses ffmpeg and nginx to delay (buffer) an incoming rtmp-stream for an amount of time.
GNU General Public License v2.0
42 stars 12 forks source link

FFMPEG will stop or crash then a restart will not work #10

Open Trauni opened 3 years ago

Trauni commented 3 years ago

Hello another big topic which happend a few times. . Sometimes the ffmpeg encoder stops to work with 2 errors:

I am not that programmer and I really dont understand a word in python but I found those two things: https://stackoverflow.com/questions/38156265/getting-av-interleaved-write-frame-broken-pipe-error https://stackoverflow.com/questions/50300013/ffmpeg-streaming-stops-after-few-seconds

I dont know if this is already in your code and I also dont know if this will solve my problems.

The biggest issue is, that we cant restart the stream after those errors without restarting the whole nginx service. Normally the python should work on again after restarting the stream automatically, but it dont do that.

Quick note: we have 2-4 scripts running at the same time in several "screens".

Trauni commented 3 years ago

av_interleaved_write_frame(): Broken pipekB time=00:46:17.96 bitrate=9769.3kbits/s speed= 1x [flv @ 0x55ea88606680] Failed to update header with correct duration. [flv @ 0x55ea88606680] Failed to update header with correct filesize. Error writing trailer of rtmp://213.190.31.69/becleanfeed/live: Broken pipe frame=166686 fps= 60 q=-1.0 Lsize= 3312947kB time=00:46:18.06 bitrate=9769.3kbits/s speed= 1x video:3281190kB audio:26354kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.163330% Conversion failed! ERROR:main:Publish stream threw exception Command '['ffmpeg', '-re', '-i', '/home/beingrtmp/record/regie/paul-1617639601.flv', '-codec', 'copy', '-f', 'flv', 'rtmp://213.190.31.69/becleanfeed/live']' returned non-zero exit status 1.

sistason commented 3 years ago

From what I read in the stackoverflow, that does not seem to be a python / delayer issue. The script just starts ffmpeg in the background and waits for it to exit/crash. It does not open any pipes nor checks stdout/stderr.

It seems more likely that it is a stream problem or even with nginx, when you need to restart that afterwards. something with buffers?

Trauni commented 3 years ago

Yes thats true but I saw an workaround with not writing the duration as an command option and other options:

This: https://stackoverflow.com/questions/803265/getting-realtime-output-using-subprocess And THIS: At the end of muxing a flv file, FFmpeg updates the header (at front of file) with duration and filesize values. However, when you are streaming, ffmpeg can't seek to the front, so the warnings are displayed.

You can disable this function, by adding a flag (-flvflags no_duration_filesize), e.g.: ffmpeg -re -i SampleM.flv -acodec libmp3lame -ar 44100 -b:a 128k \ -pix_fmt yuv420p -profile:v baseline -s 426x240 -bufsize 6000k \ -vb 400k -maxrate 1500k -deinterlace -vcodec libx264 \ -preset veryfast -g 30 -r 30 -f flv \ -flvflags no_duration_filesize \ "rtmp://live-api.facebook.com:80/rtmp/my_key"

And my question was, is this already in your script or can you do this?

sistason commented 3 years ago

Try to set the new FFMPEG_EXTRA_OPTS as FFMPEG_EXTRA_OPTS = ['-flvflags no_duration_filesize'] in the config, which hopefully solves that flv problem :)

Trauni commented 3 years ago

just as a new row?

Trauni commented 3 years ago

like

STREAM_DESTINATION = 'rtmp://...' DELAY = 900 # Seconds SINGLE = False # Set to true to just delay a single stream and exit, no reconnecting/backup-streams BACKUPSTREAM_SHORT = '' # Show while intermission BACKUPSTREAM_LONG = '' # Show while longer downtime FFMPEG_EXECUTABLE = "ffmpeg" # Use avconv if you need FFMPEG_EXTRA_OPTS = ['-flvflags no_duration_filesize']

sistason commented 3 years ago

yes. Although I think I made a mistake and it has to be

FFMPEG_EXTRA_OPTS = ['-flvflags', 'no_duration_filesize']