3

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.

4
  • 2
    Not an OpenCV error, that's ffmpeg error log message... so nothing to catch there. Commented Oct 27, 2019 at 20:27
  • Thank you, is there a way to catch this ffmpeg error from Python API? Commented Oct 28, 2019 at 6:09
  • I believe you can use 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 frame Commented Oct 28, 2019 at 20:16
  • Hi @nathancy, thank you for your comment. Unfortunately, isOpened() is not a good option since the RTSP stream was already initialized and it will always return True. The problem occurs due to high CPU load during processing and not at initialization time. Commented Oct 29, 2019 at 6:18

1 Answer 1

1

Any cpp output/error can be retrieved from Python using wurlitzer

from wurlitzer import pipes
with pipes() as (out, err):
   <any call to cpp code>

c_error = err.read()
Sign up to request clarification or add additional context in comments.

2 Comments

Did you figure out what caused the "error while decoding MB" error?
It can happen if you use UDP protocol and your network connection to the camera is slow.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.