Writing video sequences
In the previous recipes, we learned how to read a video file and extract its frames. This recipe will show you how to write frames and, therefore, create a video file. This will allow us to complete the typical video-processing chain: reading an input video stream, processing its frames, and then storing the results in a new video file.
How to do it...
Writing video files in OpenCV is done using the cv::VideoWriter
class. An instance is constructed by specifying the filename, the frame rate at which the generated video should play, the size of each frame, and whether or not the video will be created in color:
writer.open(outputFile, // filename codec, // codec to be used framerate, // frame rate of the video frameSize, // frame size isColor); // color video?
In addition, you must specify the way you want the video data to be saved. This is the codec
argument; this...