From 2d9537ec843cf39fa8fb514a41f3f4aac60e7cc1 Mon Sep 17 00:00:00 2001 From: Luke Date: Tue, 14 Jan 2020 10:36:38 +0800 Subject: [PATCH 1/5] snap --- server/FFmpegSource.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/server/FFmpegSource.cpp b/server/FFmpegSource.cpp index d8a821c6..5ba1d618 100644 --- a/server/FFmpegSource.cpp +++ b/server/FFmpegSource.cpp @@ -34,6 +34,7 @@ namespace FFmpeg { #define FFmpeg_FIELD "ffmpeg." const string kBin = FFmpeg_FIELD"bin"; const string kCmd = FFmpeg_FIELD"cmd"; +const string kSnap = FFmpeg_FIELD"snap"; const string kLog = FFmpeg_FIELD"log"; onceToken token([]() { @@ -41,9 +42,12 @@ onceToken token([]() { string ffmpeg_bin = System::execute("where ffmpeg"); //windows下先关闭FFmpeg日志(目前不支持日志重定向) mINI::Instance()[kCmd] = "%s -re -i \"%s\" -loglevel quiet -c:a aac -strict -2 -ar 44100 -ab 48k -c:v libx264 -f flv %s "; + //利用ffmpeg进行抓拍 + mINI::Instance()[kSnap] = "%s -i \"%s\" -loglevel quiet -y -f mjpeg -t 0.001 -s 720*576 %s " #else string ffmpeg_bin = System::execute("which ffmpeg"); mINI::Instance()[kCmd] = "%s -re -i \"%s\" -c:a aac -strict -2 -ar 44100 -ab 48k -c:v libx264 -f flv %s "; + mINI::Instance()[kSnap] = "%s -i \"%s\" -y -f mjpeg -t 0.001 -s 720*576 %s " #endif //默认ffmpeg命令路径为环境变量中路径 mINI::Instance()[kBin] = ffmpeg_bin.empty() ? "ffmpeg" : ffmpeg_bin; @@ -64,6 +68,7 @@ FFmpegSource::~FFmpegSource() { void FFmpegSource::play(const string &src_url,const string &dst_url,int timeout_ms,const onPlay &cb) { GET_CONFIG(string,ffmpeg_bin,FFmpeg::kBin); GET_CONFIG(string,ffmpeg_cmd,FFmpeg::kCmd); + GET_CONFIG(string, ffmpeg_snap, FFmpeg::kSnap); GET_CONFIG(string,ffmpeg_log,FFmpeg::kLog); _src_url = src_url; From 81d3e54d453575f8b0f8dd94e7f351bd3ecfbb93 Mon Sep 17 00:00:00 2001 From: Luke Date: Thu, 16 Jan 2020 11:08:15 +0800 Subject: [PATCH 2/5] mark --- server/FFmpegSource.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/FFmpegSource.cpp b/server/FFmpegSource.cpp index 5ba1d618..0deb3bb2 100644 --- a/server/FFmpegSource.cpp +++ b/server/FFmpegSource.cpp @@ -43,11 +43,11 @@ onceToken token([]() { //windows下先关闭FFmpeg日志(目前不支持日志重定向) mINI::Instance()[kCmd] = "%s -re -i \"%s\" -loglevel quiet -c:a aac -strict -2 -ar 44100 -ab 48k -c:v libx264 -f flv %s "; //利用ffmpeg进行抓拍 - mINI::Instance()[kSnap] = "%s -i \"%s\" -loglevel quiet -y -f mjpeg -t 0.001 -s 720*576 %s " + mINI::Instance()[kSnap] = "%s -i \"%s\" -loglevel quiet -y -f mjpeg -t 0.001 -s 720*576 %s "; #else string ffmpeg_bin = System::execute("which ffmpeg"); mINI::Instance()[kCmd] = "%s -re -i \"%s\" -c:a aac -strict -2 -ar 44100 -ab 48k -c:v libx264 -f flv %s "; - mINI::Instance()[kSnap] = "%s -i \"%s\" -y -f mjpeg -t 0.001 -s 720*576 %s " + mINI::Instance()[kSnap] = "%s -i \"%s\" -y -f mjpeg -t 0.001 -s 720*576 %s "; #endif //默认ffmpeg命令路径为环境变量中路径 mINI::Instance()[kBin] = ffmpeg_bin.empty() ? "ffmpeg" : ffmpeg_bin; From d2d84680c0d1b044d2c684b338aaffcb1fba4429 Mon Sep 17 00:00:00 2001 From: liuziloong <18675721@qq.com> Date: Sun, 19 Jan 2020 14:54:31 +0800 Subject: [PATCH 3/5] temp --- server/Process.cpp | 2 +- server/WebApi.cpp | 54 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/server/Process.cpp b/server/Process.cpp index d64ae72a..eb8eac4d 100644 --- a/server/Process.cpp +++ b/server/Process.cpp @@ -53,7 +53,7 @@ void Process::run(const string &cmd, const string &log_file_tmp) { ZeroMemory(&si, sizeof(si)); //结构体初始化; ZeroMemory(&pi, sizeof(pi)); - LPTSTR lpDir = const_cast(cmd .data()); + LPTSTR lpDir = const_cast(cmd.data()); if (CreateProcess(NULL, lpDir, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)){ //下面两行关闭句柄,解除本进程和新进程的关系,不然有可能 不小心调用TerminateProcess函数关掉子进程 diff --git a/server/WebApi.cpp b/server/WebApi.cpp index b2eb6713..c303b154 100644 --- a/server/WebApi.cpp +++ b/server/WebApi.cpp @@ -771,6 +771,60 @@ void installWebApi() { val["status"] = (int)status; }); + //获取录像列表(按月) + //http://127.0.0.1/index/api/getMp4RecordMonthly?app=pzstll&stream=stream_4&period=2020-01 + API_REGIST(api, getMp4RecordMonthly, { + CHECK_SECRET(); + 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; + if (enableVhost) + { + strMp4RecordPath = recordPath + "/" + _vhost + "/" + recordAppName + "/" + _app + "/" + _stream; + } + else + { + strMp4RecordPath = recordPath + "/" + recordAppName + "/" + _app + "/" + _stream; + } + DebugL << strMp4RecordPath; + + Json::Value nVal; + nVal["vhost"] = _vhost.data(); + nVal["app"] = _app.data(); + nVal["stream"] = _stream.data(); + nVal["app"] = _app.data(); + + val["data"] = nVal; + + }); + + //获取录像列表(按天) + //http://127.0.0.1/index/api/getMp4RecordDaily?app=pzstll&stream=stream_4&period=2020-01-17 + API_REGIST(api, getMp4RecordDaily, { + CHECK_SECRET(); + CHECK_ARGS("app", "stream", "period"); + + + + }); + ////////////以下是注册的Hook API//////////// API_REGIST(hook,on_publish,{ //开始推流事件 From 2384aa5bbdbda963224cb7cbf4dce115649eca5f Mon Sep 17 00:00:00 2001 From: liuziloong <18675721@qq.com> Date: Mon, 20 Jan 2020 15:02:45 +0800 Subject: [PATCH 4/5] =?UTF-8?q?MP4=E5=BD=95=E5=83=8F=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E4=B8=80=E7=BA=A7=E7=9B=AE=E5=BD=95=EF=BC=8C=E6=8C=89=E7=85=A7?= =?UTF-8?q?=EF=BC=9A=E5=B9=B4=E6=9C=88/=E5=B9=B4=E6=9C=88=E6=97=A5/*.mp4?= =?UTF-8?q?=E5=AD=98=E5=82=A8=EF=BC=9B=20=E5=A2=9E=E5=8A=A0=E6=8C=89?= =?UTF-8?q?=E6=9C=88=EF=BC=8C=E6=8C=89=E5=A4=A9=E6=9F=A5=E8=AF=A2mp4?= =?UTF-8?q?=E5=BD=95=E5=83=8F=EF=BC=9B=20=E6=B6=88=E9=99=A4=E4=B8=80?= =?UTF-8?q?=E5=A4=84=E7=BC=96=E8=AF=91=E5=99=A8=E8=AD=A6=E5=91=8A=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/WebApi.cpp | 98 ++++++++++++++++++++++++++++++-------- src/Extension/SPSParser.c | 2 +- src/Record/MP4Recorder.cpp | 6 ++- 3 files changed, 84 insertions(+), 22 deletions(-) diff --git a/server/WebApi.cpp b/server/WebApi.cpp index 28cce944..724328ac 100644 --- a/server/WebApi.cpp +++ b/server/WebApi.cpp @@ -71,6 +71,7 @@ static onceToken token([]() { }); }//namespace API + class ApiRetException: public std::runtime_error { public: ApiRetException(const char *str = "success" ,int code = API::Success):runtime_error(str){ @@ -773,9 +774,9 @@ void installWebApi() { val["status"] = (int)status; }); - //获取录像列表(按月) - //http://127.0.0.1/index/api/getMp4RecordMonthly?app=pzstll&stream=stream_4&period=2020-01 - API_REGIST(api, getMp4RecordMonthly, { + //获取录像列表(按月),返回天 + //http://127.0.0.1/index/api/getMp4RecordMonthly?app=live&stream=onvif&period=2020-01 + api_regist1("/index/api/getMp4RecordMonthly", [](API_ARGS1){ CHECK_SECRET(); CHECK_ARGS("app", "stream", "period"); @@ -787,45 +788,104 @@ void installWebApi() { auto _app = allArgs["app"]; auto _stream = allArgs["stream"]; auto _period = allArgs["period"]; - + //TODO:判断日期格式 //Vhost为空的话,存储路径不一样 - if (_vhost.empty()) - { + if (_vhost.empty()) { _vhost = DEFAULT_VHOST; } - string strMp4RecordPath; - if (enableVhost) - { - strMp4RecordPath = recordPath + "/" + _vhost + "/" + recordAppName + "/" + _app + "/" + _stream; + string strMp4RecordPath = ""; + if (enableVhost) { + strMp4RecordPath = recordPath + "/" + _vhost + "/" + recordAppName + "/" + _app + "/" + _stream + "/" + _period; + } else { + strMp4RecordPath = recordPath + "/" + recordAppName + "/" + _app + "/" + _stream + "/" + _period; } - else - { - strMp4RecordPath = recordPath + "/" + recordAppName + "/" + _app + "/" + _stream; - } - DebugL << strMp4RecordPath; + + //录像相对路径转绝对路径, 不然vs调试需要设置 + strMp4RecordPath = File::absolutePath(strMp4RecordPath, ""); + string strMp4Path = ""; + 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; nVal["vhost"] = _vhost.data(); nVal["app"] = _app.data(); nVal["stream"] = _stream.data(); nVal["app"] = _app.data(); + nVal["path"] = strMp4Path; val["data"] = nVal; - }); //获取录像列表(按天) - //http://127.0.0.1/index/api/getMp4RecordDaily?app=pzstll&stream=stream_4&period=2020-01-17 - API_REGIST(api, getMp4RecordDaily, { + //http://127.0.0.1/index/api/getMp4RecordDaily?app=live&stream=onvif&period=2020-01-17 + api_regist1("/index/api/getMp4RecordDaily",[](API_ARGS1) { CHECK_SECRET(); 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//////////// api_regist1("/index/hook/on_publish",[](API_ARGS1){ diff --git a/src/Extension/SPSParser.c b/src/Extension/SPSParser.c index b073b9cb..54c19592 100644 --- a/src/Extension/SPSParser.c +++ b/src/Extension/SPSParser.c @@ -1330,7 +1330,7 @@ int hevcDecodeShortTermRps(T_GetBitContext *pvBuf, int iDeltaRps; unsigned int uiAbsDeltaRps; uint8_t u8UseDeltaFlag = 0; - uint8_t u8DeltaRpsSign; + uint8_t u8DeltaRpsSign = 0; if (is_slice_header) { unsigned int uiDeltaIdx = parseUe(pvBuf) + 1; diff --git a/src/Record/MP4Recorder.cpp b/src/Record/MP4Recorder.cpp index a92f3fde..cd439820 100644 --- a/src/Record/MP4Recorder.cpp +++ b/src/Record/MP4Recorder.cpp @@ -53,9 +53,10 @@ MP4Recorder::~MP4Recorder() { void MP4Recorder::createFile() { closeFile(); auto strDate = getTimeStr("%Y-%m-%d"); + auto strDay = getTimeStr("%Y-%m-%d"); auto strTime = getTimeStr("%H-%M-%S"); - auto strFileTmp = _strPath + strDate + "/." + strTime + ".mp4"; - auto strFile = _strPath + strDate + "/" + strTime + ".mp4"; + auto strFileTmp = _strPath + strDate + "/" + strDay + "/." + strTime + ".mp4"; + auto strFile = _strPath + strDate + "/" + strDay + "/" + strTime + ".mp4"; /////record 业务逻辑////// _info.ui64StartedTime = ::time(NULL); @@ -66,6 +67,7 @@ void MP4Recorder::createFile() { + _info.strAppName + "/" + _info.strStreamId + "/" + strDate + "/" + + strDay + "/" + strTime + ".mp4"; try { From 795860a0197e3b37c49ae71cdb22ffb8289190e3 Mon Sep 17 00:00:00 2001 From: liuziloong <18675721@qq.com> Date: Mon, 20 Jan 2020 15:22:20 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=9B=AE=E5=BD=95?= =?UTF-8?q?=E7=BA=A7=E5=88=AB=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Record/MP4Recorder.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Record/MP4Recorder.cpp b/src/Record/MP4Recorder.cpp index cd439820..97cc9fac 100644 --- a/src/Record/MP4Recorder.cpp +++ b/src/Record/MP4Recorder.cpp @@ -52,7 +52,7 @@ MP4Recorder::~MP4Recorder() { void MP4Recorder::createFile() { closeFile(); - auto strDate = getTimeStr("%Y-%m-%d"); + auto strDate = getTimeStr("%Y-%m"); auto strDay = getTimeStr("%Y-%m-%d"); auto strTime = getTimeStr("%H-%M-%S"); auto strFileTmp = _strPath + strDate + "/" + strDay + "/." + strTime + ".mp4";