#include "RtspCaptureElement.h" #include #include #include #include #include #include #include #include RtspCaptureElement::RtspCaptureElement(const std::string &path, const std::string& camId,int fps, int reopenTime, int gpuIndex): TimerElement(10),m_path(path),m_gpuIndex(gpuIndex), m_reopenTime(reopenTime),m_camId(camId){ m_cutPath= appPref.getStringData("user.loop.absolute.path"); assert(!m_cutPath.empty()); m_capture = new CvCapture_FFMPEG(m_camId); } //定时执行,将 void RtspCaptureElement::timerFunc() { u_char *data = nullptr; int width = 0; int height = 0; int step = 0; int cn = 0; DBG("GRABFrame "<grabFrame(); if (!ret) { if (m_reopenTime < 0) { stop(); INFO("grabFrame faild, element stopping"); return; } else { usleep(m_reopenTime * 100); INFO("grabFrame faild, try reopen video: " << m_path); openVideo(); ret = m_capture->grabFrame(); if (!ret)return; } } m_picCount++; //几张选一张放入Redis if (m_picCount % m_nPicsPickOne != 0) { return; } else { m_picCount.store(0); } { ClockTimer timer("FrameToImage"); m_capture->retrieveFrame(0, &data, &step, &width, &height, &cn); cv::Mat img(height, width, CV_8UC3, data, step); cv::Mat copyMat; img.copyTo(copyMat); std::string imageName = m_capture->GetImageName(); } fireConnectors(); } std::string RtspCaptureElement::MakeDir(const std::string &timeStamp) { std::string t_FilePath = m_cutPath; if (t_FilePath.back() != '/') { t_FilePath.push_back('/'); } char buf[24]; QDateTime dt = QDateTime::fromString(QString::fromStdString(timeStamp), "yyyy-MM-dd hh:mm:ss:zzz"); std::string t_strTime=dt.toString("yyyyMMddhh").toStdString(); // DBG("t_strTime="<SaveVideoByImageName(strPath,strImageName); } void RtspCaptureElement::openVideo() { if(m_gpuIndex>=0){ setenv("CUDA_VISIBLE_DEVICES", std::to_string(m_gpuIndex).c_str(),0); } bool bResult = m_capture->open(m_path.c_str(),m_gpuIndex>=0); if(bResult) { INFO("GPUIndex: "<close(); delete m_capture; m_capture = nullptr; } //设置保存视频的最小和最大时长 void RtspCaptureElement::SetVideoMinMaxSeconds(const int minSeconds, const int maxSeconds) { INFO("VideoMinSeconds: "<SetMinMaxVideoSeconds(minSeconds,maxSeconds); }