Skip to content

Instantly share code, notes, and snippets.

@suzumura-ss
Created January 12, 2018 16:40
Show Gist options
  • Save suzumura-ss/7cd688b1fd3fb63c3c43e5417b2216e0 to your computer and use it in GitHub Desktop.
Save suzumura-ss/7cd688b1fd3fb63c3c43e5417b2216e0 to your computer and use it in GitHub Desktop.
openCV video i/o example
#include <opencv2/opencv.hpp>
#include <opencv2/video.hpp>
#pragma comment(lib, "opencv_core320.lib")
#pragma comment(lib, "opencv_videoio320.lib")
int main(int argc, const char* argv[])
{
if (argc != 3) {
return 1;
}
cv::VideoCapture videoReader(argv[1]);
if (!videoReader.isOpened()) {
printf("open failed - %s\n", argv[1]);
return 1;
}
double fps = videoReader.get(cv::CAP_PROP_FPS);
cv::Size size((int)videoReader.get(cv::CAP_PROP_FRAME_WIDTH), (int)videoReader.get(cv::CAP_PROP_FRAME_HEIGHT));
int fourcc = (int)videoReader.get(cv::CAP_PROP_FOURCC);
cv::VideoWriter videoWriter(argv[2], fourcc, fps, size, true);
if (!videoWriter.isOpened()) {
printf("open failed - %s\n", argv[2]);
return 1;
}
cv::Mat src;
while (videoReader.grab()) {
if (!videoReader.retrieve(src)) break;
videoWriter << src;
}
videoWriter.release();
videoReader.release();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment