该案例将以两路视频为案例,采用视频流媒体的方式,对多路视频流的播放进行简单的讲解。本案例使用的是大华摄像头。出流格式为rtsp://username:password@ip:port/cam/realmonitor?channel=channelNo&subtype=subtypeNo
可以参造以下链接
https://help.simtutai.cn/docs/ru-he-she-zhi-MMA?search=1
在常规控件中选择视频播放器
控件,设置视频源参数。
本案例在明确流媒体格式及具体地址时可以直接在流媒体->地址
中设置相应地址,如果需要随着变量的变化,对地址进行拼接,可以选择暂不指定
如果是固定的视频文件,可以保留
启动时自动播放
的选项,对于流媒体播放,将自动播放设置为否
以上,一路视频就添加完成了。目前最多支持四路视频
的播放。
可以在页面中添加定时器,或者添加按钮,进行手动播放
可以按照如下方式设置定时器:
注意
如果使用定时器开启,一定要将次数限制设置为 1
void Frm01::wMTimer1_timer_cb(uint16_t code, LvEvent e) {
// 播放视频
wMVideo1->play();
wMVideo2->play();
}
接下来,可以在 onLoad 函数中对定时器进行开启。
void Frm01::onLoad(){
wMTimer1->start();
}
如果在第一次运行,或者是跳转页面运行时未检测到流媒体,页面会显示空白,之后就算连接上设备也不会有显示,因此可以添加一个刷新按钮,并给按钮设置点击事件
void Frm01::wMButton1_clk_cb(uint16_t code, LvEvent e) {
/*wMButton1(刷新)的点击事件*/
wMVideo1->play();
}
让控件重新进行播放,便可解决页面卡顿不刷新、显示空白的问题
选择暂不指定格式,如下图所示
按照上面同样的方法添加定时器。在页面中自定义函数,设置视频流地址。
void Frm01::showStream(){
string ip,username,password;
vm->getChar("IP",ip);
vm->getChar("Username",username);
vm->getChar("Password",password);
string url = hmiApp->buildRTSPUrl(ip,username,password);
// 这里是在复写视频控件自动生成的 有关于该控件的坐标,大小
wMVideo1->setMainArg(6, 40, 500, 320, url);
wMVideo1->play();
}
组合为流媒体
string HmiApp::buildRTSPUrl(const string& ip, const string& username, const string& password, int channel,int subtype) {
return "rtsp://" + username + ":" + password + "@" + ip + ":554/cam/realmonitor?channel="+to_string(channel)+"&subtype="+to_string(subtype);
}
在定时器中运行该方法
void Frm01::wMTimer1_timer_cb(uint16_t code, LvEvent e) {
showStream();
}
/**
* @LEVEL0
* @brief 开始播放第i个视频
*/
STTFFmpeg* play();
/**
* @LEVEL0
* @brief 停止
*/
STTFFmpeg* stop();
/**
* @LEVEL0
* @brief 暂停
*/
STTFFmpeg* pause();
/**
* @LEVEL0
* @brief 继续
*/
STTFFmpeg* resume();
/**
* @LEVEL2
* @brief 保存当前播放帧图片(正在播放时有效)
* @param path 保存路径(后缀名可为png或jpg)
*/
bool saveJpg(string path);
util::FileUtil::createPath("/customer/prm/snapshot/");
uint64_t stamp = util::DateUtil::getMsTimeStamp2();
wMVideo1->saveJpg("/customer/prm/snapshot/"+to_string(stamp)+".png");