simple-nvr icon indicating copy to clipboard operation
simple-nvr copied to clipboard

Retry mechanism

Open 7aklhz opened this issue 2 years ago • 3 comments

Hi. Thank you for sharing your code and experience. I'm looking at https://medium.com/@tom.humph/saving-rtsp-camera-streams-with-ffmpeg-baab7e80d767 and was wondering if you know how to implement and handle retry / relaunch on (stream) error?

7aklhz avatar Nov 25 '23 05:11 7aklhz

I've tried a couple of approaches.

The first method had the logic for connecting and saving the stream encapsulated within a class. This class has logic to catch disconnection errors and reopen the connection. However after a few days this would drop the connection in a way that wasn't caught. I was never sure how it slipped through as the stream just... stopped.

The second method involved creating a separate "watcher" method / service. It checked the folder the video files were saved into for changes to files. If there were no changes for at least X seconds it would assume that the stream had crashed. It would then tell the stream class kill the stream (if still open), and try to open it again.
This didn't always pick up crashed streams immediately, but did prove to be more reliable.

I'd be interested to hear what solution you've come up with!

TomHumphries avatar Dec 05 '23 21:12 TomHumphries

This is actually what I ended up doing : https://gist.github.com/7aklhz/87bdf1bf2e1e06f77633b4949a0d948c

I make an infinity loop that tries to curl the url. If 200 ok then start ffmpeg if not retry curl after 5 seconds.

7aklhz avatar Dec 05 '23 21:12 7aklhz

Nice, thanks!

TomHumphries avatar Dec 05 '23 21:12 TomHumphries