Save a video file with OpenCV

Saving a video file

  • Initializing a video writer: CvVideoWriter *writer = 0;
    int isColor = 1;
    int fps = 25; // or 30
    int frameW = 640; // 744 for firewire cameras
    int frameH = 480; // 480 for firewire cameras
    writer=cvCreateVideoWriter("out.avi",CV_FOURCC('P' ,'I','M','1'),
    fps,cvSize(frameW,frameH),isColor);
    Other possible codec codes:
    CV_FOURCC('P','I','M','1') = MPEG-1 codec
    CV_FOURCC('M','J','P','G') = motion-jpeg codec (does not work well)
    CV_FOURCC('M', 'P', '4', '2') = MPEG-4.2 codec
    CV_FOURCC('D', 'I', 'V', '3') = MPEG-4.3 codec
    CV_FOURCC('D', 'I', 'V', 'X') = MPEG-4 codec
    CV_FOURCC('U', '2', '6', '3') = H263 codec
    CV_FOURCC('I', '2', '6', '3') = H263I codec
    CV_FOURCC('F', 'L', 'V', '1') = FLV1 codec
    A codec code of -1 will open a codec selection window (in windows).  All codecs need to be installed by yourself!!!
  • Writing the video file: IplImage* img = 0;
    int nFrames = 50;
    for(i=0;i<nFrames;i++){
    cvGrabFrame(capture); // capture a frame
    img=cvRetrieveFrame(capture); // retrieve the captured frame
    cvWriteFrame(writer,img); // add the frame to the file
    }
    To view the captured frames during capture, add the following in the loop:
    cvShowImage("mainWin", img);
    key=cvWaitKey(20); // wait 20 ms
    Note that without the 20[msec] delay the captured sequence is not displayed
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值