-
Notifications
You must be signed in to change notification settings - Fork 2
/
VideoRecorder.cxx
80 lines (66 loc) · 1.79 KB
/
VideoRecorder.cxx
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
#include <time.h>
#include <iostream>
#include <opencv2/opencv.hpp>
#include <opencv2/highgui.hpp>
#include "VideoRecorder.hxx"
using namespace std;
using namespace cv;
std::string ISentry::VideoRecorder::ext("avi");
ISentry::VideoRecorder::VideoRecorder(const libconfig::Setting& cfg):MediaRecorder(),n(0), writer(NULL)
{
enabled = cfg["enabled"];
dir=(const char *)(cfg["dir"]);
if(!cfg.lookupValue("max_width",max_width))
max_width=-1;
if(!cfg.lookupValue("max_videos",max_files))
max_files=-1;
if(!cfg.lookupValue("max_duration",max_duration))
max_duration=-1;
running = false;
}
void ISentry::VideoRecorder::addFrame(std::pair<cv::Mat,time_t> &m)
{
if(!running || !enabled)
return;
cv::Mat m_s;
rescale(m.first, m_s);
if(n==0)
{
// first frame
if(max_files > 0 && files_recorded++ >= max_files)
{
std::cerr << "NOT writing. Limit of " << max_files << " reached." << std::endl;
enabled = false; // Disable self
} else {
string fname = getFilename(m.second);
std::cerr << "Writing " << fname << std::endl;
writer = new cv::VideoWriter(fname,cv::VideoWriter::fourcc('D','I','V','X'), 30, m.first.size(), true);
//TODO: error handling
}
}
if(n++ == max_duration)
{
std::cerr << "Max video segment duration reached. Truncating." << std::endl;
stop();
} else
{
(*writer) << m.first;
n++;
}
}
void ISentry::VideoRecorder::start()
{
n=0;
FrameProcessor::start();
}
void ISentry::VideoRecorder::stop()
{
std::cerr << "Closing video segment." << std::endl;
n=0;
FrameProcessor::stop();
if(writer)
{
delete writer;
writer = NULL;
}
}