demo.py
import cv2, time
cap = cv2.VideoCapture(0)
fps = cap.get(cv2.CAP_PROP_FPS)
fourcc = cv2.VideoWriter_fourcc(*'XVID')
size = (int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)),
int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)))
# 10s保存一次
save_time = 10
start_time = time.time() - 11
while True:
end_time = time.time()
if end_time - start_time > save_time:
out = cv2.VideoWriter(f'camera_{end_time}.avi', fourcc, fps, size)
start_time = end_time
ret, frame = cap.read()
frame = cv2.flip(frame, 1)
out.write(frame)