EDIT: At the time of this writing there is no functionality within FFMPEG that can detect/handle when an RTP/RTSP stream is still active but is no longer delivering valid frames. The only solution I could find was to periodically reset the stream by stopping recording, then reconnecting and starting a new recording which -f segment
does NOT do.
I'm recording an RTSP stream from a network camera with FFMPEG, and after some time (usually about an hour and a half to two hours). I'm sure it's specifically a problem with the cameras I'm using and not FFMPEG or my system resources.
What specifically happens is the video freezes but network traffic with the camera continues - it just doesn't seem to send new frames. Because of this behaviour FFMPEG doesn't disconnect/keeps recording because the network connection is still alive. After a few minutes there will always be a single warning in the FFMPEG output:
More than 1000 frames duplicated
But it keeps recording - it's just the same frame over and over.
The command I'm using is:
ffmpeg -stimeout 1000000 -rtsp_transport udp -fflags discardcorrupt -i rtsp://192.168.1.163/live/0/MAIN -vc libx265 -f segment -segment_time 300 -segment_atclocktime 1 -reset_timestamps 1 -strftime 1 "163-%Y-%m-%d_%H-%M-%S-h265.mp4"
Some notes:
- stimeout doesn't seem to do anything as the network connection is maintained the camera just seems to stop sending (valid) frames.
- Changing the codec to copy doesn't improve the issue
- Changing the RTSP transport doesn't improve the issue
- I'm aware there is a filter to detect frozen frames, but my FFMPEG does not seem to have it - I'm going to try and build FFMPEG myself now; but would much prefer a solution that works with bundled FFMPEG ~> 4.1.3
Having FFMPEG fail and exit after > 1000 frames are duplicated would actually be ideal, as then I can just spawn FFMPEG from a script, monitor the process, and restart it when the process ends. Any solution would be great though.