MP4录像增加一级目录,按照:年月/年月日/*.mp4存储;

增加按月,按天查询mp4录像;
消除一处编译器警告;
This commit is contained in:
liuziloong 2020-01-20 15:02:45 +08:00
parent ee2ca4bda5
commit 2384aa5bbd
3 changed files with 84 additions and 22 deletions

View File

@ -71,6 +71,7 @@ static onceToken token([]() {
}); });
}//namespace API }//namespace API
class ApiRetException: public std::runtime_error { class ApiRetException: public std::runtime_error {
public: public:
ApiRetException(const char *str = "success" ,int code = API::Success):runtime_error(str){ ApiRetException(const char *str = "success" ,int code = API::Success):runtime_error(str){
@ -773,9 +774,9 @@ void installWebApi() {
val["status"] = (int)status; val["status"] = (int)status;
}); });
//获取录像列表(按月) //获取录像列表(按月),返回天
//http://127.0.0.1/index/api/getMp4RecordMonthly?app=pzstll&stream=stream_4&period=2020-01 //http://127.0.0.1/index/api/getMp4RecordMonthly?app=live&stream=onvif&period=2020-01
API_REGIST(api, getMp4RecordMonthly, { api_regist1("/index/api/getMp4RecordMonthly", [](API_ARGS1){
CHECK_SECRET(); CHECK_SECRET();
CHECK_ARGS("app", "stream", "period"); CHECK_ARGS("app", "stream", "period");
@ -791,41 +792,100 @@ void installWebApi() {
//TODO:判断日期格式 //TODO:判断日期格式
//Vhost为空的话存储路径不一样 //Vhost为空的话存储路径不一样
if (_vhost.empty()) if (_vhost.empty()) {
{
_vhost = DEFAULT_VHOST; _vhost = DEFAULT_VHOST;
} }
string strMp4RecordPath; string strMp4RecordPath = "";
if (enableVhost) if (enableVhost) {
{ strMp4RecordPath = recordPath + "/" + _vhost + "/" + recordAppName + "/" + _app + "/" + _stream + "/" + _period;
strMp4RecordPath = recordPath + "/" + _vhost + "/" + recordAppName + "/" + _app + "/" + _stream; } else {
strMp4RecordPath = recordPath + "/" + recordAppName + "/" + _app + "/" + _stream + "/" + _period;
} }
else
{ //录像相对路径转绝对路径, 不然vs调试需要设置
strMp4RecordPath = recordPath + "/" + recordAppName + "/" + _app + "/" + _stream; strMp4RecordPath = File::absolutePath(strMp4RecordPath, "");
} string strMp4Path = "";
DebugL << strMp4RecordPath; File::scanDir(strMp4RecordPath, [&strMp4Path](const string &path, bool isDir) {
if (isDir) {
//DebugL << "dir:" << path.data();
int iPost = path.rfind('/');
if (iPost != string::npos)
{
string strPath = path.substr(iPost + 1);
strMp4Path += strPath + ",";
}
}
return true;
},false);
//去掉strMp4Path最后一个 ,
strMp4Path = strMp4Path.substr(0, strMp4Path.length() - 1);
Json::Value nVal; Json::Value nVal;
nVal["vhost"] = _vhost.data(); nVal["vhost"] = _vhost.data();
nVal["app"] = _app.data(); nVal["app"] = _app.data();
nVal["stream"] = _stream.data(); nVal["stream"] = _stream.data();
nVal["app"] = _app.data(); nVal["app"] = _app.data();
nVal["path"] = strMp4Path;
val["data"] = nVal; val["data"] = nVal;
}); });
//获取录像列表(按天) //获取录像列表(按天)
//http://127.0.0.1/index/api/getMp4RecordDaily?app=pzstll&stream=stream_4&period=2020-01-17 //http://127.0.0.1/index/api/getMp4RecordDaily?app=live&stream=onvif&period=2020-01-17
API_REGIST(api, getMp4RecordDaily, { api_regist1("/index/api/getMp4RecordDaily",[](API_ARGS1) {
CHECK_SECRET(); CHECK_SECRET();
CHECK_ARGS("app", "stream", "period"); CHECK_ARGS("app", "stream", "period");
GET_CONFIG(string, recordAppName, Record::kAppName);
GET_CONFIG(string, recordPath, Record::kFilePath);
GET_CONFIG(bool, enableVhost, General::kEnableVhost);
auto _vhost = allArgs["vhost"];
auto _app = allArgs["app"];
auto _stream = allArgs["stream"];
auto _period = allArgs["period"];
}); //TODO:判断日期格式
//Vhost为空的话存储路径不一样
if (_vhost.empty()) {
_vhost = DEFAULT_VHOST;
}
string strMp4RecordPath = "";
//取录上一级目录,默认前7位位上级目录
string strParentPeriod = string(_period).substr(0, 7);
if (enableVhost) {
strMp4RecordPath = recordPath + "/" + _vhost + "/" + recordAppName + "/" + _app + "/" + _stream + "/" + strParentPeriod + "/" + _period;
}
else {
strMp4RecordPath = recordPath + "/" + recordAppName + "/" + _app + "/" + _stream + "/" + strParentPeriod + "/" + _period;
}
//录像相对路径转绝对路径, 不然vs调试需要设置
strMp4RecordPath = File::absolutePath(strMp4RecordPath, "");
Json::Value nVal;
DebugL << recordPath;
File::scanDir(strMp4RecordPath, [&](const string &path, bool isDir) {
if (!isDir) {
//去掉绝对路径从record开始返回
int iPos = path.find(recordAppName);
string strPath = path.substr(iPos);
nVal["path"].append(strPath);
}
return true;
}, false);
nVal["vhost"] = _vhost.data();
nVal["app"] = _app.data();
nVal["stream"] = _stream.data();
nVal["app"] = _app.data();
val["data"] = nVal;
});
////////////以下是注册的Hook API//////////// ////////////以下是注册的Hook API////////////
api_regist1("/index/hook/on_publish",[](API_ARGS1){ api_regist1("/index/hook/on_publish",[](API_ARGS1){

View File

@ -1330,7 +1330,7 @@ int hevcDecodeShortTermRps(T_GetBitContext *pvBuf,
int iDeltaRps; int iDeltaRps;
unsigned int uiAbsDeltaRps; unsigned int uiAbsDeltaRps;
uint8_t u8UseDeltaFlag = 0; uint8_t u8UseDeltaFlag = 0;
uint8_t u8DeltaRpsSign; uint8_t u8DeltaRpsSign = 0;
if (is_slice_header) { if (is_slice_header) {
unsigned int uiDeltaIdx = parseUe(pvBuf) + 1; unsigned int uiDeltaIdx = parseUe(pvBuf) + 1;

View File

@ -53,9 +53,10 @@ MP4Recorder::~MP4Recorder() {
void MP4Recorder::createFile() { void MP4Recorder::createFile() {
closeFile(); closeFile();
auto strDate = getTimeStr("%Y-%m-%d"); auto strDate = getTimeStr("%Y-%m-%d");
auto strDay = getTimeStr("%Y-%m-%d");
auto strTime = getTimeStr("%H-%M-%S"); auto strTime = getTimeStr("%H-%M-%S");
auto strFileTmp = _strPath + strDate + "/." + strTime + ".mp4"; auto strFileTmp = _strPath + strDate + "/" + strDay + "/." + strTime + ".mp4";
auto strFile = _strPath + strDate + "/" + strTime + ".mp4"; auto strFile = _strPath + strDate + "/" + strDay + "/" + strTime + ".mp4";
/////record 业务逻辑////// /////record 业务逻辑//////
_info.ui64StartedTime = ::time(NULL); _info.ui64StartedTime = ::time(NULL);
@ -66,6 +67,7 @@ void MP4Recorder::createFile() {
+ _info.strAppName + "/" + _info.strAppName + "/"
+ _info.strStreamId + "/" + _info.strStreamId + "/"
+ strDate + "/" + strDate + "/"
+ strDay + "/"
+ strTime + ".mp4"; + strTime + ".mp4";
try { try {