Python 如何录制视频并从网络摄像头保存?
我有一个脚本,可以用Python查看和保存网络摄像头的镜头。然而,它允许我查看视频,但当它保存时,它保存了一个空白的output.avi文件,我不知道为什么有人可以帮助Python 如何录制视频并从网络摄像头保存?,python,cv2,Python,Cv2,我有一个脚本,可以用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))) ou
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))
我使用cv2.VideoCapture(1)作为我需要的第二台网络摄像机的镜头