Environment
macOS Catalina 10.15.6
OpenCV
Python 3.8
Tyhoon HAISHEN is coming!
Source Code
import cv2 RATE = 30 cap = cv2.VideoCapture(0) w = cap.get(cv2.CAP_PROP_FRAME_WIDTH) h = cap.get(cv2.CAP_PROP_FRAME_HEIGHT) fps = cap.get(cv2.CAP_PROP_FPS) fourcc = cv2.VideoWriter_fourcc(*'h264') out = cv2.VideoWriter('out.mp4', fourcc, fps, (int(w), int(h))) count = RATE while True: ret, frame = cap.read() if ret == True: if count == 0: out.write(frame) count = RATE count -= 1 cv2.imshow('frame', frame) keyboard = cv2.waitKey(30) if keyboard == 27: break else: break cap.release() out.release() cv2.destroyAllWindows()