chenshijun
2019-04-16 f946a62d3921e86b44ff8e2973138304b9cd53cd
QiaoJiaSystem/VideoToImageMulth/RtspCaptureElement.cpp
@@ -9,6 +9,7 @@
#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) :
@@ -38,25 +39,58 @@
        }
    }
    m_picCount++;
    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::PipeVideoPublishElement(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);
                videoPublishElement->submit();
            } else {
                DBG("copyMat.empty()");
            }
        }
    } else {
        if (videoPublishElement != nullptr) {
            DBG("videoPublishElement->stop()");
            videoPublishElement->stop();
            videoPublishElement->wait();
            delete videoPublishElement;
            videoPublishElement = nullptr;
        }
    }
    //几张选一张放入Redis
    m_picCount++;
    if (m_picCount % m_nPicsPickOne != 0) {
        return;
    } else {
        m_picCount.store(0);
    }
    {
        u_char *data;
        int width = 0, height = 0, step = 0, cn = 0;
    if (copyMat.empty()) {
//        ERR("copyMat.empty()");
        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();
        m_pManager->SaveImageToRedis(m_camId, imageName, copyMat);
    }
    std::string imageName = m_capture->GetImageName();
    m_pManager->SaveImageToRedis(m_camId, imageName, copyMat);
    fireConnectors();
}
@@ -114,3 +148,11 @@
    m_capture->SetMinMaxVideoSeconds(minSeconds, maxSeconds);
}
void RtspCaptureElement::startPublishVideo() {
    m_publishVideoRet = true;
}
void RtspCaptureElement::stopPublishVideo() {
    m_publishVideoRet = false;
}