writer = cv.CreateVideoWriter('out.mp4', cv.CV_FOURCC('F', 'M', 'P', '4'),
    fps, frame_size, True)
if not writer:
    sys.stdout.write('!!! Error in creating video writer')
sys.exit(1)
while True:
    if not cv.GrabFrame(cap):
        break
frame = cv.RetrieveFrame(cap)
cv.WriteFrame(writer, frame)
cv.ReleaseVideoWriter(writer)
cv.ReleaseCapture(cap)
Making a video with opencv and ffmpeg. How to find the right color format?