8
int main(int argc, char** argv)
12
std::cerr << "You must specify SOURCE\n";
19
std::cout << "[Detector] N = " << n << std::endl;
24
std::cout << "[Detector] K = " << k << std::endl;
29
// gopSize = atoi(argv[4]);
30
// std::cout << "GOP = " << gopSize << std::endl;
32
std::string source(argv[1]);
33
std::cout << "[Detector] Start processing \"" << source.c_str() << "\"" << std::endl;
35
auto kB = [](int B) { return static_cast<float>(B) / 1024.0f; };
36
auto isKeyFrame = [](int flags) { return flags & AV_PKT_FLAG_KEY; };
38
FFmpegH264Demuxer demuxer(source.c_str());
39
StatsCollector collector(n);
40
EventTrigger trigger(1, 8);
42
uint8_t* pktData{nullptr};
49
uint64_t firstKeyFrame = 0;
52
demuxer.Demux(&pktData, &pktSize, &pktPts, &pktFlags);
53
if (!isKeyFrame(pktFlags))
61
// if (0 == firstKeyFrame)
63
// if (isKeyFrame(pktFlags))
65
// firstKeyFrame = fno;
73
// bool isKeyFrame2 = ((fno - firstKeyFrame) % gopSize == 0);
80
const auto kBytes = kB(pktSize);
82
if (IFrames > static_cast<uint64_t>(n/2))
84
const int state = trigger.update( collector.outlier(kBytes, k) );
85
if (EventTrigger::ABOUT_TO_ON == state)
88
int min = floor(pktPts / 1000.0 / 60.0);
89
int sec = floor(pktPts / 1000.0) - 60.0*min;
90
std::cout << "[Detector] EVENT! Outlier at "
92
<< " | frame #" << IFrames
93
<< " | " << min << ":" << sec
98
collector.collect(kBytes);
102
std::cout << "[Detector] Processed " << fno << " packets" << std::endl;
103
std::cout << "[Detector] Processed " << IFrames << " I-frames" << std::endl;
104
std::cout << "[Detector] Caught " << nEvents << " events" << std::endl;
106
std::cout << "[Detector] Processing finished\n";