5

I know this question has been asked infinite times, but it has not been answered with a decent answer infinite times as well.

How to make ffmpeg keep working even if source becomes unavailable? VLC waits until connection comes back again, why ffmepg does not have such functionality?

I have tried with:

-reconnect 1 -reconnect_at_eof 1 -reconnect_streamed 1 -reconnect_delay_max 4962 -timeout 2000000000

but none works as expected. FFmpeg quits after only few seconds. I don't want to restart ffmpeg if connection interrupts because I need output HLS fragments to be available. Restarting ffmpeg makes fragments to be overwritten from the beginning.

5

FFmpeg command line arguments are position sensitive, so maybe you are not adding them in the right position. Try to put those options before the input. Example:

ffmpeg -reconnect 1 -reconnect_at_eof 1 -reconnect_streamed 1 -reconnect_delay_max 2 -i input -c:v copy -c:a copy outputfile.m3u8

'reconnect_delay_max' range is [0 - 4294]

It worked for me.

  • I already use reconnecting parameters before the input URL. FFmpeg version is the latest. – Viktor Joras Mar 9 '16 at 9:29
  • I'm also using the latest version of ffmpeg in your option the 'reconnect_delay_max value need to be between [0 - 4294] yours is 4962 try with a lower value – slim tabka Mar 9 '16 at 9:47
  • Ok even with 4294 it makes no difference. Once the HTTP source is down it quits with: [http @ 0x1f986c0] Will reconnect at 26390596 error=Success. [http @ 0x1f986c0] Will reconnect at 0 error=Success. Last message repeated 2 times – Viktor Joras Mar 9 '16 at 9:54
  • Yes I know with 4962 it will not work, try this -reconnect_delay_max 2 just to test it, and if it doesn't work can you copy paste the whole command. – slim tabka Mar 9 '16 at 9:57
  • It resists 2 seconds, but are not enough. This is the whole command: /bin/ffmpeg -reconnect 1 -reconnect_at_eof 1 -reconnect_streamed 1 -reconnect_delay_max 2000 -timeout 2000000000 -y -thread_queue_size 5512 -nostats -nostdin -hide_banner -fflags +genpts -probesize 10000000 -analyzeduration 15000000 -i http://127.0.0.1:5555/video1 -strict -2 -dn -c copy -hls_flags delete_segments -hls_time 10 -hls_list_size 30 /root/list.m3u8 – Viktor Joras Mar 9 '16 at 10:01
1

I have solution for connection down! Just add option stimeout ( in microseconds )

ffmpeg -stimeout 10000000 \
-i rtsp://input_ip/h264 \
-c copy \
-f flv rtmp://output_ip
  • Set socket TCP I/O timeout in microseconds. It's not clear how this will help. – Ken Sharp May 24 '20 at 17:35
1

FFmpeg DOES NOT reconnect if the interruption lasts more than 4 seconds. When network session is lost ffmpeg quits.

The reason for this is that apparently the variable holding the maximum reconnect is 32-bits in size and contains a number which it divides by 1,000,000 to get a millisecond count. Hence the maximum wait is 2^32 / 1000000 = 4294.9673 milliseconds or 4.294 seconds.

  • 1
    This is not always true. Ffmpeg will stall sometimes, output halted, connection closed but the proccess is still alive. Try to suspend and resume connection. For me it happens also if the server i am connecting to is stalling for some reason, connection closed in log, but process is alive. – mmm Apr 3 '16 at 9:56
  • Not always true, sometimes? Is your theory reproducible? – Viktor Joras Jan 11 '18 at 18:06
  • This was a long time ago, but with poor connections it will still happen, yes, I believe. Difficult to reproduce unless the right circumstances are there. – mmm Jan 29 '18 at 17:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.