#include "NewRecordVideoElement.h"
|
#include <basic/util/app/AppPreference.hpp>
|
|
//#todo index int -> string
|
NewRecordVideoElement::NewRecordVideoElement(std::string camid) :
|
videoEncoderElement(cv::Size(1920, 1080), 9, 0),
|
camID(camid)
|
{
|
|
// basicPath();
|
m_cutPath= appPref.getStringData("user.loop.absolute.path");
|
}
|
|
NewRecordVideoElement::~NewRecordVideoElement() {
|
m_imgBufQue.clear();
|
}
|
|
std::string NewRecordVideoElement::startRecord() {
|
|
// ImgInfo info=m_HiredisTool.getImage(camID);
|
ImgInfo info;
|
getImg(info);
|
std::string srcPath= getFileName(info.time);
|
|
|
try {
|
videoEncoderElement.threadInitial(srcPath, info.img);
|
}
|
catch (std::exception &e) {
|
ERR(e.what())
|
}
|
return srcPath;
|
}
|
|
void NewRecordVideoElement::endRecord() {
|
ImgInfo info;
|
getImg(info);
|
videoEncoderElement.threadClosing();
|
}
|
|
void NewRecordVideoElement::doRecord() {
|
|
|
// ImgInfo info=m_HiredisTool.getImage(camID);
|
ImgInfo info;
|
getImg(info);
|
DBG(" time="<<info.time);
|
videoEncoderElement.doFunc(info.img);
|
}
|
|
std::string NewRecordVideoElement::getFileName(std::string timeStamp)
|
{
|
std::string dirPath=makeDir();
|
|
char szDateTime[256] = {0};
|
sprintf(szDateTime, "%s%s.mp4", dirPath.c_str(), timeStamp.c_str());
|
DBG(szDateTime);
|
return szDateTime;
|
}
|
|
|
std::string NewRecordVideoElement::makeDir() {
|
|
//# ./camIndex/YYYYMM/DD/YYYYMMDDHH/
|
std::string t_FilePath = m_cutPath;
|
|
if (t_FilePath.back() != '/') {
|
t_FilePath.push_back('/');
|
}
|
char buf[24];
|
|
time_t t=time(nullptr);
|
// 20180901113048 2018-09-01 11:30:48
|
strftime(buf,24,"%Y%m%d%H",localtime(&t));
|
std::string t_strTime(buf);
|
//# ./camIndex/YYYYMM/DD/
|
t_FilePath.append(camID + "/" + t_strTime.substr(0, 6)+ "/" +t_strTime.substr(6, 2) + "/");
|
//YYYYMMDDHH
|
t_FilePath.append(t_strTime.substr(0,10) + "/");
|
std::string t_cmd = "mkdir -p '";
|
t_cmd.append(t_FilePath + "'");
|
//#get path mkdir path
|
system(t_cmd.c_str());
|
|
return t_FilePath;
|
}
|
void NewRecordVideoElement::pushImgBuf(const std::string& time,cv::Mat img)
|
{
|
ImgInfo info;
|
info.img=img;
|
info.time=time;
|
m_imgBufQue.push_front(info);
|
// int size=m_imgBufQue.size();
|
// DBG("m_imgBufQue size="<<size);
|
}
|
void NewRecordVideoElement::getImg(ImgInfo& info)
|
{
|
//todo
|
int len=10;
|
info=m_imgBufQue.back();
|
int size=m_imgBufQue.size();
|
//DBG("m_imgBufQue size="<<size<<" time="<<info.time);
|
if(size>len)
|
{
|
m_imgBufQue.pop_back();
|
|
|
}
|
|
|
|
}
|