-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvideo-recorder.cpp
87 lines (69 loc) · 2.06 KB
/
video-recorder.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
77
78
79
80
81
82
83
84
85
86
87
#include "opencv2/opencv.hpp"
#include <iostream>
#include <stdio.h>
#include <chrono>
#include <ctime>
using namespace std;
using namespace cv;
int main(int argc, const char** argv)
{
VideoCapture video0;
video0.set(CAP_PROP_FRAME_WIDTH, 640.0);
video0.set(CAP_PROP_FRAME_HEIGHT, 480.0);
video0.set(CAP_PROP_FPS, 25.0);
video0.set(CAP_PROP_FOURCC, CV_FOURCC('X','2', '6', '4'));
video0.set(CAP_PROP_AUTOFOCUS, 1);
video0.set(CAP_PROP_CONVERT_RGB, 1);
video0.open("/dev/video2");
if (!video0.isOpened()) {
cerr << "ERROR: Unable to open device" << endl;
return 1;
}
VideoCapture video1;
video1.set(CAP_PROP_FRAME_WIDTH, 640.0);
video1.set(CAP_PROP_FRAME_HEIGHT, 480.0);
video1.set(CAP_PROP_FPS, 25.0);
video1.set(CAP_PROP_FOURCC, CV_FOURCC('X','2', '6', '4'));
video1.set(CAP_PROP_AUTOFOCUS, 1);
video1.set(CAP_PROP_CONVERT_RGB, 1);
video1.open("/dev/video3");
if (!video1.isOpened()) {
cerr << "ERROR: Unable to open device" << endl;
return 1;
}
Size resolution = Size(640, 480);
bool isColor = true;
int codec = CV_FOURCC('M', 'J', 'P', 'G');
double fps = 25.0;
string filename = "./out.mkv";
string filename2 = "./out2.mkv";
VideoWriter writer;
writer.open(filename, codec, fps, resolution);
if (!writer.isOpened()) {
cerr << "ERROR: Could not open output file for write" << endl;
return 1;
}
VideoWriter writer2;
writer2.open(filename2, codec, fps, resolution);
if (!writer2.isOpened()) {
cerr << "ERROR: Could not open output file for write" << endl;
return 1;
}
unsigned int totalFrames = 30 * fps;
unsigned int qtdFrames = 0;
Mat frame;
Mat frame2;
cout << "Start recording.." << endl;
for(;;) {
video0.read(frame);
writer.write(frame);
video1.read(frame2);
writer2.write(frame2);
qtdFrames++;
if (qtdFrames == totalFrames) {
break;
}
}
cout << "End recording" << endl;
return 0;
}