解码MB 171、1,字节流-27时出错

问题描述

我有一个应用程序,在其中我从海康威视摄像机读取了两个RTSP流,并进行处理。因为它是热像仪,所以有两个流,它有两个流,一个是普通流,另一个是热流。 这是我阅读流的方式:

import cv2
normal_path = "rtsp://adress@192.168.1.120/Streaming/channels/102"
thermal_path = "rtsp://adress@192.168.1.120/Streaming/channels/201"
normal_capture = cv2.VideoCapture(normal_path)
thermal_capture = cv2.VideoCapture(thermal_path)
while True:
    try:
        ret,thermal_frame = thermal_capture.read(0)
        ret1,normal_frame = normal_capture.read(0)
        #do a lot of things
    except:
        continue

normal_capture.release()
thermal_capture.release()
cv2.destroyAllWindows()

问题是,例如,一段时间后,在应用正常运行5个小时后,它会收到如下错误

[h264 @ 0x2ac51c0] error while decoding MB 17 1,bytestream -27

有人知道为什么会这样吗?您知道为什么这个错误会超出try和except吗?

解决方法

我在使用单个流时遇到了同样的问题,尽管我遇到它的时间要早​​得多(进入流的几分钟)。我通过检查 ret 是否不是 True 来处理它 如果是,则重建流。

import cv2
thermal_path = "rtsp://adress@192.168.1.120/Streaming/channels/201"
thermal_capture = cv2.VideoCapture(thermal_path)
while True:

    ret,thermal_frame = thermal_capture.read(0)
    if not ret:
        thermal_capture.release()
        thermal_capture = cv2.VideoCapture(thermal_path)
        print('Found error; rebuilding stream')

    #do a lot of things

thermal_capture.release()
cv2.destroyAllWindows()