Opencv provides classes and functions for reading videos, as well as classes and functions for generating a video from multiple frames or images.
For details, see:
Http://opencv.willowgarage.com/wiki/documentation/cpp/highgui/VideoWriter
Http://opencv.willowgarage.com/wiki/VideoCodecs
The following is a simple sample code for reading videos, processing video frames, and writing/saving videos:
// Read the video file, save the video file // Author: www.icvpr.com // blog: http://blog.csdn.net/icvpr # include <iostream> # include <string> # include <opencv2/opencv. HPP> int main (INT argc, char ** argv) {STD: String strinputname = "input. avi "; STD: String stroutputename =" output. avi "; // input videocv: videocapture capture (strinputname); If (! Capture. isopened () {STD: cout <"Open video error happened" <STD: Endl; Return-1 ;} // info of output videoint codec = static_cast <int> (capture. get (cv_cap_prop_fourcc); int framerate = capture. get (cv_cap_prop_fps); CV: Size framesize = CV: size (INT) capture. get (cv_cap_prop_frame_width), (INT) capture. get (cv_cap_prop_frame_height); CV: videowriter; writer. open (stroutputename, cv_fourcc ('D', 'I', 'V', 'x'), framerate, framesize, true); If (! Writer. isopened () {STD: cout <"cannot open the output video file for write" <STD: Endl; Return-1 ;}// process framecv :: mat frame; while (capture. read (FRAME) {// dosomething // save framewriter. write (FRAME); // display CV: imshow ("video", frame); If (CV: waitkey (framerate)> 0) // press any key to exit {break;} return 0 ;}
-------------------------------------------------------
<Reprint Please note: http://blog.csdn.net/icvpr>