Split Video

Split Video to a batch of pictures

Input: Video file path, Output directory
Output: png from frame to frame

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/*************************************************************************
> File Name: SplitVideo.cpp
> Author: zyy
> Mail: zyy34472@gmail.com
************************************************************************/


#include <unistd.h>
#include <iostream>
#include <opencv2/opencv.hpp>
#include <video.hpp>

using namespace std;
using namespace cv;

int main (int argc, char** argv)
{

if (argc < 3) {
cout << "[Usage] " << endl;
cout << "\t ./SplitVideo filename outputdir" << endl;
return -1;
}
string outdir = string(argv[2]);
string cmd = "mkdir " + outdir +" 2>/dev/null";
system(cmd.c_str());
VideoCapture vc;
vc.open(argv[1]);
if (!vc.isOpened()) {
cout << "Cann't open " << argv[1] <<endl;
return -1;
}
Mat frame;
for (int i = 1; vc.read(frame); i++)
imwrite(outdir+ "/" + to_string(i) + ".png", frame);
return 0;
}

Contents
  1. 1. Split Video to a batch of pictures