我有一个应用程序,在里面我可以从hikvision摄像头读取两个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中出现吗?
发布于 2021-01-23 08:24:25
我在单个流中遇到了同样的问题,尽管我遇到的时间要早得多(在流中只有几分钟)。我通过检查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()https://stackoverflow.com/questions/64464169
复制相似问题