视频捕获后无法在CV2中读取视频文件

问题描述 投票:0回答:1

我正在从我的网络摄像头捕获一个文件并将其保存:

fourcc = cv2.VideoWriter_fourcc('H','2','6','4')
out = cv2.VideoWriter(self.output_video_fn, fourcc, 20.0, (w, h), isColor = True)
flag = False
while not flag:
        success, buf = self.cam.read()
        print("******* Success is ", success)
        print(buf)
        if success == True:
            print("Wait")
            cv2.waitKey(1500) #todo delete after loop is good
            print("Here")
            flag = True
            # self.IAPS_TASK_IS_FINISHED = True
            # print(buf)
            out.write(buf)
    self.cam.release()
    print("Saved video to ", self.output_video_fn)

保存后我正试着玩它。我无法在VLC中播放(大小为162KB,并且持续时间为00:00)。我正在尝试在cv2中玩:

cap = cv2.VideoCapture(self.output_video_fn)

while(cap.isOpened()):
        ret, frame = cap.read()
        print("Ret is ", ret)
        print("frame is ", frame)

        cv2.imshow('frame', frame)
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break

cap.release()
cv2.destroyAllWindows()

但Ret是假的,框架是无。问题是什么?

python-3.x webcam video-capture video-processing cv2
1个回答
0
投票

我只使用OpenCV及其C和C ++ API,但如果您尝试编写包含Alpha通道的图像数据,或者如果编解码器在系统上不可用,我之前就注意到了VideoWriter问题。如果编解码器不存在,某些环境似乎不会导致异常。你能确认你有H264吗?

© www.soinside.com 2019 - 2024. All rights reserved.