v1.5.t4
The error checking with ffmpeg is not working. Learned that it doesn't always return 0 on success. Decided to remove the error checking altogether. Instead ffmpeg failures should be checked manually using stderr. Dirent includes .. and . so I decided to switch to the filesystem entry listing that should hopefully exclude those special directories. The camera webroot was not generating .index files. those files would only get generated if motion was detected. Copied the code that does that onto recLoop() to execute regardless of motion.
This commit is contained in:
parent
baeaabbd55
commit
5ab50433cf
|
@ -57,46 +57,23 @@ bool fileExists(const string& name)
|
|||
return access(name.c_str(), F_OK) != -1;
|
||||
}
|
||||
|
||||
string replaceAll(string str, const string &from, const string &to)
|
||||
{
|
||||
if (from.empty()) return str;
|
||||
|
||||
size_t startPos = 0;
|
||||
|
||||
while ((startPos = str.find(from, startPos)) != string::npos)
|
||||
{
|
||||
str.replace(startPos, from.length(), to);
|
||||
|
||||
startPos += to.length();
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
vector<string> lsFilesInDir(const string &path, const string &ext)
|
||||
{
|
||||
DIR *dir;
|
||||
struct dirent *ent;
|
||||
vector<string> names;
|
||||
|
||||
if ((dir = opendir(path.c_str())) != NULL)
|
||||
for (auto &entry : directory_iterator(path))
|
||||
{
|
||||
while ((ent = readdir(dir)) != NULL)
|
||||
if (entry.is_regular_file())
|
||||
{
|
||||
if (ent->d_type & DT_REG)
|
||||
{
|
||||
auto name = string(ent->d_name);
|
||||
auto name = entry.path().filename().string();
|
||||
|
||||
if (name.ends_with(ext.c_str()) || ext.empty())
|
||||
if (ext.empty() || name.ends_with(ext))
|
||||
{
|
||||
names.push_back(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
closedir(dir);
|
||||
}
|
||||
|
||||
sort(names.begin(), names.end());
|
||||
|
||||
return names;
|
||||
|
@ -104,27 +81,15 @@ vector<string> lsFilesInDir(const string &path, const string &ext)
|
|||
|
||||
vector<string> lsDirsInDir(const string &path)
|
||||
{
|
||||
DIR *dir;
|
||||
struct dirent *ent;
|
||||
vector<string> names;
|
||||
|
||||
if ((dir = opendir(path.c_str())) != NULL)
|
||||
for (auto &entry : directory_iterator(path))
|
||||
{
|
||||
while ((ent = readdir(dir)) != NULL)
|
||||
if (entry.is_directory())
|
||||
{
|
||||
if (ent->d_type & DT_DIR)
|
||||
{
|
||||
auto name = string(ent->d_name);
|
||||
|
||||
if ((name != "..") || (name != "."))
|
||||
{
|
||||
names.push_back(name);
|
||||
names.push_back(entry.path().filename().string());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
closedir(dir);
|
||||
}
|
||||
|
||||
sort(names.begin(), names.end());
|
||||
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
#include <errno.h>
|
||||
#include <vector>
|
||||
#include <thread>
|
||||
#include <dirent.h>
|
||||
#include <filesystem>
|
||||
#include <mutex>
|
||||
#include <sys/types.h>
|
||||
|
@ -36,7 +35,7 @@ using namespace cv;
|
|||
using namespace std;
|
||||
using namespace std::filesystem;
|
||||
|
||||
#define APP_VER "1.5.t3"
|
||||
#define APP_VER "1.5.t4"
|
||||
#define APP_NAME "Motion Watch"
|
||||
|
||||
struct shared_t
|
||||
|
@ -72,7 +71,6 @@ string genDstFile(const string &dirOut, const char *fmt, const string &e
|
|||
string genTimeStr(const char *fmt);
|
||||
string cleanDir(const string &path);
|
||||
string parseForParam(const string &arg, int argc, char** argv, bool argOnly);
|
||||
string replaceAll(string str, const string &from, const string &to);
|
||||
bool createDir(const string &dir);
|
||||
bool createDirTree(const string &full_path);
|
||||
bool fileExists(const string& name);
|
||||
|
|
|
@ -46,7 +46,6 @@ void logLoop(shared_t *share)
|
|||
htmlText += "<html>\n";
|
||||
htmlText += "<head>\n";
|
||||
htmlText += "<link rel='stylesheet' href='/theme.css'>\n";
|
||||
htmlText += "<meta http-equiv='refresh' content='10'>";
|
||||
htmlText += "</head>\n";
|
||||
htmlText += "<body>\n";
|
||||
htmlText += "<p>\n";
|
||||
|
|
22
src/main.cpp
22
src/main.cpp
|
@ -52,7 +52,7 @@ void detectLoop(shared_t *share)
|
|||
sleep(1);
|
||||
}
|
||||
}
|
||||
while (!bufFiles.empty());
|
||||
while (!bufFiles.empty() && !share->recLoopWait);
|
||||
|
||||
detLog("detectLoop() -- finished", share);
|
||||
}
|
||||
|
@ -77,6 +77,9 @@ void recLoop(shared_t *share)
|
|||
recLog("/tmp/mow-lock pesent, skipping update of the webroot page.", share);
|
||||
}
|
||||
|
||||
genHTMLul(share->outDir, share->camName, share);
|
||||
recLog("camera specific webroot page updated. page = " + share->outDir + "/index.html", share);
|
||||
|
||||
auto bufPath = cleanDir(share->buffDir) + "/%03d." + share->vidExt;
|
||||
auto secs = to_string(share->secs);
|
||||
auto limSecs = to_string(share->secs + 3);
|
||||
|
@ -87,26 +90,11 @@ void recLoop(shared_t *share)
|
|||
recLog("detect_loop started in a seperate thread.", share);
|
||||
recLog("ffmpeg = " + cmd, share);
|
||||
|
||||
auto ret = system(cmd.c_str());
|
||||
|
||||
if (ret == 0)
|
||||
{
|
||||
recLog("ffmpeg_return_code = " + to_string(ret), share);
|
||||
system(cmd.c_str());
|
||||
|
||||
share->recLoopWait = true;
|
||||
|
||||
th2.join();
|
||||
}
|
||||
else
|
||||
{
|
||||
recLog("ffmpeg failed, cooling down for " + to_string(share->secs) + "secs.", share);
|
||||
recLog("ffmpeg_return_code = " + to_string(ret), share);
|
||||
|
||||
// simulate that ffmpeg is running even after it has failed.
|
||||
sleep(share->secs);
|
||||
|
||||
share->recLoopWait = true;
|
||||
}
|
||||
|
||||
if (!share->skipCmd)
|
||||
{
|
||||
|
|
16
src/web.cpp
16
src/web.cpp
|
@ -14,8 +14,6 @@
|
|||
|
||||
void genHTMLul(const string &outputDir, const string &title, shared_t *share)
|
||||
{
|
||||
DIR *dir;
|
||||
struct dirent *ent;
|
||||
vector<string> logNames;
|
||||
vector<string> regNames = lsFilesInDir(outputDir);
|
||||
vector<string> dirNames = lsDirsInDir(outputDir);
|
||||
|
@ -82,24 +80,23 @@ void genHTMLul(const string &outputDir, const string &title, shared_t *share)
|
|||
|
||||
void genHTMLvid(const string &outputVid, shared_t *share)
|
||||
{
|
||||
auto filename = path(outputVid).filename().string();
|
||||
auto vidName = path(outputVid).filename().string();
|
||||
auto filePath = path(outputVid).parent_path().string();
|
||||
auto fileName = vidName.substr(0, vidName.size() - (share->vidExt.size() + 1));
|
||||
string htmlText = "<!DOCTYPE html>\n";
|
||||
|
||||
filename = replaceAll(filename, share->vidExt, "html");
|
||||
|
||||
htmlText += "<html>\n";
|
||||
htmlText += "<head>\n";
|
||||
htmlText += "<link rel='stylesheet' href='/theme.css'>\n";
|
||||
htmlText += "</head>\n";
|
||||
htmlText += "<body>\n";
|
||||
htmlText += "<video width=100% height=100% controls autoplay>\n";
|
||||
htmlText += " <source src='" + filename + "' type='video/" + share->vidExt + "'>\n";
|
||||
htmlText += " <source src='" + vidName + "' type='video/" + share->vidExt + "'>\n";
|
||||
htmlText += "</video>\n";
|
||||
htmlText += "</body>\n";
|
||||
htmlText += "</html>";
|
||||
|
||||
ofstream file(string(cleanDir(filePath) + "/" + filename + ".html").c_str());
|
||||
ofstream file(string(filePath + "/" + fileName + ".html").c_str());
|
||||
|
||||
file << htmlText << endl;
|
||||
|
||||
|
@ -113,7 +110,10 @@ void genCSS(shared_t *share)
|
|||
cssText += " background-color: " + share->webBg + ";\n";
|
||||
cssText += " color: " + share->webTxt + ";\n";
|
||||
cssText += " font-family: " + share->webFont + ";\n";
|
||||
cssText += "}";
|
||||
cssText += "}\n";
|
||||
cssText += "a {\n";
|
||||
cssText += " color: " + share->webTxt + ";\n";
|
||||
cssText += "}\n";
|
||||
|
||||
ofstream file(string(cleanDir(share->webRoot) + "/theme.css").c_str());
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user