提交 eb3cb0c2 authored 作者: blu's avatar blu

feature: max event video length

上级 20d2e722
...@@ -46,6 +46,7 @@ struct DetectParam { ...@@ -46,6 +46,7 @@ struct DetectParam {
int pre; int pre;
int post; int post;
float entropy; float entropy;
int maxDuration; // max event video length in minutes
}; };
enum EventState { enum EventState {
...@@ -63,9 +64,9 @@ private: ...@@ -63,9 +64,9 @@ private:
int iid; int iid;
AVFormatContext *pAVFormatInput = nullptr; AVFormatContext *pAVFormatInput = nullptr;
AVCodecContext *pCodecCtx = nullptr; AVCodecContext *pCodecCtx = nullptr;
DetectParam detPara = {25, 500, -1, 3, 3, 30, 0.3}; DetectParam detPara = {25, 500, -1, 3, 3, 30, 0.3, 10};
EventState evtState = EventState::NONE; EventState evtState = EventState::NONE;
chrono::system_clock::time_point evtStartTm, evtStartTmLast; chrono::system_clock::time_point evtStartTm, evtStartTmLast, evtStartTmOrig;
queue<string> *evtQueue; queue<string> *evtQueue;
int streamIdx = -1; int streamIdx = -1;
json config; json config;
...@@ -297,6 +298,13 @@ private: ...@@ -297,6 +298,13 @@ private:
detPara.fpsProc = evmlmotion["fpsProc"]; detPara.fpsProc = evmlmotion["fpsProc"];
} }
if(evmlmotion.count("maxDuration") == 0|| !evmlmotion["maxDuration"].is_number_integer() ||evmlmotion["maxDuration"] <= 1 || evmlmotion["maxDuration"] >= 100) {
spdlog::info("evmlmotion {} invalid maxDuration value. should be in (0, 100) as int(minutes), default to {}", selfId, detPara.maxDuration);
}
else {
detPara.maxDuration = evmlmotion["maxDuration"];
}
spdlog::info("evmlmotion {} detection params: entropy {}, area {}, thresh {}, fpsProc {}", selfId, detPara.entropy, detPara.area, detPara.thre, detPara.fpsProc); spdlog::info("evmlmotion {} detection params: entropy {}, area {}, thresh {}, fpsProc {}", selfId, detPara.entropy, detPara.area, detPara.thre, detPara.fpsProc);
// setup sub // setup sub
...@@ -524,6 +532,19 @@ private: ...@@ -524,6 +532,19 @@ private:
return 0; return 0;
} }
void makeEvent(string evtType, int ts) {
json p;
p["type"] = EV_MSG_TYPE_AI_MOTION;
p["gid"] = selfId;
p["event"] = evtType; //EV_MSG_EVENT_MOTION_END;
p["ts"] = ts;
spdlog::info("evmlmotion {} packet ts delta: {}", selfId, packetTsDelta);
evtQueue->push(p.dump());
if(evtQueue->size() > MAX_EVENT_QUEUE_SIZE*2) {
evtQueue->pop();
}
}
void detectMotion(AVPixelFormat format,AVFrame *pFrame, bool detect = true) void detectMotion(AVPixelFormat format,AVFrame *pFrame, bool detect = true)
{ {
static bool first = true; static bool first = true;
...@@ -596,6 +617,7 @@ private: ...@@ -596,6 +617,7 @@ private:
evtState = PRE; evtState = PRE;
spdlog::debug("state: NONE->PRE ({}, {})", dura, evtCnt); spdlog::debug("state: NONE->PRE ({}, {})", dura, evtCnt);
evtStartTmLast = evtStartTm; evtStartTmLast = evtStartTm;
evtStartTmOrig = evtStartTm;
evtCnt = 0; evtCnt = 0;
} }
break; break;
...@@ -606,6 +628,7 @@ private: ...@@ -606,6 +628,7 @@ private:
spdlog::debug("state: PRE->PRE ({}, {})", dura, evtCnt); spdlog::debug("state: PRE->PRE ({}, {})", dura, evtCnt);
evtState = PRE; evtState = PRE;
evtStartTmLast = evtStartTm; evtStartTmLast = evtStartTm;
evtStartTmOrig = evtStartTm;
evtCnt = 0; evtCnt = 0;
} }
else if (true/*dura > detPara.pre && evtCnt >= detPara.pre*/) { else if (true/*dura > detPara.pre && evtCnt >= detPara.pre*/) {
...@@ -613,18 +636,11 @@ private: ...@@ -613,18 +636,11 @@ private:
json p; json p;
spdlog::debug("state: PRE->IN ({}, {})", dura, evtCnt); spdlog::debug("state: PRE->IN ({}, {})", dura, evtCnt);
evtCnt = 0; evtCnt = 0;
p["type"] = EV_MSG_TYPE_AI_MOTION; makeEvent(EV_MSG_EVENT_MOTION_START, packetTs);
p["gid"] = selfId;
p["event"] = EV_MSG_EVENT_MOTION_START;
auto tmp = chrono::duration_cast<chrono::seconds>(evtStartTmLast.time_since_epoch()).count(); auto tmp = chrono::duration_cast<chrono::seconds>(evtStartTmLast.time_since_epoch()).count();
p["ts"] = packetTs;
packetTsDelta = tmp - packetTs; packetTsDelta = tmp - packetTs;
evtStartTmLast = evtStartTm; evtStartTmLast = evtStartTm;
//p["frame"] = origin.clone(); evtStartTmOrig = evtStartTm;
evtQueue->push(p.dump());
if(evtQueue->size() > MAX_EVENT_QUEUE_SIZE * 2) {
evtQueue->pop();
}
} }
} }
else { else {
...@@ -645,6 +661,12 @@ private: ...@@ -645,6 +661,12 @@ private:
} }
} }
else { else {
if(chrono::duration_cast<chrono::seconds>(evtStartTmOrig - evtStartTm).count() > detPara.maxDuration) {
evtStartTmOrig = evtStartTm;
makeEvent(EV_MSG_EVENT_MOTION_END, packetTs);
evtCnt = 0;
makeEvent(EV_MSG_EVENT_MOTION_START, packetTs);
}
evtStartTmLast = evtStartTm; evtStartTmLast = evtStartTm;
spdlog::debug("state: IN->IN ({}, {})", dura, evtCnt); spdlog::debug("state: IN->IN ({}, {})", dura, evtCnt);
evtCnt = 0; evtCnt = 0;
...@@ -657,17 +679,8 @@ private: ...@@ -657,17 +679,8 @@ private:
spdlog::debug("state: POST->NONE ({}, {})", dura, evtCnt); spdlog::debug("state: POST->NONE ({}, {})", dura, evtCnt);
evtState = NONE; evtState = NONE;
evtCnt = 0; evtCnt = 0;
json p; makeEvent(EV_MSG_EVENT_MOTION_END, packetTs);
p["type"] = EV_MSG_TYPE_AI_MOTION;
p["gid"] = selfId;
p["event"] = EV_MSG_EVENT_MOTION_END;
auto tmp = chrono::duration_cast<chrono::seconds>(evtStartTmLast.time_since_epoch()).count() + (int)(detPara.post/2);
p["ts"] = tmp - packetTsDelta;
spdlog::info("evmlmotion {} packet ts delta: {}", selfId, packetTsDelta); spdlog::info("evmlmotion {} packet ts delta: {}", selfId, packetTsDelta);
evtQueue->push(p.dump());
if(evtQueue->size() > MAX_EVENT_QUEUE_SIZE*2) {
evtQueue->pop();
}
} }
} }
else { else {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论