核心函数:
1. cvCreateFileCapture
2. cvGetCaptureProperty
3. cvQueryFrame
4. cvCreateVideoWriter
5. cvWriteFrame
程序:
#include "cv.h"#include "cxcore.h"#include "highgui.h"#include#include int Vedio(int argc,char** argv){CvCapture* SrcCapture=cvCreateFileCapture("e:\\vedio\\1.avi"); //读取视频文件cvNamedWindow("src");cvNamedWindow("GRAY");IplImage* SrcImage=NULL;int fps=cvGetCaptureProperty(SrcCapture,CV_CAP_PROP_FPS); //获取视频文件信息CvSize size=cvSize(cvGetCaptureProperty(SrcCapture,CV_CAP_PROP_FRAME_WIDTH),cvGetCaptureProperty(SrcCapture,CV_CAP_PROP_FRAME_HEIGHT));CvVideoWriter *VideoWriter=cvCreateVideoWriter("e:\\vedio\\3.avi",CV_FOURCC('X','V','I','D'),fps,size); //创建写入文件信息SrcImage=cvQueryFrame(SrcCapture);IplImage* Gray=cvCreateImage(cvGetSize(SrcImage),8,1);while(1){SrcImage=cvQueryFrame(SrcCapture); //获取每一帧图像if(SrcImage==NULL){break;}cvShowImage("src",SrcImage);cvCvtColor(SrcImage,Gray,CV_BGR2GRAY);cvShowImage("GRAY",Gray);cvWriteFrame(VideoWriter,Gray); //保存文件char c=cvWaitKey(10);if(c==27){break;}}//cvWaitKey(0);cvDestroyWindow("src");cvDestroyWindow("GRAY");cvReleaseCapture(&SrcCapture);cvReleaseVideoWriter(&VideoWriter);return 0;}