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 专家,所以任何帮助将不胜感激!
I'm having problems to get a video stream from a IP camera I have. I'm using opencv to get the images from it. Here's the code i have:
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
Actually, this thing works, but it takes too much time to display the images. I'm guessing it's because of this error from ffmpeg.
[mjpeg @ 0x8cd0940]max_analyze_duration reached
[mjpeg @ 0x8cd0940]Estimating duration from bitrate, this may be inaccurate
I'm not a python expert so any help would be appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,mjpeg是一种相对简单的视频格式。如果您阅读网络摄像机的手册,您就可以找到如何使用一些 JavaScript 代码在浏览器中显示视频。事实上,如果您打开 http://prot-on.dyndns.org:8080 的链接/video2.mjpeg 在 Google Chrome 中,您可以毫无问题地观看视频。 (也许你不应该留下相机的真实URL)
其次,据我所知,你的相机的帧速率相当慢。这可能是由于互联网延迟或相机设置造成的。将您在 Chrome 中看到的内容与您的代码显示的视频进行比较,如果它们具有相同的质量,那么这不是您的代码的问题。
First, mjpeg is a relatively simple video format. If you read your IP camera's manual, it's very like that you can find how to display the video in browser with a bit JavaScript code. In fact, if you open link of http://prot-on.dyndns.org:8080/video2.mjpeg in Google Chrome, you would see the video without any problem. (Maybe you shouldn't leave the real URL of your camera)
Second, as far as I can see, the frame rate of your camera is pretty slow. That might due to Internet latency or your camera's setting. Compare what you see in Chrome with the video displayed by your code, if they are of same quality, then it's not your code's problem.