OPENCV C++保存视频

    //视频保存位置
       string outputVideoPath = "/home/lhc/_20211209204549292.avi";

       //打开摄像头
       VideoCapture capture0(0);

       VideoWriter outputVideo;
       //获取当前摄像头的视频信息
       cv::Size S = cv::Size((int)capture0.get(CV_CAP_PROP_FRAME_WIDTH),
                             (int)capture0.get(CV_CAP_PROP_FRAME_HEIGHT));
       //打开视频路劲,设置基本信息 open函数中你参数跟上面给出的VideoWriter函数是一样的
       outputVideo.open(outputVideoPath, CV_FOURCC('P','I','M','1'), 20.0, S, true);
       //

       if (!outputVideo.isOpened()) {
           cout << "fail to open!" << endl;
       }


       cv::Mat frameImage;
       int count = 0;

       while(true) {
           //读取当前帧
           capture0 >> frameImage;

           if (frameImage.empty()) break;

           ++count;
           //输出当前帧
           cv::imshow("output", frameImage);
           //保存当前帧
           outputVideo << frameImage;

           if (char(waitKey(1)) == 'q') break;
       }


       std::cout << "TotalFrame: " << count << std::endl;

你可能感兴趣的:(c++,opencv,音视频)