本文章主要是使用MSVC编译器,因为QtAV是依赖FFmpeg的,所以需要下载QtAV源码和QtAV-depends-windows-x86+x64;
官网地址:http://www.qtav.org/
Github 地址:https://github.com/wang-bin/QtAV
1,解压
将文件解压到同一个文件夹下:

2,修改.qmake.conf配置文件

INCLUDEPATH += $$PWD/../QtAV-depends-windows-x86+x64/include
LIBS += -L$$PWD/../QtAV-depends-windows-x86+x64/lib/x64
3.打开项目


4、分别构建Debug和Release


5.分别双击执行Debug和Release下的sdk_install.bat文件,会将QtAV编译的库和头文件,模块等都拷贝到Qt内部模块种。


6、新建工程
添加三个环境变量,主要是配置FFmpeg库的路径设置 CPATH 到 H:\QtCode\CSOI\CSOI\VisualizationSafety\VisualizationAVCell\QtAV-depends-windows-x86+x64\include
设置 LD_LIBRARY_PATH 到 H:\QtCode\CSOI\CSOI\VisualizationSafety\VisualizationAVCell\QtAV-depends-windows-x86+x64\bin\x64
设置 LIBRARY_PATH 到 H:\QtCode\CSOI\CSOI\VisualizationSafety\VisualizationAVCell\QtAV-depends-windows-x86+x64\lib\x64

.pro 文件中添加模块

INCLUDEPATH += $$PWD/QTAV/include
INCLUDEPATH += $$PWD/QTAV/include/QtAV
INCLUDEPATH += $$PWD/QTAV/include/QtAV/5.9.7/QtAV/private
INCLUDEPATH += $$PWD/QTAV/include/QtAV/private
INCLUDEPATH += $$PWD/QTAV/include/QtAVWidgetswin32:CONFIG(release, debug|release): LIBS += -L$$PWD/QTAV/lib_win_x86_64/ -lcommon
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/QTAV/lib_win_x86_64/ -lcommondwin32:CONFIG(release, debug|release): LIBS += -L$$PWD/QTAV/lib_win_x86_64/ -lQmlAV
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/QTAV/lib_win_x86_64/ -lQmlAVdwin32:CONFIG(release, debug|release): LIBS += -L$$PWD/QTAV/lib_win_x86_64/ -lQtAV1
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/QTAV/lib_win_x86_64/ -lQtAVd1win32:CONFIG(release, debug|release): LIBS += -L$$PWD/QTAV/lib_win_x86_64/ -lQtAVWidgets1
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/QTAV/lib_win_x86_64/ -lQtAVWidgetsd1
.h
#include
#include
#include using namespace QtAV;class VisualizationAVCell : public QLabel
{Q_OBJECT
public:explicit VisualizationAVCell(QWidget *parent = nullptr);~VisualizationAVCell();signals:public slots:void slot_play();void slot_pause();void slot_stop();private:QtAV::VideoOutput *m_vo;QtAV::AVPlayer *m_player;
};
.cpp
#include
#include VisualizationAVCell::VisualizationAVCell(QWidget *parent) : QLabel(parent)
{QtAV::Widgets::registerRenderers();m_player = new QtAV::AVPlayer(this);m_vo = new QtAV::VideoOutput(this);if(nullptr == m_vo->widget())return;QGridLayout *grid = new QGridLayout;grid->addWidget(m_vo->widget());this->setLayout(grid);m_player->setRenderer(m_vo);
}VisualizationAVCell::~VisualizationAVCell()
{}void VisualizationAVCell::slot_play()
{m_player->play("H:/QtCode/CSOI/CSOI/testfile/av.mp4");
}void VisualizationAVCell::slot_pause()
{m_player->pause();
}void VisualizationAVCell::slot_stop()
{m_player->stop();
}