#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硬解码
|
* 主要完成视频帧的获取以及向CvCapture_FFMPEG传送数据
|
*/
|
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);
|
|
//保存视频接口,从RtspAnalysManager发起调用
|
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();
|
|
//根据timeStamp创建路径
|
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;
|
|
//几张图丢一张,目前是8张丢一张
|
const int m_nPicsPickOne = 8;
|
|
RtspAnalysManager *m_pManager;
|
};
|
|
#endif // VIDEOCAPTUREELEMENT_H
|