启动电脑摄像头录制10s视频(python+opencv)

启动电脑摄像头录制10s视频(python+opencv)

import cv2
#读取本地摄像头并设置视频格式。
capture = cv2.VideoCapture(0,cv2.CAP_DSHOW)
fourcc = cv2.VideoWriter_fourcc(* 'XVID')
fps = 20
output = cv2.VideoWriter("ten_Senconds.avi",fourcc,fps,(640,480))
frame_Num = 10* fps
#逐帧读取视频并保存
while(capture.isOpened() and frame_Num >0):
	retval,frame = capture.read()
	if retval == True:
		output.write(frame)
		cv2.imshow('frame',frame)
	key = cv2.waitKey(1)
	frame_Num -=1
#释放摄像头
capture.release()
output.release()
cv2.destroyALLWindows()

你可能感兴趣的:(opencv,python,音视频)