直接上代码
cv::VideoCapture cap;#用来从视频中获取图片.
cv::VideoWriter output_video;#用来将图片写入到视频中.
cap.open("./test.avi");
int video_fps = cap.get(CAP_PROP_FPS); //获取帧率
int width = cap.get(CAP_PROP_FRAME_WIDTH);//获取图像宽
int height = cap.get(CAP_PROP_FRAME_HEIGHT); //获取图像高
output_video.open("./result.avi", cv::VideoWriter::fourcc('D', 'I', 'V', 'X'), video_fps, Size(width,height), true);
while(cap.isOpened())
{
cv::Mat frame;
cap >> frame;#从视频中获取图片.
cv::Mat img=frame.clone();
output_video << img;#将图片写入到视频中.
}
output_video.release();