派生自 development/c++

pansen
2018-12-17 7d797b1a5786a8d4ca3aafe2484c75ad15ba9d8f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#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();
 
 
        }
 
 
 
 }