opencv录制视频——CvVideoWriter

〇、参考
https://blog.csdn.net/zbbmm/article/details/76696979

一、几处关键的代码
1.CvVideoWriter *writer = 0;
2.writer=cvCreateVideoWriter(name_str.c_str(),CV_FOURCC(‘D’,‘I’,‘V’,‘X’),this->fps,cvSize(frameW,frameH),isColor); 3.cvReleaseVideoWriter(&this->writer);

二、说明
1.CVAPI (CvVideoWriter*) cvCreateVideoWriter( const char* filename, int fourcc, double fps, CvSize frame_size,int is_color CV_DEFAULT(1))的四个参数:
参数1:文件名
参数2:编码格式
参数3:视频格式大小,例如cvSize(640*480)
参数4:颜色,当isColor=-1时保存为灰度,当isColor>=1时,彩色视频

重点说一下参数2:
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
将上面的改成 -1 将会打开一个编码器的选择窗口.

2.cvReleaseVideoWriter:一定要在录制结束后,释放writer,如果不释放,会出现视频无法打开或者打开错误的问题,并且视频的总时长、帧数等信息缺失。

你可能感兴趣的:(opencv录制视频——CvVideoWriter)