cv::string sFileName = "first.avi";
int nFourcc = CV_FOURCC('M', 'J', 'P', 'G');
int nFps = 30;
cv::Size nFrameSize = cv::Size(mat.cols, mat.rows);
cv::VideoWriter video;
video.open(sFileName, nFourcc, nFps, nFrameSize, true);
cv::cvtColor(mat, mat, CV_GRAY2BGR);//转彩色
for (int i = 0; i < 120; i++)
{
if (video.isOpened())
video.write(mat);
}
video.release();