ffmpeg keep connection if network source down

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.


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 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

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.