#include <opencv2/opencv.hpp> #include <iostream> using namespace cv; using namespace std; int main(int argc, char** argv) { VideoCapture capture(0); if (!capture.isOpened()) { printf("could not load video data...\n"); return -1; } double fps = capture.get(CV_CAP_PROP_FPS); // 获取视频帧fps Size size = Size(capture.get(CV_CAP_PROP_FRAME_WIDTH), capture.get(CV_CAP_PROP_FRAME_HEIGHT)); //获取帧图像的宽度和高度 size( , ) printf("FPS : %f", fps); VideoWriter writer("L:/opencv_picture/wv_demo.mp4", CV_FOURCC('D', 'I', 'V', 'X'), 15.0, size, true); //将摄像头采集的视频写到一个mp4的文件中 //VideoWriter writer 函数的参数: //1.文件位置名称格式 2.编码器(为-1时可以选着编码方式)3.录制帧数 4.录制视频的size 5.true // create window Mat frame; namedWindow("video-demo", CV_WINDOW_AUTOSIZE); // show each frame and save while (capture.read(frame)) { imshow("video-demo", frame); writer.write(frame); char c = waitKey(100); if (c == 27) { break; } } waitKey(0); return 0; }