我希望使用Python和OpenCV处理来自IP摄像头(交通监控)的mms视频流。该视频流无法受到我的控制。该视频流可用mms或mmst方案获取 -
mms://194.90.203.111/cam2
可以在VLC和Windows Media Player上播放。
mmst://194.90.203.111/cam2
仅适用于VLC。
我已经尝试使用FFmpeg和VLC重新流式传输来更改方案为HTTP,但没有成功。
据我所知,mms使用Windows Media Video对流进行编码。在URI末尾添加'.mjpeg'没有成功。我还没有找到OpenCV接受哪些类型的流。
这是我的代码 -
import cv2, platform
#import numpy as np
cam = "mms://194.90.203.111/cam2"
#cam = 0 # Use local webcam.
cap = cv2.VideoCapture(cam)
if not cap:
print("!!! Failed VideoCapture: invalid parameter!")
while(True):
# Capture frame-by-frame
ret, current_frame = cap.read()
if type(current_frame) == type(None):
print("!!! Couldn't read frame!")
break
# Display the resulting frame
cv2.imshow('frame',current_frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# release the capture
cap.release()
cv2.destroyAllWindows()
我漏掉了什么?OpenCV可以捕获哪种类型的视频流?是否有一种优雅的解决方案,而无需更改方案或进行转码?
谢谢!
Python版本为2.7.8,OpenCV版本为2.4.9,均为x86。操作系统为Win7 x64。