如何从wifi摄像头获取http流压缩格式:python上的h.264?

2024-04-20 12:50:35 发布

您现在位置:Python中文网/ 问答频道 /正文

嘿!我正在为学校做一个使用高清眼镜Wifi摄像头的项目,该摄像头使用H.264压缩格式。我已经阅读了很多关于如何从相机获取帧的文档,但是我不应该管理我的问题。我的代码如下所示:

import cv2

while True:
    cap = cv2.VideoCapture('http://admin:@192.168.10.1/videostream.asf?user=admin&pwd=') 
    ret, frame = cap.read()
    print(frame) 

我只想看到它正确地获取帧,但它会删除如下错误:

[h264 @ 0x1e0a100] non-existing PPS 0 referenced

[h264 @ 0x1e0a100] non-existing PPS 0 referenced

[h264 @ 0x1e0a100] decode_slice_header error

[h264 @ 0x1e0a100] no frame!

我真的很感激你的帮助!谢谢D


Tags: 项目admin格式cv2frame学校wifi摄像头
1条回答
网友
1楼 · 发布于 2024-04-20 12:50:35

在评论的帮助下,我可以解决我的问题,并在初始帧丢失的情况下工作

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

从该链接复制:Video Streaming from IP Camera in Python Using OpenCV cv2.VideoCapture

相关问题 更多 >