繁体   English   中英

如何录制视频并从网络摄像头保存?

[英]How to record a video and save it from webcam?

我有一个脚本可以使用 Python 查看和保存网络摄像头镜头。 但是,它允许我查看视频,但是当它保存时,它会保存一个空白的 output.avi 文件,我不知道为什么有人可以提供帮助;

import cv2

cv2.namedWindow("preview")
vc = cv2.VideoCapture(1)
fourcc = cv2.VideoWriter_fourcc(*'XVID')
rows = (int(vc.get(3)))
cols = (int(vc.get(4)))
out = cv2.VideoWriter("output.avi", fourcc, 20.0, (rows, cols), False)
        
if vc.isOpened(): # try to get the first frame
    rval, frame = vc.read()
else:
    rval = False


while rval:
    
    rval, frame = vc.read()
    cv2.imshow("preview", frame)
    out.write(frame)
    key = cv2.waitKey(20)

    if key == 27: # exit on ESC
        vc.release()
        out.release()
        break



cv2.destroyAllWindows()

尽量不要将 isColor 设置为 false。

你的脚本对我out = cv2.VideoWriter("output.avi", fourcc, 20.0, (rows, cols))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM