You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
120 lines
3.0 KiB
C++
120 lines
3.0 KiB
C++
8 months ago
|
#include "ffmpegvideodlg.h"
|
||
|
#include "ui_ffmpegvideodlg.h"
|
||
7 months ago
|
#include <QMessageBox>
|
||
8 months ago
|
|
||
|
ffmpegvideoDlg::ffmpegvideoDlg(QWidget *parent)
|
||
|
: QWidget(parent)
|
||
|
, ui(new Ui::ffmpegvideoDlg)
|
||
|
{
|
||
|
ui->setupUi(this);
|
||
|
iniWindow();
|
||
|
}
|
||
|
|
||
|
ffmpegvideoDlg::~ffmpegvideoDlg()
|
||
|
{
|
||
7 months ago
|
stop();
|
||
8 months ago
|
delete ui;
|
||
8 months ago
|
}
|
||
|
|
||
|
|
||
|
void ffmpegvideoDlg::iniWindow()
|
||
|
{
|
||
7 months ago
|
QString VideoFilePath = QDir::currentPath()+"./Video";
|
||
|
QDir VideoDir (VideoFilePath);
|
||
|
if(!VideoDir.exists())
|
||
|
{
|
||
|
VideoDir.mkdir(VideoFilePath);
|
||
|
qDebug()<<"文件夹创建成功";
|
||
|
}
|
||
|
}
|
||
8 months ago
|
void ffmpegvideoDlg::setUrl(QString url)
|
||
|
{
|
||
|
ffmpeg->setUrl(url);
|
||
|
}
|
||
|
|
||
|
void ffmpegvideoDlg::play()
|
||
|
{
|
||
|
if(!m_PlayStatus)
|
||
|
{
|
||
7 months ago
|
m_PlayStatus = true;
|
||
|
ffmpeg = new Cffmpeg_decode;
|
||
|
ffmpeg->IsstopPlay = false;
|
||
|
ffmpeg->moveToThread(&workerThread);
|
||
|
connect(&workerThread,&QThread::finished,ffmpeg,&QObject::deleteLater); //线程发送结束标志
|
||
|
connect(this, &ffmpegvideoDlg::operate, ffmpeg, &Cffmpeg_decode::run); //线程开始处理数据
|
||
|
connect(ffmpeg,SIGNAL(sendQImage(QImage)),this,SLOT(receiveQImage(QImage))); //发送解析的图片
|
||
|
connect(ffmpeg,SIGNAL(sendConnectFail(int)),this,SLOT(showMessagBox(int))); //发送错误信息提示
|
||
|
workerThread.start();
|
||
|
emit this->operate(); //启用线程信号
|
||
8 months ago
|
}
|
||
|
}
|
||
|
void ffmpegvideoDlg::stop()
|
||
|
{
|
||
7 months ago
|
if(m_PlayStatus)
|
||
|
{
|
||
|
m_PlayStatus = false;
|
||
|
ffmpeg->IsstopPlay = true; //线程结束标志
|
||
|
workerThread.quit(); //线程退出时自动delete线程里的类
|
||
|
workerThread.wait();
|
||
|
img.fill(Qt::black);
|
||
8 months ago
|
}
|
||
|
}
|
||
|
|
||
7 months ago
|
//绘图事件
|
||
8 months ago
|
void ffmpegvideoDlg::paintEvent(QPaintEvent *)
|
||
|
{
|
||
|
QPainter painter(this);
|
||
7 months ago
|
painter.drawImage(m_ax,m_ay,img);
|
||
|
}
|
||
|
|
||
|
//区域大小改变事件
|
||
|
void ffmpegvideoDlg::resizeEvent(QResizeEvent *event)
|
||
|
{
|
||
|
//区域1920*1080自适应
|
||
|
double VideoAreaHeight = this->height();
|
||
|
double VideoAreaWidth = this->width();
|
||
|
//高度值相对比较大
|
||
|
if(VideoAreaHeight*16>VideoAreaWidth*9)
|
||
|
{
|
||
|
m_setVideoAreaWidth = VideoAreaWidth;
|
||
|
m_setVideoAreaHeight = VideoAreaWidth*9/16;
|
||
|
m_ax = 0;
|
||
|
m_ay = 0.5*(VideoAreaHeight-m_setVideoAreaHeight);
|
||
|
}
|
||
|
//宽度值相对比较大
|
||
|
else
|
||
|
{
|
||
|
m_setVideoAreaHeight = VideoAreaHeight;
|
||
|
m_setVideoAreaWidth = VideoAreaHeight*16/9;
|
||
|
m_ax = 0.5*(VideoAreaWidth-m_setVideoAreaWidth);
|
||
|
m_ay = 0;
|
||
|
}
|
||
8 months ago
|
}
|
||
|
|
||
|
void ffmpegvideoDlg::receiveQImage(const QImage &rImg)
|
||
|
{
|
||
7 months ago
|
|
||
|
//img = rImg.scaled(this->size());
|
||
|
QSize imgsize(m_setVideoAreaWidth,m_setVideoAreaHeight);
|
||
|
img = rImg.scaled(imgsize);
|
||
8 months ago
|
update();
|
||
|
}
|
||
7 months ago
|
//显示不同提示消息
|
||
|
void ffmpegvideoDlg::showMessagBox(int type)
|
||
|
{
|
||
|
switch (type) {
|
||
|
case 1:
|
||
|
QMessageBox::information(NULL,tr("提示"),"获取视频失败",QMessageBox::Ok);
|
||
|
break;
|
||
|
default:
|
||
|
break;
|
||
|
}
|
||
8 months ago
|
|
||
7 months ago
|
}
|
||
8 months ago
|
bool ffmpegvideoDlg::Isplay(bool IsstopPlay)
|
||
|
{
|
||
|
return ffmpeg->IsstopPlay = IsstopPlay;
|
||
|
}
|
||
7 months ago
|
|
||
|
|