-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.cpp
46 lines (34 loc) · 1.03 KB
/
test.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
#include "video_encoder.h"
#include <iostream>
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
int main() {
VideoCapture cap("./input/office.mp4");
if(!cap.isOpened()){
cout<<"cannot open file."<<endl;
return 1;
}
int width = cap.get(CV_CAP_PROP_FRAME_WIDTH);
int height = cap.get(CV_CAP_PROP_FRAME_HEIGHT);
VideoEncoder encoder("./output/office.h264", Size(width, height), VideoEncoder::VIDEO_CODEC_H264);
encoder.disableBitrateControl();
encoder.init();
int initialization_flag = encoder.getInitializationFlag();
if(initialization_flag < 0) {
cerr<<"Error: main.cpp: Video encoder initialization failed with error code: "<<initialization_flag<<endl;
return 1;
} else if(initialization_flag > 0)
cerr<<"Warning: main.cpp: Video encoder initialization warning with warning code: "<<initialization_flag<<endl;
while(1){
Mat frame;
bool bSuccess = cap.read(frame);
if(!bSuccess){
cout<<"cannot read frame."<<endl;
break;
}
encoder.write(frame);
}
encoder.flush_close();
return 0;
}