[FFmpeg-user] Dealing with an intermittent rtsp source

Ben Barker ben at bbarker.co.uk
Sun May 30 20:15:21 EEST 2021

If I use ffmpeg to join an rtsp stream:

ffmpeg -i rtsp://<some_address> -vcodec copy -an -f mp4 <output>

This works fine. However, if the rtsp source becomes unavailable briefly -
for instance perhaps the network goes down, or the source is restarted,
then ffmpeg hangs on:

frame=xxx fps= 25 q=-1.0 q=-1.0 size=  211103kB time=.....

The frame counter does not increment - which is a sign that the stream has
hung - but I can't seem to programmatically detect that - so ffmpeg remains
running, but does not reconnect to the stream

I have tried various timeouts to handle this - without success so far. Is
there an obvious solution to this I am missing? If the source is not
present when ffmpeg is started, it will fail and I can handle that. But if
it fails once the stream has been joined, I seem to end up stuck....?

More information about the ffmpeg-user mailing list