Python与IP摄像头的问题
我在从我拥有的IP摄像头获取视频流时遇到了问题。我正在使用opencv来获取图像。以下是我写的代码:
import sys
import cv
video="http://prot-on.dyndns.org:8080/video2.mjpeg"
capture =cv.CaptureFromFile(video)
cv.NamedWindow('Video Stream', 1 )
while True:
# capture the current frame
frame = cv.QueryFrame(capture)
if frame is None:
break
else:
#detect(frame)
cv.ShowImage('Video Stream', frame)
if k == 0x1b: # ESC
print 'ESC pressed. Exiting ...'
break
实际上,这个代码是能工作的,但显示图像的时间太长了。我猜这可能是因为ffmpeg出现了这个错误。
[mjpeg @ 0x8cd0940]max_analyze_duration reached
[mjpeg @ 0x8cd0940]Estimating duration from bitrate, this may be inaccurate
我对python不是很熟悉,所以任何帮助都非常感谢!
1 个回答
1
首先,mjpeg是一种比较简单的视频格式。如果你查看你的IP摄像头的说明书,可能会发现用一点JavaScript代码就能在浏览器中显示视频。实际上,如果你在Google Chrome中打开这个链接:http://prot-on.dyndns.org:8080/video2.mjpeg,你会发现视频可以正常播放。(不过,最好不要公开你摄像头的真实网址)
其次,从我看到的情况来看,你的摄像头的帧率比较慢。这可能是因为网络延迟或者是你摄像头的设置。你可以把在Chrome中看到的画面和你代码显示的视频进行比较,如果它们的质量差不多,那就说明问题不在你的代码上。