From aeece7b98ccf7f9ff9f9e8d1b85971166c07441a Mon Sep 17 00:00:00 2001 From: blakeblackshear Date: Wed, 20 Feb 2019 07:12:07 -0600 Subject: [PATCH] handle RTSP stream errors --- detect_objects.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/detect_objects.py b/detect_objects.py index d61b665a2..75c6bd235 100644 --- a/detect_objects.py +++ b/detect_objects.py @@ -360,11 +360,18 @@ def fetch_frames(shared_arr, shared_frame_time, frame_lock, frame_ready, frame_s arr = tonumpyarray(shared_arr).reshape(frame_shape) # start the video capture - video = cv2.VideoCapture(RTSP_URL) + video = cv2.VideoCapture() + video.open(RTSP_URL) # keep the buffer small so we minimize old data video.set(cv2.CAP_PROP_BUFFERSIZE,1) while True: + # check if the video stream is still open, and reopen if needed + if not video.isOpened(): + success = video.open(RTSP_URL) + if not success: + time.sleep(1) + continue # grab the frame, but dont decode it yet ret = video.grab() # snapshot the time the frame was grabbed