You should try the OpenCV library, reading and writing images and videos .
CreateVideoWriter
CreateVideoWriter (filename, fourcc, fps, frame_size, is_color) -> CvVideoWriter Creates a record of video files.
Parameters: filename (str) - name of the output video file. fourcc (int) - The 4-character codec code used to compress frames. For example, CV_FOURCC ('P', 'I', 'M,' 1 ') is the MPEG-1 codec, CV_FOURCC (' M ',' J ',' P ',' G ') is the motion-jpeg codec, and so on. .d. In Win32, you can pass -1 to select a compression method and additional compression options from the dialog. In Win32, if 0 is used when using the avi name, it will create a video recorder that creates an uncompressed AVI file. fps (float) - Barometer of the created video stream. frame_size (CvSize) - The size of the video frames. is_color (int). If it is not equal to zero, the encoder expects and encodes color frames, otherwise it will work with frames in grayscale (the flag is currently only supported on Windows). The cvCreateVideoWriter function creates a video recording structure.
Writeframe
WriteFrame (author, image) -> int Writes a frame to a video file.
Parameters: writer (CvVideoWriter) - video recording structure image (IplImage) - recorded frame The cvWriteFrame function writes / adds one frame to a video file.
here is another link.
Ivica source share