import cv2
cap = cv2.VideoCapture(1, cv2.CAP_DSHOW)
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 1920); #宽度
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 1080); #高度
cap.set(cv2.CAP_PROP_FPS, 30); #帧率 帧/秒
fourcc = cv2.VideoWriter_fourcc('X', 'V', 'I', 'D')
out = cv2.VideoWriter('testwrite.avi', fourcc, 30.0, (1920, 1080), True)
while (cap.isOpened()):
ret, frame = cap.read()
if ret == True:
cv2.imshow('frame', frame)
out.write(frame)
if cv2.waitKey(10) & 0xFF == ord('q'):
break
else:
break
cap.release()
out.release()
cv2.destroyAllWindows()
参考文献:
1.关于opencv更改摄像头参数(帧率,分辨率,曝光度……)的几个问题
2.cv::VideoWriter Class Reference
3.Video Codecs by FOURCC
4.cv2.VideoWriter() 指定写入视频帧编码格式
5.csdn cv2.VideoWriter()
6.OpenCV Python 录制视频