From 381af8e92a424deb9a8ce4c316cabcb9f1b4ffe4 Mon Sep 17 00:00:00 2001
From: miyanhui <dennismi1024@gmail.com>
Date: 星期二, 12 二月 2019 14:17:32 +0800
Subject: [PATCH] 大图新方案合并
---
QiaoJiaSystem/DataManagerServer/http_configserver.cpp | 291 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 278 insertions(+), 13 deletions(-)
diff --git a/QiaoJiaSystem/DataManagerServer/http_configserver.cpp b/QiaoJiaSystem/DataManagerServer/http_configserver.cpp
index 6bdf1ac..53e9376 100644
--- a/QiaoJiaSystem/DataManagerServer/http_configserver.cpp
+++ b/QiaoJiaSystem/DataManagerServer/http_configserver.cpp
@@ -21,7 +21,7 @@
//#include "HcRecord.h"
#include <time.h>
#include <dirent.h>
-
+#include "basic/pipe_element/ffmpeg/basic_struct_for_video_image.h"
using namespace std;
devHttpServer_c::devHttpServer_c()
@@ -65,10 +65,12 @@
void devHttpServer_c::init(void) {
std::string strDevId = appConfig.getStringProperty("DEV_ID");
+
// DSVAD010120181119
m_batch = strDevId.substr(5, 2);
m_SerialNumber = strDevId.substr(7, 2);
+ DBG("DevID: "<<strDevId<<" Batch: "<<m_batch <<" SerNum: "<<m_SerialNumber);
fdfsClient.rwLock.wrlock();
fdfsClient.fastFds = new FastFds("WebFDSClient.conf");
@@ -2399,21 +2401,24 @@
}
}
-std::string devHttpServer_c::getAlarmImageFromVideoFile(std::string ip, unsigned int port, std::string content,
+
+std::string devHttpServer_c::getAlarmImageFromVideoFileByPicDate(const std::string& devId,const std::string& picDate,
PResponse &response) {
- DBG("ip:" << ip << "; port:" << port);
- DBG("content: " << content);
- Json::Reader reader;
- Json::Value value;
+ //DBG("ip:" << ip << "; port:" << port);
+ //DBG("content: " << content);
+ //Json::Reader reader;
+ //Json::Value value;
try {
- if (reader.parse(content, value)) {
+ //if (reader.parse(content, value)) {
+ if(!devId.empty() && !picDate.empty())
+ {
std::string videoPath;
- std::string devId = value["videoNum"].asString();
- std::string picDate = value["picDate"].asString();
+ //std::string devId = value["videoNum"].asString();
+ //std::string picDate = value["picDate"].asString();
//std::string path_uuid = videoPath;//value["path_uuid"].asString();
qint64 sub;
- std::string path = getVideoPathByTime(picDate, devId, sub);
+ std::string path = getVideoPathByPicDate(picDate, devId, sub);
if (path.empty()) {
ERR("{\"error\":\"not find path\"}");
@@ -2521,17 +2526,183 @@
}
}
+
+
+std::string devHttpServer_c::getAlarmImageFromVideoFile(std::string ip, unsigned int port, std::string content,
+ PResponse &response) {
+ INFO("ip:" << ip << "; port:" << port << "content: " << content);
+ Json::Reader reader;
+ Json::Value value;
+ try {
+ if (reader.parse(content, value)) {
+ std::string devId = value["videoNum"].asString();
+ std::string picDate = value["picDate"].asString();
+ std::string imgKey = value["imgKey"].asString();
+ if(imgKey.empty())
+ {
+ return getAlarmImageFromVideoFileByPicDate(devId,picDate,response);
+ }
+ else
+ {
+ return getAlarmImageFromVideoFileByImageKey(devId,imgKey,response);
+ }
+ }
+ else{
+ response->write(SimpleWeb::StatusCode::server_error_not_implemented, "{\"error\":\"浼犺緭閿欒锛岃妫�鏌ワ紒\"}");
+ ERR("ImageURL:浼犺緭閿欒锛岃妫�鏌�");
+ return "";
+ }
+ }
+ catch (std::exception ex) {
+ std::string message = "{\"error\":\"寮傚父閿欒锛�";
+ message.append(const_cast<char *>(ex.what())).append("\"}");
+ response->write(SimpleWeb::StatusCode::server_error_not_implemented, message);
+ ERR("ImageURL:寮傚父閿欒 "<<ex.what());
+ return "";
+ }
+}
+
+
+
+std::string devHttpServer_c::getAlarmImageFromVideoFileByImageKey(const std::string& devId,const std::string& imgKey,
+ PResponse &response) {
+ try {
+ if (!devId.empty() && !imgKey.empty()) {
+ std::string videoPath;
+ std::string path = getVideoPathByImgKey(imgKey, devId);
+ if (path.empty()) {
+ ERR("Not Find Path: "<<path);
+ return "{\"error\":\"鏈煡鍒拌棰戣矾寰刓"}";
+ }
+ videoPath.clear();
+ videoPath = path;
+
+ VideoName_s_t videoSt = VideoName_s_t::fromString(path);
+ ImageName_s_t imgSt = ImageName_s_t::fromString(imgKey);
+
+ //#todo 鎸夌収鏃堕棿鍛藉悕
+ std::string str_imgName(AppUtil::getTimeString() + ".jpg");// = "test.jpg";
+
+ auto frameIdDiff = imgSt.m_frameId-videoSt.m_startFrameId;
+ char selectExpBuff[32]={0};
+ std::string strSelectTemplate=R"#( -vf "select=eq(n\,%d)")#";
+ sprintf(selectExpBuff,strSelectTemplate.c_str(),frameIdDiff-1);
+ if(videoSt.Valid() && imgSt.Valid() ) {
+ std::string cmd("ffmpeg -i '" + videoPath+"'"+std::string(selectExpBuff)+" -vframes 1" +" -y '" + str_imgName + "'");
+ INFO("Video To Image Cmd: "<<cmd);
+ system(cmd.c_str());
+ }
+ else {
+ ERR("Parse Video and Image Failed Path: "<<path <<" ImageId: "<<imgKey);
+ return "{\"error\":\"鏈煡鍒拌棰戣矾寰刓"}";
+ }
+
+ cv::Mat img = cv::imread(str_imgName);
+ if (img.empty()) {
+ ERR("{\"error\":\"Video File error\"}");
+ return "{\"error\":\"瑙嗛鏂囦欢閿欒\"}";
+ }
+
+ std::vector<unsigned char> buffer;
+ CvUtil::cvMat2Buffer(img, buffer);
+ std::string img_url = "http://";
+ fdfsClient.rwLock.rdlock();
+ if (fdfsClient.fastFds != nullptr) {
+ std::string t_strImg = "";
+ if (!fdfsClient.fastFds->uploadFile(buffer, t_strImg, "jpg")) {
+ img_url = "upload image fail";
+ ERR("Upload Image Failed "<<str_imgName);
+ } else {
+ std::string str_tmp_cmd("rm -f '" + str_imgName + "'");
+ system(str_tmp_cmd.c_str());
+ img_url.append(t_strImg);
+ img_url.clear();
+ img_url = t_strImg;
+ }
+ }
+ fdfsClient.rwLock.unlock();
+ std::string result("{\"img_url\":\"" + img_url + "\"}");
+ INFO("ImageURL:"<<img_url);
+ return result;
+ } else {
+ response->write(SimpleWeb::StatusCode::server_error_not_implemented, "{\"error\":\"浼犺緭閿欒锛岃妫�鏌ワ紒\"}");
+ ERR("ImageURL:浼犺緭閿欒锛岃妫�鏌�");
+ return "";
+ }
+ }
+ catch (std::exception ex) {
+ std::string message = "{\"error\":\"寮傚父閿欒锛�";
+ message.append(const_cast<char *>(ex.what())).append("\"}");
+ response->write(SimpleWeb::StatusCode::server_error_not_implemented, message);
+ ERR("ImageURL:寮傚父閿欒 "<<ex.what());
+ return "";
+ }
+}
+
+
+std::string
+devHttpServer_c::getRecordVideoPathNew(std::string ip, unsigned int port, std::string content, PResponse &response) {
+
+ Json::Reader reader;
+ Json::Value value;
+
+ INFO("REQ From: "<<ip<<":"<<port<<" Content:"<<content);
+ if (reader.parse(content, value)) {
+ std::string devId = value["videoNum"].asString();
+ std::string picDate = value["picDate"].asString();
+ std::string imgKey = value["imgKey"].asString();
+ std::string path;
+ if(imgKey.empty())
+ {
+ qint64 sub;
+ path = getVideoPathByPicDate(picDate,devId,sub);
+ }
+ else
+ {
+ path = getVideoPathByImgKey(devId,imgKey);
+ }
+ //std::string path = getVideoPathByImgKey(imgKey, devId, sub);
+ ERR("VideoNum: "<<devId <<" PicDate: "<<picDate<<" imgKey: "<<imgKey);
+ if (path.empty()) {
+ std::string strRsp = "{\"ret_status\":\"鍐呭鏈夎锛岃妫�鏌ワ紒\"}";
+ ERR("RSP:"<< strRsp);
+ return strRsp;
+ } else {
+ std::string result = "{\"file_path\":\"" + path + "\"}";
+ INFO("RSP:"<<result);
+ return result;
+ }
+ } else {
+ std::string strRsp="{\"ret_status\":\"浼犺緭閿欒锛岃妫�鏌ワ紒\"}";
+ ERR("RSP:"<< strRsp);
+ return strRsp;
+ }
+}
+
+
std::string
devHttpServer_c::getRecordVideoPath(std::string ip, unsigned int port, std::string content, PResponse &response) {
Json::Reader reader;
Json::Value value;
+ INFO("REQ From: "<<ip<<":"<<port<<" Content:"<<content);
if (reader.parse(content, value)) {
std::string devId = value["videoNum"].asString();
std::string picDate = value["picDate"].asString();
- qint64 sub;
- std::string path = getVideoPathByTime(picDate, devId, sub);
+ std::string imgKey = value["imgKey"].asString();
+ std::string path;
+ if(imgKey.empty())
+ {
+ qint64 sub;
+ path = getVideoPathByPicDate(picDate,devId,sub);
+ }
+ else
+ {
+ path = getVideoPathByImgKey(devId,imgKey);
+ }
+
+ //std::string path = getVideoPathByTime(picDate, devId, sub);
if (path.empty()) {
return "{\"ret_status\":\"鍐呭鏈夎锛岃妫�鏌ワ紒\"}";
@@ -2620,7 +2791,8 @@
return true;
}
-std::string devHttpServer_c::getVideoPathByTime(const std::string &time, const std::string &camId, qint64 &sub) {
+
+std::string devHttpServer_c::getVideoPathByPicDate(const std::string &time, const std::string &camId, qint64 &sub) {
std::string t_FilePath = appConfig.getStringProperty("cutPath");
bool find = false;
@@ -2680,6 +2852,78 @@
}
+
+std::string devHttpServer_c::GetVideoByImgKey(const std::string strImageName,const std::string& strPath) {
+ static std::mutex g_mutex;
+ std::lock_guard<std::mutex> lock(g_mutex);
+ std::vector<std::string> vec = forEachFileByImgKey(strPath);
+ ImageName_s_t imgSt = ImageName_s_t::fromString(strImageName);
+ if(!imgSt.Valid())
+ {
+ ERR("ParseImageName Failed : "<<strImageName);
+ return "";
+ }
+ //DBG("Path: "<<strPath<<" VecSize: "<<vec.size());
+ std::vector<VideoName_s_t> videoStVec;
+ for (const auto &item : vec) {
+ auto videoParseResult = VideoName_s_t::fromString(item);
+ if (videoParseResult.Valid()) {
+ if (videoParseResult.m_startFrameId <= imgSt.m_frameId &&
+ imgSt.m_frameId < videoParseResult.m_endFrameId) {
+ auto imgTm = AppUtil::ParseFromHypenTimeStr(imgSt.m_timeStamp);
+ auto videoTm = AppUtil::ParseFromHypenTimeStr(videoParseResult.m_timeStamp);
+ if (AppUtil::IsRightAfterLeft(imgTm, videoTm)) {
+ videoStVec.emplace_back(videoParseResult);
+ INFO("Image " << strImageName << " Video: " << item << " Match");
+ } else {
+ ERR("Image " << strImageName << " Video: " << item << " Not Match");
+ }
+ } else{
+ ERR("ImageID: "<<imgSt.m_frameId <<" VideoRange: "<<videoParseResult.m_startFrameId<<" , "<<videoParseResult.m_endFrameId);
+ }
+
+ } else {
+ ERR("VideoName : " << item << " Parse Failed");
+ }
+ }
+
+ if (videoStVec.size() >= 1) {
+ std::string strVideoName = strPath + videoStVec[0].ToVideoName();
+ INFO("ImageName: "<<strImageName<<" SingleMatchVideo: "<<strVideoName);
+ return strVideoName;
+ } else {
+ ERR("ImageName: "<<strImageName<<" MatchVideoCount: "<<videoStVec.size());
+ for(auto& item:vec)
+ {
+ ERR("VideoName: "<<item);
+ }
+ return "";
+ }
+}
+
+//鏂扮殑鏍规嵁鍥剧墖鍚嶇О鑾峰彇璺緞鐨勬柟娉�
+std::string devHttpServer_c::getVideoPathByImgKey(const std::string &strImageName, const std::string &camId)
+{
+ INFO("GetVideoFor: "<<strImageName<<" CamID:"<<camId);
+ ImageName_s_t imgSt= ImageName_s_t::fromString(strImageName);
+
+ struct tm imgTime = AppUtil::ParseFromHypenTimeStr(imgSt.m_timeStamp);
+ char curFolder[128]={0};
+ // 201901/26/2019012614 ---- 201901/26/2019012615 {骞存湀}/{鏃/{骞存湀鏃ユ椂}/
+ sprintf(curFolder,"%04d%02d/%02d/%04d%02d%02d%02d/",imgTime.tm_year+1900,imgTime.tm_mon+1,
+ imgTime.tm_mday,
+ imgTime.tm_year+1900,imgTime.tm_mon+1,imgTime.tm_mday,imgTime.tm_hour);
+ std::string t_FilePath = appConfig.getStringProperty("cutPath");
+ std::string videoPath = t_FilePath+"/"+camId+"/"+std::string(curFolder);
+ return GetVideoByImgKey(strImageName,videoPath);
+}
+
+
+/*std::string devHttpServer_c::getVideoPathByTime(const std::string &time, const std::string &camId, qint64 &sub) {
+
+ return getVideoPathByTime2(time,camId,sub);
+}*/
+
qint64 devHttpServer_c::getVideoTime(/*const std::string &videoPath,*/std::string &str_tmpTime) {
// std::string cmd_getVideoFileTime(
// " ffmpeg -i '" + videoPath + "' 2>&1 | grep 'Duration' | cut -d ' ' -f 4 | sed s/,//");
@@ -2704,6 +2948,7 @@
return len_ms;
}
+//鑾峰彇鏌愪釜鐩綍涓嬬殑鎵�鏈夋枃浠讹紝涓嶅甫鎵╁睍鍚�
std::vector<std::string> devHttpServer_c::forEachFile(const std::string &dir_name) {
std::vector<std::string> v;
auto dir = opendir(dir_name.data());
@@ -2725,6 +2970,26 @@
return v;
}
+//鑾峰彇鏌愪釜鐩綍涓嬬殑鎵�鏈夋枃浠讹紝甯︽墿灞曞悕
+std::vector<std::string> devHttpServer_c::forEachFileByImgKey(const std::string &dir_name) {
+ std::vector<std::string> v;
+ auto dir = opendir(dir_name.data());
+ struct dirent *ent;
+ int len = 0;
+ if (dir) {
+ while ((ent = readdir(dir)) != NULL) {
+ std::string filename = std::string(ent->d_name);
+ std::string temp;
+ if (filename != "." && filename != "..") {
+ v.push_back(filename);
+ }
+
+ }
+ closedir(dir);
+ }
+ return v;
+}
+
std::string devHttpServer_c::addPersons(std::string ip, unsigned int port, std::string content, PResponse &response) {
DBG("ip:" << ip << "; port:" << port);
// DBG("content: " << content);
--
Gitblit v1.8.0