diff --git a/src/common.cpp b/src/common.cpp index 2f11941..0546e74 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -134,23 +134,18 @@ void cleanupStream(const string &plsPath) void enforceMaxEvents(shared_t *share) { - auto names = lsFilesInDir(".", ".m3u8"); + auto names = lsFilesInDir(".", ".mp4"); while (names.size() > share->maxEvents) { - if (names[0] != "stream.m3u8") - { - // removes the playlist file extension. - auto nameOnly = names[0].substr(0, names[0].size() - 5); - auto imgFile = nameOnly + ".jpg"; - auto webFile = nameOnly + ".html"; + // removes the playlist file extension. + auto nameOnly = names[0].substr(0, names[0].size() - 4); + auto imgFile = nameOnly + ".jpg"; + auto webFile = nameOnly + ".html"; - cleanupStream(names[0]); - remove(names[0]); - - if (exists(imgFile)) remove(imgFile); - if (exists(webFile)) remove(webFile); - } + if (exists(names[0])) remove(names[0]); + if (exists(imgFile)) remove(imgFile); + if (exists(webFile)) remove(webFile); names.erase(names.begin()); } diff --git a/src/common.h b/src/common.h index e7464c7..f97be62 100644 --- a/src/common.h +++ b/src/common.h @@ -38,7 +38,7 @@ using namespace std; using namespace std::filesystem; using namespace std::chrono; -#define APP_VER "2.0.t8" +#define APP_VER "2.0.t9" #define APP_NAME "Motion Watch" #define REC_LOG_NAME "rec_log_lines.html" #define DET_LOG_NAME "det_log_lines.html" @@ -47,10 +47,7 @@ using namespace std::chrono; struct pls_t { string evName; - string dstPath; vector srcPaths; - vector dstPaths; - vector extINFs; uint64_t createTime; Mat thumbnail; }; diff --git a/src/main.cpp b/src/main.cpp index 564e49f..fc7a9d7 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -43,8 +43,8 @@ void eventLoop(shared_t *share) try { - wrOutm3u8(event, share); - genHTMLvid(evName); + wrOutVod(event, share); + genHTMLvod(evName); if (!exists(evName + ".jpg")) { diff --git a/src/mo_detect.cpp b/src/mo_detect.cpp index 33c8603..bb56cd7 100644 --- a/src/mo_detect.cpp +++ b/src/mo_detect.cpp @@ -16,7 +16,6 @@ void detectMoInStream(const string &bufPath, shared_t *share) { ifstream fileIn(bufPath); string tsPath; - string extINF; Mat thumbnail; auto clipPathFilter = genTimeStr("VIDEO_TS/live/%Y/%j/%H/"); @@ -27,13 +26,9 @@ void detectMoInStream(const string &bufPath, shared_t *share) { tsPath = line; } - else if (line.starts_with("#EXTINF")) - { - extINF = line; - } } - if (!tsPath.empty() && !extINF.empty()) + if (!tsPath.empty()) { if (moDetect(tsPath, thumbnail, share)) { @@ -42,16 +37,12 @@ void detectMoInStream(const string &bufPath, shared_t *share) if (share->recList.find(eventName) != share->recList.end()) { share->recList[eventName].srcPaths.push_back(tsPath); - share->recList[eventName].dstPaths.push_back(genEventPath(tsPath)); - share->recList[eventName].extINFs.push_back(extINF); } else { pls_t event; event.srcPaths.push_back(tsPath); - event.dstPaths.push_back(genEventPath(tsPath)); - event.extINFs.push_back(extINF); event.createTime = genEpoch(); event.thumbnail = thumbnail.clone(); @@ -136,32 +127,19 @@ bool moDetect(const string &buffFile, Mat &vidThumb, shared_t *share) return mod; } -void wrOutm3u8(const pls_t &event, shared_t *share) +void wrOutVod(const pls_t &event, shared_t *share) { - auto plsFile = event.evName + ".m3u8"; + auto concat = event.evName + ".tmp"; - ofstream file(plsFile.c_str()); + ofstream file(concat.c_str()); - file << "#EXTM3U" << endl; - file << "#EXT-X-VERSION:3" << endl; - file << "#EXT-X-TARGETDURATION:10" << endl; - file << "#EXT-X-MEDIA-SEQUENCE:0" << endl; - file << "#EXT-X-START:TIME-OFFSET=0" << endl; - file << "#EXT-X-PLAYLIST-TYPE:VOD" << endl; - - for (auto i = 0; i < event.extINFs.size(); ++i) + for (auto i = 0; i < event.srcPaths.size(); ++i) { - auto src = event.srcPaths[i]; - auto dst = event.dstPaths[i]; - - createDirTree(path(dst).parent_path().string()); - copy_file(src, dst); - - file << event.extINFs[i] << endl; - file << dst << endl; + file << "file '" << event.srcPaths[i] << "''" << endl; } - file << "#EXT-X-ENDLIST" << endl; - file.close(); + + system(string("ffmpeg -f concat -safe 0 -i " + concat + " -c copy " + event.evName + ".mp4").c_str()); + remove(concat); } diff --git a/src/mo_detect.h b/src/mo_detect.h index ccc7fd4..d3998a4 100644 --- a/src/mo_detect.h +++ b/src/mo_detect.h @@ -19,6 +19,6 @@ bool imgDiff(Mat &prev, Mat &next, shared_t *share); bool moDetect(const string &buffFile, Mat &vidThumb, shared_t *share); void detectMoInStream(const string &bufPath, shared_t *share); -void wrOutm3u8(const pls_t &pls, shared_t *share); +void wrOutVod(const pls_t &pls, shared_t *share); #endif // MO_DETECT_H diff --git a/src/web.cpp b/src/web.cpp index 1fff46c..53f9f72 100644 --- a/src/web.cpp +++ b/src/web.cpp @@ -51,7 +51,7 @@ void genHTMLul(const string &outputDir, const string &title, shared_t *share) htmlText += "\n"; htmlText += "

Motion Events

\n"; - genHTMLvid("stream"); + genHTMLstream("stream"); } for (auto &®Name : regNames) @@ -96,7 +96,7 @@ void genHTMLul(const string &outputDir, const string &title, shared_t *share) file.close(); } -void genHTMLvid(const string &name) +void genHTMLstream(const string &name) { string htmlText = "\n"; @@ -143,6 +143,32 @@ void genHTMLvid(const string &name) file.close(); } +void genHTMLvod(const string &name) +{ + string htmlText = "\n"; + + htmlText += "\n"; + htmlText += "\n"; + htmlText += "\n"; + htmlText += "\n"; + htmlText += "\n"; + htmlText += "\n"; + htmlText += "\n"; + htmlText += "\n"; + htmlText += "\n"; + htmlText += "\n"; + htmlText += "\n"; + htmlText += ""; + + ofstream file(string(name + ".html").c_str()); + + file << htmlText << endl; + + file.close(); +} + void genCSS(shared_t *share) { string cssText = "body {\n"; diff --git a/src/web.h b/src/web.h index b716fc0..5f4beba 100644 --- a/src/web.h +++ b/src/web.h @@ -16,7 +16,8 @@ #include "common.h" void genHTMLul(const string &outputDir, const string &title, shared_t *share); -void genHTMLvid(const string &name); +void genHTMLstream(const string &name); +void genHTMLvod(const string &name); void genCSS(shared_t *share); #endif // WEB_H