派生自 development/c++

miyanhui
2019-02-13 dccc8c41c31866785fdaf5cba40354cdc7afbd8f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#ifndef RTSPCAPTUREELEMENT_H
#define RTSPCAPTUREELEMENT_H
 
#include <basic/pipe/TimerElement.h>
#include <opencv2/opencv.hpp>
#include "../StructureApp/HiredisTool.h"
#include <atomic>
class RtspAnalysManager;
struct CvCapture_FFMPEG;
 
    /**
     * 使用ffmpeg封装的视频采集流水元素
     * 输入,rtsp地址或文件(mp4或avi)路径,输出opencv中的cv::Mat
     * 支持GPU硬解码
     */
    class RtspCaptureElement: public TimerElement {
    public:
        RtspCaptureElement(const std::string& path,const std::string& camId, int fps = 30, int reOpenTime = -1, int gpuIndex = -1,RtspAnalysManager* manager= nullptr);
        void SaveVideo(const std::string& strImageName);
        void SetVideoMinMaxSeconds(const int minSeconds,const int maxSeconds);
    private:
        virtual void timerFunc() override;
        virtual void threadInitial() override;
        virtual void threadClosing() override;
        void openVideo();
 
        //
        std::string MakeDir(const std::string& timeStamp);
    private:
        //用来抓取视频的Ffmpeg的封装类
        CvCapture_FFMPEG* m_capture;
        //保存视频流的路径,类似于rtsp://admin:a1234567@192.168.1.201:554/h264/ch2/main/av_stream
        std::string m_path;
 
        // Redis的工具类
        HiredisTool m_redisTool;
 
        //对保存到Redis的图片进行计数
        std::atomic<int> m_picCount{0};
        //GPU的索引
        int m_gpuIndex;
 
        //打开视频流失败的时候,sleep一段时间
        int m_reopenTime;
 
        //摄像机ID
        std::string m_camId;
 
        //用来保存录像视频的路径
        std::string m_cutPath;
 
        //几张图丢一张,目前是4张丢一张
        const int m_nPicsPickOne = 8;
 
        //每台摄像机保存到Redis的图片数量的最大值
        const int M_CAM_PIC_MAX_COUNT = 50;
 
        RtspAnalysManager * m_pManager;
    };
 
#endif // VIDEOCAPTUREELEMENT_H