Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to retrieve FFMPEG (called from OpenCV) Python decoding error

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.

like image 965
Amit_JCI Avatar asked Nov 20 '25 11:11

Amit_JCI


1 Answers

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()
like image 135
Amit_JCI Avatar answered Nov 22 '25 00:11

Amit_JCI



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!