v2.1.t1
- reduced the hls size to 2 seconds. - motion clips are not being combined. fixed it by making event loop track the size of shared_t::recList instead of system time. - maxScore is now global inside of shared_t instead of locally inside detectMoInStream().
This commit is contained in:
parent
19872b3ff5
commit
bafd2bf727
|
@ -350,8 +350,3 @@ string genVidNameFromLive(const string &tsPath)
|
|||
return string();
|
||||
}
|
||||
}
|
||||
|
||||
uint64_t genEpoch()
|
||||
{
|
||||
return duration_cast<seconds>(system_clock::now().time_since_epoch()).count();
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ using namespace std;
|
|||
using namespace std::filesystem;
|
||||
using namespace std::chrono;
|
||||
|
||||
#define APP_VER "2.0"
|
||||
#define APP_VER "2.1.t1"
|
||||
#define APP_NAME "Motion Watch"
|
||||
#define REC_LOG_NAME "rec_log_lines.html"
|
||||
#define DET_LOG_NAME "det_log_lines.html"
|
||||
|
@ -44,13 +44,13 @@ struct pls_t
|
|||
{
|
||||
string evName;
|
||||
vector<string> srcPaths;
|
||||
uint64_t createTime;
|
||||
Mat thumbnail;
|
||||
};
|
||||
|
||||
struct shared_t
|
||||
{
|
||||
map<string, pls_t> recList;
|
||||
string curEventName;
|
||||
string conf;
|
||||
string recLog;
|
||||
string detLog;
|
||||
|
@ -64,6 +64,7 @@ struct shared_t
|
|||
string webFont;
|
||||
string webRoot;
|
||||
bool skipCmd;
|
||||
int maxScore;
|
||||
int procTime;
|
||||
int schSec;
|
||||
int pixThresh;
|
||||
|
@ -90,6 +91,5 @@ void enforceMaxEvents(shared_t *share);
|
|||
bool rdConf(shared_t *share);
|
||||
vector<string> lsFilesInDir(const string &path, const string &ext = string());
|
||||
vector<string> lsDirsInDir(const string &path);
|
||||
uint64_t genEpoch();
|
||||
|
||||
#endif // COMMON_H
|
||||
|
|
17
src/main.cpp
17
src/main.cpp
|
@ -27,17 +27,12 @@ void eventLoop(shared_t *share)
|
|||
{
|
||||
while (share->retCode == 0)
|
||||
{
|
||||
while (!share->recList.empty())
|
||||
while (share->recList.size() > 1)
|
||||
{
|
||||
auto it = share->recList.begin();
|
||||
auto evName = it->first;
|
||||
auto event = it->second;
|
||||
auto timeDiff = genEpoch() - event.createTime;
|
||||
|
||||
// wait at least 62 seconds before processing the event in
|
||||
// queue.
|
||||
if ((timeDiff > 0) && (timeDiff > 62))
|
||||
{
|
||||
try
|
||||
{
|
||||
createDirTree("events");
|
||||
|
@ -53,14 +48,9 @@ void eventLoop(shared_t *share)
|
|||
{
|
||||
recLog(string("err: ") + ex.what(), share);
|
||||
}
|
||||
|
||||
share->recList.erase(it);
|
||||
}
|
||||
|
||||
sleep(5);
|
||||
}
|
||||
|
||||
sleep(5);
|
||||
sleep(10);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -126,7 +116,7 @@ void recLoop(shared_t *share)
|
|||
" -hls_segment_filename 'live/%Y-%j-%H-%M-%S.ts'" +
|
||||
" -hls_flags delete_segments" +
|
||||
" -y -vcodec copy" +
|
||||
" -f hls -hls_time 10 -hls_list_size 400" +
|
||||
" -f hls -hls_time 2 -hls_list_size 1000" +
|
||||
" stream.m3u8";
|
||||
|
||||
recLog("ffmpeg_run: " + cmd, share);
|
||||
|
@ -170,6 +160,7 @@ int main(int argc, char** argv)
|
|||
{
|
||||
sharedRes.retCode = 0;
|
||||
sharedRes.procTime = 0;
|
||||
sharedRes.maxScore = 0;
|
||||
sharedRes.skipCmd = false;
|
||||
|
||||
rdConf(&sharedRes);
|
||||
|
|
|
@ -16,6 +16,11 @@ void detectMoInStream(const string &streamFile, shared_t *share)
|
|||
{
|
||||
if (share->procTime >= share->schSec)
|
||||
{
|
||||
share->curEventName.clear();
|
||||
|
||||
share->procTime = 0;
|
||||
share->maxScore = 0;
|
||||
|
||||
if (!share->skipCmd)
|
||||
{
|
||||
detLog("no motion detected, running post command: " + share->postCmd, share);
|
||||
|
@ -24,7 +29,6 @@ void detectMoInStream(const string &streamFile, shared_t *share)
|
|||
else
|
||||
{
|
||||
share->skipCmd = false;
|
||||
share->procTime = 0;
|
||||
|
||||
detLog("motion detected, skipping the post command.", share);
|
||||
}
|
||||
|
@ -42,15 +46,23 @@ void detectMoInStream(const string &streamFile, shared_t *share)
|
|||
}
|
||||
}
|
||||
|
||||
if (share->curEventName.empty())
|
||||
{
|
||||
share->curEventName = genTimeStr("%Y-%j-%H-%M");
|
||||
}
|
||||
|
||||
if (!tsPath.empty())
|
||||
{
|
||||
if (moDetect(tsPath, thumbnail, share))
|
||||
{
|
||||
auto eventName = genTimeStr("%Y-%j-%H-%M");
|
||||
|
||||
if (share->recList.find(eventName) != share->recList.end())
|
||||
if (share->recList.find(share->curEventName) != share->recList.end())
|
||||
{
|
||||
share->recList[eventName].srcPaths.push_back(tsPath);
|
||||
share->recList[share->curEventName].srcPaths.push_back(tsPath);
|
||||
|
||||
if (!thumbnail.empty())
|
||||
{
|
||||
share->recList[share->curEventName].thumbnail = thumbnail.clone();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -58,17 +70,16 @@ void detectMoInStream(const string &streamFile, shared_t *share)
|
|||
|
||||
event.srcPaths.push_back(tsPath);
|
||||
|
||||
event.createTime = genEpoch();
|
||||
event.thumbnail = thumbnail.clone();
|
||||
event.evName = eventName;
|
||||
event.evName = share->curEventName;
|
||||
|
||||
share->recList.insert(pair{eventName, event});
|
||||
share->recList.insert(pair{event.evName, event});
|
||||
}
|
||||
|
||||
share->skipCmd = true;
|
||||
}
|
||||
|
||||
share->procTime += 10;
|
||||
share->procTime += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -87,14 +98,13 @@ bool imgDiff(const Mat &prev, const Mat &next, int &score, shared_t *share)
|
|||
|
||||
score = countNonZero(diff);
|
||||
|
||||
detLog("diff_score: " + to_string(score) + " tresh: " + to_string(share->imgThresh), share);
|
||||
detLog("diff_score: " + to_string(score) + " thresh: " + to_string(share->imgThresh), share);
|
||||
|
||||
return score >= share->imgThresh;
|
||||
}
|
||||
|
||||
bool moDetect(const string &buffFile, Mat &vidThumb, shared_t *share)
|
||||
{
|
||||
auto maxScore = 0;
|
||||
auto score = 0;
|
||||
|
||||
detLog("stream_clip: " + buffFile, share);
|
||||
|
@ -122,9 +132,9 @@ bool moDetect(const string &buffFile, Mat &vidThumb, shared_t *share)
|
|||
{
|
||||
if (imgDiff(prev, next, score, share))
|
||||
{
|
||||
if (score > maxScore)
|
||||
if (score > share->maxScore)
|
||||
{
|
||||
maxScore = score;
|
||||
share->maxScore = score;
|
||||
|
||||
resize(next, vidThumb, Size(720, 480), INTER_LINEAR);
|
||||
}
|
||||
|
@ -145,7 +155,7 @@ bool moDetect(const string &buffFile, Mat &vidThumb, shared_t *share)
|
|||
|
||||
capture.release();
|
||||
|
||||
return maxScore > 0;
|
||||
return score > 0;
|
||||
}
|
||||
|
||||
void wrOutVod(const pls_t &event, shared_t *share)
|
||||
|
|
Loading…
Reference in New Issue
Block a user