From 080afae264fe7ff89a54886f28dff208fe5a06c4 Mon Sep 17 00:00:00 2001 From: chenshijun <csj_sky@126.com> Date: 星期二, 16 四月 2019 22:01:35 +0800 Subject: [PATCH] 整合代码 --- QiaoJiaSystem/VideoToImageMulth/RtspCaptureElement.cpp | 68 +++++++++++++++++++++++++++------ 1 files changed, 55 insertions(+), 13 deletions(-) diff --git a/QiaoJiaSystem/VideoToImageMulth/RtspCaptureElement.cpp b/QiaoJiaSystem/VideoToImageMulth/RtspCaptureElement.cpp index 70c9143..38fcecb 100644 --- a/QiaoJiaSystem/VideoToImageMulth/RtspCaptureElement.cpp +++ b/QiaoJiaSystem/VideoToImageMulth/RtspCaptureElement.cpp @@ -2,12 +2,14 @@ #include <basic/debug/Debug.h> #include <opencv2/opencv.hpp> #include <basic/timer_counter/Clocktimer.h> -#include <basic/pipe_element/ffmpeg/cap_ffmpeg_impl.hpp> #include <thread> #include <basic/util/app/AppPreference.hpp> #include <QString> #include <QDateTime> #include "RtspAnalysManager.h" +//#include <basic/pipe_element/ffmpeg/cap_ffmpeg_impl.hpp> +#include "../../../BasicPlatForm/basic/pipe_element/ffmpeg/FfmpegElement.cpp" +#include <basic/util/app/AppConfig.h> RtspCaptureElement::RtspCaptureElement(const std::string &path, const std::string &camId, int fps, int reopenTime, int gpuIndex, RtspAnalysManager *manager) : @@ -37,25 +39,57 @@ } } - m_picCount++; - //鍑犲紶閫変竴寮犳斁鍏edis - if (m_picCount % m_nPicsPickOne != 0) { - return; + u_char *data; + int width = 0, height = 0, step = 0, cn = 0; + cv::Mat copyMat; + + //#publish Video + if (m_publishVideoRet) { + if (videoPublishElement == nullptr) { + string path = appConfig.getStringProperty("srsAddr") + "cam" + m_camId + ".flv"; + cv::Size size_(appConfig.getIntProperty("pulish.width"), appConfig.getIntProperty("pulish.height")); + int gupIdx = appPref.getIntData("gpu.index"); + videoPublishElement = new ffmpeg::VideoPublishElement(path, size_, "flv", 25, gupIdx); + videoPublishElement->start(); + } else { +// DBG("videoPublishElement->setImage()"); + m_capture->retrieveFrame(0, &data, &step, &width, &height, &cn); + cv::Mat img(height, width, CV_8UC3, data, step); + img.copyTo(copyMat); + + if (!copyMat.empty()) { + videoPublishElement->setImage(copyMat); + } else { + DBG("copyMat.empty()"); + } + } } else { - m_picCount.store(0); + if (videoPublishElement != nullptr) { + DBG("videoPublishElement->stop()"); + videoPublishElement->stop(); + videoPublishElement->wait(); + delete videoPublishElement; + videoPublishElement = nullptr; + } } - { - u_char *data; - int width = 0, height = 0, step = 0, cn = 0; - m_capture->retrieveFrame(0, &data, &step, &width, &height, &cn); + //鍑犲紶閫変竴寮犳斁鍏edis + m_picCount++; + if (m_picCount % m_nPicsPickOne != 0) { +// return; + } else { + m_picCount.store(0); - cv::Mat img(height, width, CV_8UC3, data, step); - cv::Mat copyMat; - img.copyTo(copyMat); + if (copyMat.empty()) { +// ERR("copyMat.empty()"); + m_capture->retrieveFrame(0, &data, &step, &width, &height, &cn); + cv::Mat img(height, width, CV_8UC3, data, step); + img.copyTo(copyMat); + } std::string imageName = m_capture->GetImageName(); m_pManager->SaveImageToRedis(m_camId, imageName, copyMat); } + fireConnectors(); } @@ -113,3 +147,11 @@ m_capture->SetMinMaxVideoSeconds(minSeconds, maxSeconds); } +void RtspCaptureElement::startPublishVideo() { + m_publishVideoRet = true; +} + +void RtspCaptureElement::stopPublishVideo() { + m_publishVideoRet = false; +} + -- Gitblit v1.8.0