| | |
| | | #include <time.h> |
| | | #include <dirent.h> |
| | | #include "basic/pipe_element/ffmpeg/basic_struct_for_video_image.h" |
| | | |
| | | using namespace std; |
| | | |
| | | devHttpServer_c::devHttpServer_c() |
| | |
| | | std::string out = value.size() > 0 ? value.toStyledString() : "[]"; |
| | | return out; |
| | | } |
| | | |
| | | #define ADD_CAMERA 0 |
| | | #define EDIT_CAMERA 1 |
| | | |
| | | //编辑摄像机 |
| | | std::string devHttpServer_c::cam_edit(std::string ip, unsigned int port, std::string content, PResponse &response) { |
| | | DBG("ip:" << ip << "; port:" << port); |
| | |
| | | // rec_sdk.str_det_thr = QString::fromStdString(value["str_det_thr"].asString()); |
| | | // rec_sdk.str_cmp_thr = QString::fromStdString(value["str_cmp_thr"].asString()); |
| | | bool is_exist=db_c.searchCamDevByCamId(rec.str_cam_dev_id); |
| | | if(ADD_CAMERA == type ) |
| | | { |
| | | if(is_exist) |
| | | { |
| | | if (ADD_CAMERA == type) { |
| | | if (is_exist) { |
| | | return "{\"ret_status\": \"请勿重复添加!\"}"; |
| | | } |
| | | else |
| | | { |
| | | } else { |
| | | ret =db_c.insertCamDevTable(rec); |
| | | if (!ret) { |
| | | return "err_db_content"; |
| | | } |
| | | } |
| | | } |
| | | else if(EDIT_CAMERA == type ) |
| | | { |
| | | if(is_exist) |
| | | { |
| | | } else if (EDIT_CAMERA == type) { |
| | | if (is_exist) { |
| | | ret = db_c.updateCamDevTable(rec); |
| | | if (!ret) { |
| | | return "err_db_content"; |
| | | } |
| | | } |
| | | else |
| | | { |
| | | } else { |
| | | return "{\"ret_status\": \"内容有误,请检查!\"}"; |
| | | } |
| | | } |
| | | else |
| | | { |
| | | } else { |
| | | return "{\"ret_status\": \"内容有误,请检查!\"}"; |
| | | } |
| | | |
| | |
| | | std::string devHttpServer_c::getAlarmImageByPicDateAndDevId(const std::string& picDate,const std::string& devId, |
| | | PResponse &response) { |
| | | try { |
| | | if(!devId.empty() && !picDate.empty()) |
| | | { |
| | | if (!devId.empty() && !picDate.empty()) { |
| | | std::string videoPath; |
| | | qint64 sub; |
| | | std::string path = getVideoPathByPicDate(picDate, devId, sub); |
| | |
| | | } |
| | | |
| | | |
| | | |
| | | std::string devHttpServer_c::getAlarmImageFromVideoFile(std::string ip, unsigned int port, std::string content, |
| | | PResponse &response) { |
| | | INFO("ip:" << ip << "; port:" << port << "content: " << content); |
| | |
| | | std::string picDate = value["picDate"].asString(); |
| | | std::string imgKey = value["imgKey"].asString(); |
| | | //兼容旧版本 |
| | | if(imgKey=="undefined" || imgKey.empty()) |
| | | { |
| | | if (imgKey == "undefined" || imgKey.empty()) { |
| | | DBG("getAlarmImageByPicDateAndDevId " << imgKey); |
| | | return getAlarmImageByPicDateAndDevId(picDate,devId,response); |
| | | } |
| | | else |
| | | { |
| | | } else { |
| | | DBG("getAlarmImageByImageKeyAndDevId " << imgKey); |
| | | return getAlarmImageByImageKeyAndDevId(imgKey,devId,response); |
| | | } |
| | | } |
| | | else{ |
| | | } else { |
| | | response->write(SimpleWeb::StatusCode::server_error_not_implemented, "{\"error\":\"传输错误,请检查!\"}"); |
| | | ERR("ImageURL:传输错误,请检查"); |
| | | return ""; |
| | |
| | | return ""; |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | std::string devHttpServer_c::getAlarmImageByImageKeyAndDevId(const std::string& imgKey,const std::string& devId, |
| | |
| | | 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 + "'"); |
| | | 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 { |
| | | } else { |
| | | ERR("Parse Video and Image Failed Path: "<<path <<" ImageId: "<<imgKey); |
| | | return "{\"error\":\"未查到视频路径\"}"; |
| | | } |
| | |
| | | std::string path; |
| | | |
| | | //兼容旧版本 |
| | | if(imgKey=="undefined"||imgKey.empty()) |
| | | { |
| | | if (imgKey == "undefined" || imgKey.empty()) { |
| | | qint64 sub; |
| | | path = getVideoPathByPicDate(picDate,devId,sub); |
| | | } |
| | | else |
| | | { |
| | | } else { |
| | | path = getVideoPathByImgKey(imgKey,devId); |
| | | } |
| | | //std::string path = getVideoPathByImgKey(imgKey, devId, sub); |
| | |
| | | std::lock_guard<std::mutex> lock(g_mutex); |
| | | std::vector<std::string> vec = forEachFileByImgKey(strPath); |
| | | ImageName_s_t imgSt = ImageName_s_t::fromString(imgKey); |
| | | if(!imgSt.Valid()) |
| | | { |
| | | if (!imgSt.Valid()) { |
| | | ERR("ParseImageName Failed : "<<imgKey); |
| | | return ""; |
| | | } |
| | |
| | | ERR("Image " << imgKey << " Video: " << item << " Not Match"); |
| | | } |
| | | } else{ |
| | | ERR("ImageID: "<<imgSt.m_frameId <<" VideoRange: "<<videoParseResult.m_startFrameId<<" , "<<videoParseResult.m_endFrameId); |
| | | ERR("ImageID: " << imgSt.m_frameId << " VideoRange: " << videoParseResult.m_startFrameId << " , " |
| | | << videoParseResult.m_endFrameId); |
| | | } |
| | | |
| | | } else { |
| | |
| | | return strVideoName; |
| | | } else { |
| | | ERR("ImageName: "<<imgKey<<" MatchVideoCount: "<<videoStVec.size()); |
| | | for(auto& item:vec) |
| | | { |
| | | for (auto &item:vec) { |
| | | ERR("VideoName: "<<item); |
| | | } |
| | | return ""; |
| | |
| | | } |
| | | |
| | | //新的根据图片名称获取路径的方法 |
| | | std::string devHttpServer_c::getVideoPathByImgKey(const std::string &imgKey, const std::string &camId) |
| | | { |
| | | std::string devHttpServer_c::getVideoPathByImgKey(const std::string &imgKey, const std::string &camId) { |
| | | INFO("GetVideoFor: "<<imgKey<<" CamID:"<<camId); |
| | | ImageName_s_t imgSt= ImageName_s_t::fromString(imgKey); |
| | | |
| | |
| | | std::string videoPath = t_FilePath+"/"+camId+"/"+std::string(curFolder); |
| | | return GetVideoNameByImgKey(imgKey,videoPath); |
| | | } |
| | | |
| | | |
| | | |
| | | qint64 devHttpServer_c::getVideoTime(/*const std::string &videoPath,*/std::string &str_tmpTime) { |
| | |
| | | std::string pass = value["str_password"].asString(); |
| | | std::string brand = value["str_brand"].asString(); |
| | | std::string rtsp_url = rtspAddrBuild(ip, port, username, pass, brand); |
| | | if (rtsp_url.empty() ) |
| | | { |
| | | if (rtsp_url.empty()) { |
| | | return "{\"ret_status\":\"内容有误,请检查!\"}"; |
| | | } |
| | | // unsigned char serialnumber[SERIALNO_LEN] = {0}; |
| | |
| | | str_imgName +="-"; |
| | | str_imgName += "snapshot.jpg"; |
| | | //admin:a1234567@192.168.1.201:554/h264/ch1/main/av_stream -r 1/25 -f image2 -s 1920*1080 /home/basic/work_src/a.jpg |
| | | std::string cmd("ffmpeg -i " + rtsp_url + " -vf select='eq(pict_type\\,I)',setpts='N/(25*TB)' -f image2 -s 1920*1080 -y " + str_imgName); |
| | | std::string cmd( |
| | | "ffmpeg -i " + rtsp_url + " -vf select='eq(pict_type\\,I)',setpts='N/(25*TB)' -f image2 -s 1920*1080 -y " + |
| | | str_imgName); |
| | | // std::string cmd("ffmpeg -i " + rtsp_url + " -r 1/25 -f image2 -s 1920*1080 -y " + str_imgName); |
| | | DBG(cmd); |
| | | system(cmd.c_str()); |