cv2.VideoWriter(filename, fourcc, fps, frameSize, isColor=None) -> retval
cv2.VideoWriter.open(filename, fourcc, fps, frameSize, isColor=None) -> retval
cv2.VideoWriter.isOpened() -> retval
cv2.VideoWriter.write(image) -> None
import cv2
cap = cv2.VideoCapture(0)
w = round(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
h = round(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
fps = cap.get(cv2.CAP_PROP_FPS)
fourcc = cv2.VideoWriter_fourcc(*'DIVX') # *'DIVX' == 'D', 'I', 'V', 'X'
delay = round(1000 / fps)
out = cv2.VideoWriter('output.avi', fourcc, fps, (w, h))
while True:
ret, frame = cap.read()
out.write(frame)
cv2.imshow('frame', frame)
if cv2.waitKey(delay) == 27:
break
Reference
1) 제로베이스 데이터스쿨 강의자료