While trying to read a video stream form an IP camera using:
stream = cv2.VideoCapture(src)
(grabbed, frame) = stream.read()
The grabbed returns True while sometimes the frames are corrupted (probably due to high CPU load). An internal Opencv error like the following is showing on the terminal:
[h264 @ 0x25e99400] error while decoding MB 87 29, bytestream -5
Is there a way to catch this error? Please note that I tried the obvious try:except with cv2.error etc. In such case of corrupted frame it would be preferable to restart the connection to the camera.
isOpened()to check if the camera is corrupted. It allows you to skip the broken video and go on to the next one but the error message will still be printed.if stream.isOpened():then attempt to read a frameisOpened()is not a good option since the RTSP stream was already initialized and it will always returnTrue. The problem occurs due to high CPU load during processing and not at initialization time.