[英]How to get http stream from wifi camera compressed format: h.264 on python?
Hy.嗨。 I am working on a project for school using a HD-eyewear Wifi Camera that uses H.264 compressed format, I have read a lot of documentation about how to get the frames from the camera.我正在为学校开发一个使用 H.264 压缩格式的高清眼镜 Wifi 摄像头的项目,我已经阅读了很多关于如何从摄像头获取帧的文档。 but I shouldn't manage my problem: My code looks like this:但我不应该解决我的问题:我的代码如下所示:
import cv2
while True:
cap = cv2.VideoCapture('http://admin:@192.168.10.1/videostream.asf?user=admin&pwd=')
ret, frame = cap.read()
print(frame)
I only want to see that it gets correctly the frames, but it drops errors like this:我只想看到它能正确获取帧,但它会丢弃这样的错误:
[h264 @ 0x1e0a100] non-existing PPS 0 referenced
[h264 @ 0x1e0a100] non-existing PPS 0 referenced
[h264 @ 0x1e0a100] decode_slice_header error
[h264 @ 0x1e0a100] no frame!
I really apreciate the help: Thanks!我非常感谢您的帮助:谢谢! :D :D
With a little help from comments, I could solve my problem, and works, with some initial frame loss.在评论的帮助下,我可以解决我的问题,并且可以工作,但会丢失一些初始帧。
import cv2
from threading import Thread
import time
url = ('http://admin:@192.168.10.1/videostream.asf?user=admin&pwd=')
class VideoStream(object):
def __init__(self,url = ('http://admin:@192.168.10.1/videostream.asf?user=admin&pwd=')):
self.capture = cv2.VideoCapture(url)
self.thread = Thread(target=self.update, args=())
self.thread.daemon = True
self.thread.start()
def update(self):
while True:
if self.capture.isOpened():
(self.status, self.frame) = self.capture.read()
time.sleep(.01)
def show_frame(self):
cv2.imshow('frame', self.frame)
key = cv2.waitKey(1)
if key == ord('q'):
self.capture.release()
cv2.destroyAllWindows()
exit(1)
if __name__ == '__main__':
video_stream = VideoStream()
while True:
try:
video_stream.show_frame()
except AttributeError:
pass
Copied from this link: Video Streaming from IP Camera in Python Using OpenCV cv2.VideoCapture从此链接复制: Video Streaming from IP Camera in Python Using OpenCV cv2.VideoCapture
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.