-
Notifications
You must be signed in to change notification settings - Fork 0
/
split_video_frames.cpp
76 lines (69 loc) · 1.57 KB
/
split_video_frames.cpp
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
takes video file as parameter and
split video to the corresponding
frames into jpg images
@author sudhanshu singh chauhan
*/
#include<iostream>
#include<string>
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "boost/lexical_cast.hpp"
using namespace std;
using namespace cv;
//command line argument keys
const char* keys =
{
"{help h usage? || print this message}"
"{@video || Video File, if not defined then exit program}"
};
int main(int argc, char **argv){
//parser object to process command line parameters
CommandLineParser parser(argc, argv, keys);
parser.about("split_video_frames v1.0.0");
if(parser.has("help")){
parser.printMessage();
return 0;
}
//getting video file name in command
//line parameter
string videoFile = parser.get<String>(0);
if(!parser.check()){
parser.printErrors();
return 0;
}
VideoCapture cap; //to capture the video file
if(videoFile != ""){
cap.open(videoFile);
}
else{
cout<<"no video file provided!.."<<endl;
cout<<"exiting.. bye"<<endl;
}
if(!cap.isOpened()){
return -1;
}
int frame_count = 0;
//processing each frame and
//saving it as jpg image file
for(;;){
Mat frame;
cap >> frame;
string file_name = "frame";
if(!frame.empty()){
file_name += boost::lexical_cast<string>(frame_count);
file_name += ".jpg";
imwrite(file_name, frame);
}
//break the loop when no more
//frames are left
else{
break;
}
frame_count++;
}
//release the video capture object when done
//so that program doesnt block anymore
cap.release();
return EXIT_SUCCESS;
}