一、前言
视频监控内核组件重构和完善花了一年多时间,整个组件个人认为设计的最好的部分就是各种结构体参数的设计,而且分门别类,有枚举值,也有窗体相关的结构体参数,解码相关的结构体参数,同时将部分常用的结构体参数的获取和设置单独提供了函数,参阅海康大华等大厂的sdk的设计方式,也是将众多的参数统一归类的不同的结构体中,这样后期非常容易就能拓展,比如又新增一个参数,只需要动结构体就行,但是也有个不完美的地方就是,如果没有提供单独的参数设置接口,需要先获取之前的结构体参数,然后在此基础上修改,最后重新设置,因为如果你没有先获取再更新最后设置,而是重新定义了一个结构体参数,则很可能会把之前设置好的结构体参数覆盖掉。
窗体结构体参数设计如下:
//窗体参数
struct WidgetPara {
int borderWidth; //边框大小
QColor borderColor; //边框颜色
QColor focusColor; //焦点颜色
QColor bgColor; //背景颜色
QColor textColor; //文字颜色
QColor fillColor; //填充颜色
int bgTextSize; //文字大小
QString bgText; //背景文字
QImage bgImage; //背景图片
QString videoFlag; //视频通道标识
ScaleMode scaleMode; //缩放显示模式
VideoMode videoMode; //视频显示模式
DrawMode osdDrawMode; //标签绘制模式
DrawMode graphDrawMode; //图形绘制模式
int soundValue; //默认音量大小
bool soundMuted; //默认静音状态
bool sharedData; //共享解码线程
bool copyImage; //是否拷贝图片
bool restartClear; //重连清空画面
bool bannerEnable; //悬浮条是否启用
int bannerSize; //悬浮条尺寸大小(横向则表示高度/纵向表示宽度)
BannerPosition bannerPosition;//悬浮条位置
WidgetPara() {
borderWidth = 1;
borderColor = Qt::transparent;
focusColor = "#22A3A9";
bgColor = Qt::transparent;
textColor = Qt::transparent;
fillColor = Qt::transparent;
//fillColor = Qt::black;
bgTextSize = 25;
bgText = "视频";
bgImage = QImage();
//bgImage = QImage(":/image/bg_novideo.png");
videoFlag = "";
scaleMode = ScaleMode_Auto;
videoMode = VideoMode_Hwnd;
osdDrawMode = DrawMode_Cover;
graphDrawMode = DrawMode_Cover;
soundValue = 100;
soundMuted = false;
sharedData = false;
copyImage = false;
restartClear = true;
bannerEnable = false;
bannerSize = 25;
bannerPosition = BannerPosition_Top;
}
};
视频采集结构体参数设计如下:
//视频采集参数
struct VideoPara {
VideoCore videoCore; //解析内核
QString videoUrl; //视频地址
QString bufferSize; //缓存分辨率
int frameRate; //视频帧率
DecodeType decodeType; //解码速度策略
QString hardware; //硬件加速名称
QString transport; //通信协议(tcp udp)
int caching; //缓存时间(默认500毫秒)
bool audioLevel; //开启音频振幅
bool decodeAudio; //解码音频数据
bool playAudio; //解码播放声音
bool playRepeat; //重复循环播放
int openSleepTime; //打开休息时间(最低1000 单位毫秒)
int readTimeout; //采集超时时间(0=不处理 单位毫秒)
int connectTimeout; //连接超时时间(0=不处理 单位毫秒)
VideoPara() {
videoCore = VideoCore_None;
videoUrl = "";
bufferSize = "0x0";
frameRate = 0;
decodeType = DecodeType_Fast;
hardware = "none";
transport = "tcp";
caching = 500;
audioLevel = false;
decodeAudio = true;
playAudio = true;
playRepeat = false;
openSleepTime = 3000;
readTimeout = 0;
connectTimeout = 500;
}
void reset() {
videoUrl = "";
bufferSize = "0x0";
frameRate = 0;
}
};
二、效果图
在这里插入图片描述
三、体验地址
-
国内站点:https://gitee.com/feiyangqingyun
-
国际站点:https://github.com/feiyangqingyun
-
个人作品:https://blog.csdn.net/feiyangqingyun/article/details/97565652
-
体验地址:https://pan.baidu.com/s/1d7TH_GEYl5nOecuNlWJJ7g 提取码:01jf 文件名:bin_video_system。
-
联系方式:微信 feiyangqingyun
-
官方店:https://shop114595942.taobao.com/
四、相关代码
void frmPlayer::initPara()
{
//设置窗体参数
WidgetPara widgetPara = ui->videoWidget->getWidgetPara();
widgetPara.scaleMode = (ScaleMode)AppConfig::Player_ScaleMode;
widgetPara.videoMode = (VideoMode)AppConfig::Player_VideoMode;
widgetPara.soundValue = AppConfig::Player_SoundValue;
widgetPara.soundMuted = AppConfig::Player_SoundMuted;
widgetPara.bannerEnable = true;
//设置视频参数
VideoPara videoPara = ui->videoWidget->getVideoPara();
videoPara.videoCore = (VideoCore)AppConfig::Player_VideoCore;
videoPara.videoUrl = AppConfig::Player_VideoUrl;
videoPara.decodeType = (DecodeType)AppConfig::Player_DecodeType;
videoPara.hardware = AppConfig::Player_Hardware;
videoPara.caching = AppConfig::Player_Caching;
videoPara.audioLevel = true;
videoPara.playRepeat = AppConfig::Player_PlayRepeat;
videoPara.openSleepTime = AppConfig::Player_OpenSleepTime;
videoPara.readTimeout = AppConfig::Player_ReadTimeout;
videoPara.connectTimeout = AppConfig::Player_ConnectTimeout;
//要先初始化参数再设置
VideoHelper::initPara(widgetPara, videoPara);
ui->videoWidget->setWidgetPara(widgetPara);
ui->videoWidget->setVideoPara(videoPara);
}
void frmPlayer::on_btnPlay_clicked()
{
this->initPara();
if (!ui->videoWidget->init()) {
return;
}
//关联采集线程信号槽
VideoThread *videoThread = ui->videoWidget->getVideoThread();
connect(videoThread, SIGNAL(receivePlayStart(int)), this, SLOT(receivePlayStart(int)));
connect(videoThread, SIGNAL(receivePlayFinsh()), this, SLOT(receivePlayFinsh()));
connect(videoThread, SIGNAL(recorderStateChanged(RecorderState, QString)), this, SLOT(recorderStateChanged(RecorderState, QString)));
connect(videoThread, SIGNAL(receiveDuration(qint64)), this, SLOT(receiveDuration(qint64)));
connect(videoThread, SIGNAL(receivePosition(qint64)), this, SLOT(receivePosition(qint64)));
connect(videoThread, SIGNAL(receiveVolume(int)), this, SLOT(receiveVolume(int)));
connect(videoThread, SIGNAL(receiveMuted(bool)), this, SLOT(receiveMuted(bool)));
//设置音视频保存的格式类型
videoThread->setSaveVideoType(SaveVideoType_Mp4);
videoThread->setSaveAudioType(SaveAudioType_None);
ui->videoWidget->play();
ui->widget->setEnabled(false);
//复位和清空标签及图形相关(也可以不清空这样相当于可以提前设置)
osdIndex = 0;
graphIndex = 0;
ui->videoWidget->clearOsd();
ui->videoWidget->clearGraph();
}
void frmPlayer::on_btnStop_clicked()
{
ui->videoWidget->stop();
ui->widget->setEnabled(true);
}