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 video file.

How to do it...

Let's expand our VideoProcessor class in order to give it the ability to write video files. This is done using the OpenCV cv::VideoWriter class. An instance of this is therefore added as a member of our class (plus few other member variables):

class VideoProcessor { private: ... // the OpenCV video writer object cv::VideoWriter writer; // output filename std::string outputFile; ...

Get OpenCV 2 Computer Vision Application Programming Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.