[英]How to record a video and save it from webcam?
I have a script to view and save webcam footage with Python.我有一个脚本可以使用 Python 查看和保存网络摄像头镜头。 However, it allows me to view the video but when its saved it saves a blank output.avi file and I dont know why can someone help;但是,它允许我查看视频,但是当它保存时,它会保存一个空白的 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()
Try not setting isColor to false.尽量不要将 isColor 设置为 false。
Your script worked for me with out = cv2.VideoWriter("output.avi", fourcc, 20.0, (rows, cols))
你的脚本对我out = cv2.VideoWriter("output.avi", fourcc, 20.0, (rows, cols))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.