import cv2
cam = cv2.VideoCapture(0) # Começa a gravar
# out = cv2.VideoWriter('Teste.avi', -1, 20.0, (640, 480))
fourcc = cv2.VideoWriter_fourcc(*'XVID')
out = cv2.VideoWriter('path//of//location//output.avi',fourcc, 20.0, (640,480))
while (cam.isOpened()):
op,frame = cam.read()
if (op == True):
out.write(frame)
cv2.imshow('frame',frame)
if cv2.waitKey(1) & 0xFF == ord('x'):
break
else:
break
cam.release()
out.release()
cv2.destroyAllWindows()
Если у вас есть сомнения, вы можете обратиться к документации .