用python-opencv录制视频
学废只需要1分钟
import cv2 as cv
# 打开摄像头
cap = cv.VideoCapture(0)
# *mp4v是mp4在openCV里的写法
fourcc = cv.VideoWriter_fourcc(*'mp4v')
# (640,480)表示分辨率
# 30表示帧率
lz = cv.VideoWriter('D:/output.mp4',fourcc,30,(640,480))
while cap.isOpened():
# ret为标记,frame为帧数
ret,frame = cap.read()
# 如果没有读取,退出
if not ret:
break
# 写入每一帧
lz.write(frame)
cv.imshow('frame',frame)
if cv.waitKey(1) == ord('q'):
break
# 释放资源
cap.release()
lz.release()
cv.destroyAllWindows()