ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

QtAV编译以及使用

2022-07-13 11:31:07  阅读:246  来源: 互联网

标签:Qt QtAV Desktop 编译 64 workspace 使用 qt


Qt视频播放器,自己按照网上的方法,成功试了一遍。

第一个链接是方法。第二个链接是 环境变量配置。

http://www.javashuo.com/article/p-hsuvjvjc-nr.html

前言

本文详细描述Window 10 和Ubuntu 14.04使用Qt Creator编译QtAV 1.12的步骤linux

1 Windows

1.1 依赖环境

第一种方法:
下载编译好的ffmpeg-3.4.2-win64-devffmpeg-3.4.2-win64-shared,解压获得git

D:\qt-workspace\ffmpeg-3.4.2-win64-dev
D:\qt-workspace\ffmpeg-3.4.2-win64-shared

第二种方法:
QtAV官方有提供编译好的依赖库 QtAV-depends-windows-x86%2Bx64.7z,解压获得github

D:\qt-workspace\QtAV-depends-windows-x86+x64

1.2 QtAV编译

下载QtAV-1.12.0,解压获得QtAV-1.12.0,在Qt Creator中导入QtAV项目
Qt Creator导入QtAV
而后在Qt Creator设置编译时候的环境变量,换成本身ffmpeg解压的路径web

变量
CPATH D:\qt-workspace\ffmpeg-3.4.2-win64-dev\include
LD_LIBRARY_PATH D:\qt-workspace\ffmpeg-3.4.2-win64-dev\lib
LIBRARY_PATH D:\qt-workspace\ffmpeg-3.4.2-win64-dev\lib

QtAv编译环境变量设置
若是使用的是QtAV提供编译好的依赖库的话,须要注意压缩包里提供了32位和64位的库,我要编译64位的,因此路径是…\lib\x64,若是要编译32位的,则路径是…/lib,变量值以下ubuntu

变量
CPATH D:\qt-workspace\QtAV-depends-windows-x86+x64\include
LD_LIBRARY_PATH D:\qt-workspace\QtAV-depends-windows-x86+x64\lib\x64
LIBRARY_PATH D:\qt-workspace\QtAV-depends-windows-x86+x64\lib\x64

编译的时候报错
error: avutil is required, but compiler can not find it
缘由可能没有安装好ffmpeg或者上述的环境变量设置的路径有误,或者ffmpeg版本不对windows

编译完成,点击Qt Creator侧边栏的小电脑图标,选择须要运行的程序
QtAV Demo选择
好比选择了player,再点击运行按钮,可能运行会报以下的错误ide

22:02:28: Starting D:\qt-workspace\build-QtAV-Desktop_Qt_5_12_3_MinGW_64_bit-Release\bin\Player.exe ...
22:02:29: 程序异常结束。
22:02:29: The process was ended forcefully.
22:02:29: D:/qt-workspace/build-QtAV-Desktop_Qt_5_12_3_MinGW_64_bit-Release/bin/Player.exe crashed.

在1.1小节解压获得的ffmpeg-3.4.2-win64-shared中,把bin目录下的动态连接库复制到QtAV的编译目录的bin目录下,好比个人目录是svg

D:\qt-workspace\ffmpeg-3.4.2-win64-shared\bin
D:\qt-workspace\build-QtAV-Desktop_Qt_5_12_3_MinGW_64_bit-Release\bin

须要复制的动态连接库是
ffmpeg-3.4.2-win64-shared dll
再次运行就不会有错误了
QtAV Demo player
若是使用的是QtAV提供编译好的依赖库的话,注意编译64位要…bin/x64目录下的,32位要…/bin目录下的,以下所示ui

D:\qt-workspace\QtAV-depends-windows-x86+x64\bin\x64
D:\qt-workspace\build-QtAV-Desktop_Qt_5_12_3_MinGW_64_bit-Release\bin

dll

1.3 QtAV安装

在QtAV编译目录下双击sdk_install.bat便可,好比个人目录是this

D:\qt-workspace\build-QtAV-Desktop_Qt_5_12_3_MinGW_64_bit-Release

以后库文件和头文件等就会安装到Qt Sdk相关路径下,其余使用QtAV的应用就能够依赖上了

1.4 QtAV使用

新建一个Demo

#include<WidgetRenderer.h>
#include<QApplication>
#include<QtAV>
#include<QtAVWidgets>
#include<QtAV/AVPlayer.h>

using namespace QtAV;

intmain(int argc,char*argv[]){
    QApplication a(argc, argv);
    WidgetRenderer renderer;
    renderer.show();
    Widgets::registerRenderers();
    AVPlayer player;
    player.setRenderer(&renderer);
    player.play("test.mov");
    return a.exec();
}

在Demo的pro文件中加入

QT += av avwidgets
LIBS += -lQtAV1 -lQtAVWidgets1

若是Demo的pro文件没有添加LIBS += -lQtAV1 -lQtAVWidgets1,编译的时候可能会报错undefined reference to,注意是-lQtAV1 -lQtAVWidgets1,不是-lQtAV -lQtAVWidgets

g++ -Wl,-subsystem,console -mthreads -o debug\test.exe debug/main.o  -LF:\Qt5.12.3\5.12.3\mingw73_64\lib F:\Qt5.12.3\5.12.3\mingw73_64\lib\libQt5OpenGLd.a F:\Qt5.12.3\5.12.3\mingw73_64\lib\libQt5Widgetsd.a F:\Qt5.12.3\5.12.3\mingw73_64\lib\libQt5Guid.a F:\Qt5.12.3\5.12.3\mingw73_64\lib\libQt5Cored.a   
debug/main.o: In function `main':
D:\qt-workspace\build-test-Desktop_Qt_5_12_3_MinGW_64_bit-Debug/../test/main.cpp:12: undefined reference to `__imp__ZN4QtAV14WidgetRendererC1EP7QWidget6QFlagsIN2Qt10WindowTypeEE'
D:\qt-workspace\build-test-Desktop_Qt_5_12_3_MinGW_64_bit-Debug/../test/main.cpp:14: undefined reference to `__imp__ZN4QtAV7Widgets17registerRenderersEv'
D:\qt-workspace\build-test-Desktop_Qt_5_12_3_MinGW_64_bit-Debug/../test/main.cpp:15: undefined reference to `__imp__ZN4QtAV8AVPlayerC1EP7QObject'
D:\qt-workspace\build-test-Desktop_Qt_5_12_3_MinGW_64_bit-Debug/../test/main.cpp:16: undefined reference to `__imp__ZN4QtAV8AVPlayer11setRendererEPNS_13VideoRendererE'
D:\qt-workspace\build-test-Desktop_Qt_5_12_3_MinGW_64_bit-Debug/../test/main.cpp:17: undefined reference to `__imp__ZN4QtAV8AVPlayer4playERK7QString'
D:\qt-workspace\build-test-Desktop_Qt_5_12_3_MinGW_64_bit-Debug/../test/main.cpp:15: undefined reference to `__imp__ZN4QtAV8AVPlayerD1Ev'
D:\qt-workspace\build-test-Desktop_Qt_5_12_3_MinGW_64_bit-Debug/../test/main.cpp:15: undefined reference to `__imp__ZN4QtAV8AVPlayerD1Ev'
debug/main.o: In function `QtAV::QPainterRenderer::~QPainterRenderer()':
F:/Qt5.12.3/5.12.3/mingw73_64/include/QtAV/QPainterRenderer.h:31: undefined reference to `__imp__ZTVN4QtAV16QPainterRendererE'
F:/Qt5.12.3/5.12.3/mingw73_64/include/QtAV/QPainterRenderer.h:31: undefined reference to `__imp__ZN4QtAV13VideoRendererD2Ev'
debug/main.o: In function `QtAV::WidgetRenderer::~WidgetRenderer()':
F:/Qt5.12.3/5.12.3/mingw73_64/include/QtAVWidgets/WidgetRenderer.h:35: undefined reference to `__imp__ZTVN4QtAV14WidgetRendererE'
F:/Qt5.12.3/5.12.3/mingw73_64/include/QtAVWidgets/WidgetRenderer.h:35: undefined reference to `__imp__ZTVN4QtAV14WidgetRendererE'
F:/Qt5.12.3/5.12.3/mingw73_64/include/QtAVWidgets/WidgetRenderer.h:35: undefined reference to `__imp__ZTVN4QtAV14WidgetRendererE'
collect2.exe: error: ld returned 1 exit status
mingw32-make[1]: *** [Makefile.Debug:65: debug/test.exe] Error 1
mingw32-make: *** [Makefile:38: debug] Error 2
mingw32-make[1]: Leaving directory 'D:/qt-workspace/build-test-Desktop_Qt_5_12_3_MinGW_64_bit-Debug'
23:18:26: 进程"F:\Qt5.12.3\Tools\mingw730_64\bin\mingw32-make.exe"退出,退出代码 2 。
Error while building/deploying project test (kit: Desktop Qt 5.12.3 MinGW 64-bit)
When executing step "Make"

编译完成以后,把ffmpeg的动态库复制到应用的目录下,参照1.2小节运行Demo的作法
若是运行的时候报错QWidget: Must construct a QApplication before a QWidget

23:47:18: Starting D:\qt-workspace\build-test1-Desktop_Qt_5_12_3_MinGW_64_bit-Debug\debug\test1.exe ...
QWidget: Must construct a QApplication before a QWidget
23:47:24: 程序异常结束。
23:47:24: The process was ended forcefully.
23:47:24: D:/qt-workspace/build-test1-Desktop_Qt_5_12_3_MinGW_64_bit-Debug/debug/test1.exe crashed.

多是应用编译成debug版本的了,QtAV库是release版本的,把应用编译成release版本便可

2 Ubuntu

2.1 依赖环境

安装如下包,其中libopenal和libpulse是两个音频输出库

sudo apt-get install libglu1-mesa-dev freeglut3-dev mesa-common-dev
sudo apt-get install libavutil-dev libavcodec-dev libavformat-dev libswscale-dev

sudo apt-get install libopenal-dev libpulse-dev libva-dev libxv-dev libass-dev libegl1-mesa-dev

而后下载ffmpeg3.4.6,解压获得ffmpeg-3.4.6,在解压目录里执行

./configure --enable-shared --disable-x86asm --prefix=/youpath/ffmpeg-3.4.6/install

2.2 QtAV编译

下载QtAV-1.12.0,解压获得QtAV-1.12.0,在Qt Creator中导入QtAV项目
Qt Creator导入QtAV
须要注意的是在qmake以前,必须安装libopenal等库,否则会没有声音输出
而后在Qt Creator设置编译时候的环境变量

变量
CPATH /youpath/ffmpeg-3.4.6/install/include
LD_LIBRARY_PATH /opt/Qt5.12.3/Tools/QtCreator/lib/Qt/lib:/youpath/ffmpeg-3.4.6/install/lib
LIBRARY_PATH /youpath/ffmpeg-3.4.6/install/lib

LD_LIBRARY_PATH这个环境变量可能原本就有,那么在原来的值后面追加ffmpeg lib安装路径便可
QtAv编译环境变量设置
编译的时候报错
error: avutil is required, but compiler can not find it
缘由可能没有安装好ffmpeg或者上述的环境变量设置的路径有误,或者ffmpeg版本不对

编译完成,点击Qt Creator侧边栏的小电脑图标,选择须要运行的程序
QtAV Demo选择
好比选择了player,再点击运行按钮,就能够看到Demo程序了
QtAV Demo player

2.3 QtAV安装

进入QtAV的编译目录,好比个人是

/home/anruliu/Desktop/workspace/sourcecode/qt/build-QtAV-Desktop_Qt_5_12_3_GCC_64bit-Debug

里面有个sdk_install.sh文件,执行

chmod +x sdk_install.sh
sudo ./sdk_install.sh

以后库文件和头文件等就会安装到Qt Sdk相关路径下,其余使用QtAV的应用就能够依赖上了

2.4 QtAV使用

新建一个Demo

#include<WidgetRenderer.h>
#include<QApplication>
#include<QtAV>
#include<QtAVWidgets>
#include<QtAV/AVPlayer.h>

using namespace QtAV;

intmain(int argc,char*argv[]){
    QApplication a(argc, argv);
    WidgetRenderer renderer;
    renderer.show();
    Widgets::registerRenderers();
    AVPlayer player;
    player.setRenderer(&renderer);
    player.play("test.mov");
    return a.exec();
}

在Demo的pro文件中加入

QT += av avwidgets
LIBS += -lQtAV -lQtAVWidgets

再按照2.2小节的步骤添加CPATH、LD_LIBRARY_PATH、LIBRARY_PATH等环境变量,编译运行便可
QtAV Demo
若是Demo的pro文件没有添加LIBS += -lQtAV -lQtAVWidgets,编译的时候可能会报错undefined reference to

g++ -c -pipe -g -std=gnu++11 -Wall -W -D_REENTRANT -fPIC -DQT_DEPRECATED_WARNINGS -DQT_QML_DEBUG -DQT_AVWIDGETS_LIB -DQT_AV_LIB -DQT_OPENGL_LIB -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I../xxx -I. -I/opt/Qt5.12.3/5.12.3/gcc_64/include -I/opt/Qt5.12.3/5.12.3/gcc_64/include/QtAVWidgets -I/opt/Qt5.12.3/5.12.3/gcc_64/include/QtAV -I/opt/Qt5.12.3/5.12.3/gcc_64/include/QtOpenGL -I/opt/Qt5.12.3/5.12.3/gcc_64/include/QtWidgets -I/opt/Qt5.12.3/5.12.3/gcc_64/include/QtGui -I/opt/Qt5.12.3/5.12.3/gcc_64/include/QtCore -I. -isystem /usr/include/libdrm -I/opt/Qt5.12.3/5.12.3/gcc_64/mkspecs/linux-g++ -o main.o ../xxx/main.cpp
g++ -Wl,-rpath,/opt/Qt5.12.3/5.12.3/gcc_64/lib -o xxx main.o   -L/opt/Qt5.12.3/5.12.3/gcc_64/lib -lQt5OpenGL -lQt5Widgets -lQt5Gui -lQt5Core -lGL -lpthread   
main.o: In function `main':
/home/anruliu/Desktop/workspace/sourcecode/qt/build-xxx-Desktop_Qt_5_12_3_GCC_64bit-Debug/../xxx/main.cpp:12: undefined reference to `QtAV::WidgetRenderer::WidgetRenderer(QWidget*, QFlags<Qt::WindowType>)'
/home/anruliu/Desktop/workspace/sourcecode/qt/build-xxx-Desktop_Qt_5_12_3_GCC_64bit-Debug/../xxx/main.cpp:14: undefined reference to `QtAV::Widgets::registerRenderers()'
/home/anruliu/Desktop/workspace/sourcecode/qt/build-xxx-Desktop_Qt_5_12_3_GCC_64bit-Debug/../xxx/main.cpp:15: undefined reference to `QtAV::AVPlayer::AVPlayer(QObject*)'
/home/anruliu/Desktop/workspace/sourcecode/qt/build-xxx-Desktop_Qt_5_12_3_GCC_64bit-Debug/../xxx/main.cpp:16: undefined reference to `QtAV::AVPlayer::setRenderer(QtAV::VideoRenderer*)'
/home/anruliu/Desktop/workspace/sourcecode/qt/build-xxx-Desktop_Qt_5_12_3_GCC_64bit-Debug/../xxx/main.cpp:17: undefined reference to `QtAV::AVPlayer::play(QString const&)'
/home/anruliu/Desktop/workspace/sourcecode/qt/build-xxx-Desktop_Qt_5_12_3_GCC_64bit-Debug/../xxx/main.cpp:15: undefined reference to `QtAV::AVPlayer::~AVPlayer()'
/home/anruliu/Desktop/workspace/sourcecode/qt/build-xxx-Desktop_Qt_5_12_3_GCC_64bit-Debug/../xxx/main.cpp:15: undefined reference to `QtAV::AVPlayer::~AVPlayer()'
main.o: In function `QtAV::QPainterRenderer::~QPainterRenderer()':
/opt/Qt5.12.3/5.12.3/gcc_64/include/QtAV/QPainterRenderer.h:31: undefined reference to `vtable for QtAV::QPainterRenderer'
/opt/Qt5.12.3/5.12.3/gcc_64/include/QtAV/QPainterRenderer.h:31: undefined reference to `QtAV::VideoRenderer::~VideoRenderer()'
main.o: In function `QtAV::WidgetRenderer::~WidgetRenderer()':
/opt/Qt5.12.3/5.12.3/gcc_64/include/QtAVWidgets/WidgetRenderer.h:35: undefined reference to `vtable for QtAV::WidgetRenderer'
/opt/Qt5.12.3/5.12.3/gcc_64/include/QtAVWidgets/WidgetRenderer.h:35: undefined reference to `vtable for QtAV::WidgetRenderer'
/opt/Qt5.12.3/5.12.3/gcc_64/include/QtAVWidgets/WidgetRenderer.h:35: undefined reference to `vtable for QtAV::WidgetRenderer'
collect2: error: ld returned 1 exit status
make: *** [xxx] Error 1
20:05:29: 进程"/usr/bin/make"退出,退出代码 2 。
Error while building/deploying project xxx (kit: Desktop Qt 5.12.3 GCC 64bit)
The kit Desktop Qt 5.12.3 GCC 64bit has configuration issues which might be the root cause for this problem.
When executing step "Make"

参考文献

[1] Qt第三方库QtAV— ubuntu编译与运行
[2] QtAV官方文档

 

QtCreator配置环境变量

https://blog.csdn.net/nicai_xiaoqinxi/article/details/88419217

使用QtCreator编译程序往往会出现一些编译的问题(库路径或头文件路径找不到),QtCreator可以配置环境变量以解决一些上述的问题。

 

1. 进入Projects(项目)

 

 

2. 点击Details(详情)

 

 

3. 如有需要可以清除系统环境变量

 

   4. 找到INCLUDE与LIB进行设置

 

 

5.如需要修改或添加其他变量在右侧按钮设置即可

————————————————

版权声明:本文为CSDN博主「Qt君」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。

原文链接:https://blog.csdn.net/nicai_xiaoqinxi/article/details/88419217

 

 

前言

本文详细描述Window 10 和Ubuntu 14.04使用Qt Creator编译QtAV 1.12的步骤linux

1 Windows

1.1 依赖环境

第一种方法:
下载编译好的ffmpeg-3.4.2-win64-devffmpeg-3.4.2-win64-shared,解压获得git

D:\qt-workspace\ffmpeg-3.4.2-win64-dev
D:\qt-workspace\ffmpeg-3.4.2-win64-shared

第二种方法:
QtAV官方有提供编译好的依赖库 QtAV-depends-windows-x86%2Bx64.7z,解压获得github

D:\qt-workspace\QtAV-depends-windows-x86+x64

1.2 QtAV编译

下载QtAV-1.12.0,解压获得QtAV-1.12.0,在Qt Creator中导入QtAV项目
Qt Creator导入QtAV
而后在Qt Creator设置编译时候的环境变量,换成本身ffmpeg解压的路径web

变量
CPATH D:\qt-workspace\ffmpeg-3.4.2-win64-dev\include
LD_LIBRARY_PATH D:\qt-workspace\ffmpeg-3.4.2-win64-dev\lib
LIBRARY_PATH D:\qt-workspace\ffmpeg-3.4.2-win64-dev\lib

QtAv编译环境变量设置
若是使用的是QtAV提供编译好的依赖库的话,须要注意压缩包里提供了32位和64位的库,我要编译64位的,因此路径是…\lib\x64,若是要编译32位的,则路径是…/lib,变量值以下ubuntu

变量
CPATH D:\qt-workspace\QtAV-depends-windows-x86+x64\include
LD_LIBRARY_PATH D:\qt-workspace\QtAV-depends-windows-x86+x64\lib\x64
LIBRARY_PATH D:\qt-workspace\QtAV-depends-windows-x86+x64\lib\x64

编译的时候报错
error: avutil is required, but compiler can not find it
缘由可能没有安装好ffmpeg或者上述的环境变量设置的路径有误,或者ffmpeg版本不对windows

编译完成,点击Qt Creator侧边栏的小电脑图标,选择须要运行的程序
QtAV Demo选择
好比选择了player,再点击运行按钮,可能运行会报以下的错误ide

22:02:28: Starting D:\qt-workspace\build-QtAV-Desktop_Qt_5_12_3_MinGW_64_bit-Release\bin\Player.exe ...
22:02:29: 程序异常结束。
22:02:29: The process was ended forcefully.
22:02:29: D:/qt-workspace/build-QtAV-Desktop_Qt_5_12_3_MinGW_64_bit-Release/bin/Player.exe crashed.

在1.1小节解压获得的ffmpeg-3.4.2-win64-shared中,把bin目录下的动态连接库复制到QtAV的编译目录的bin目录下,好比个人目录是svg

D:\qt-workspace\ffmpeg-3.4.2-win64-shared\bin
D:\qt-workspace\build-QtAV-Desktop_Qt_5_12_3_MinGW_64_bit-Release\bin

须要复制的动态连接库是
ffmpeg-3.4.2-win64-shared dll
再次运行就不会有错误了
QtAV Demo player
若是使用的是QtAV提供编译好的依赖库的话,注意编译64位要…bin/x64目录下的,32位要…/bin目录下的,以下所示ui

D:\qt-workspace\QtAV-depends-windows-x86+x64\bin\x64
D:\qt-workspace\build-QtAV-Desktop_Qt_5_12_3_MinGW_64_bit-Release\bin

dll

1.3 QtAV安装

在QtAV编译目录下双击sdk_install.bat便可,好比个人目录是this

D:\qt-workspace\build-QtAV-Desktop_Qt_5_12_3_MinGW_64_bit-Release

以后库文件和头文件等就会安装到Qt Sdk相关路径下,其余使用QtAV的应用就能够依赖上了

1.4 QtAV使用

新建一个Demo

#include<WidgetRenderer.h>
#include<QApplication>
#include<QtAV>
#include<QtAVWidgets>
#include<QtAV/AVPlayer.h>

using namespace QtAV;

intmain(int argc,char*argv[]){
    QApplication a(argc, argv);
    WidgetRenderer renderer;
    renderer.show();
    Widgets::registerRenderers();
    AVPlayer player;
    player.setRenderer(&renderer);
    player.play("test.mov");
    return a.exec();
}

在Demo的pro文件中加入

QT += av avwidgets
LIBS += -lQtAV1 -lQtAVWidgets1

若是Demo的pro文件没有添加LIBS += -lQtAV1 -lQtAVWidgets1,编译的时候可能会报错undefined reference to,注意是-lQtAV1 -lQtAVWidgets1,不是-lQtAV -lQtAVWidgets

g++ -Wl,-subsystem,console -mthreads -o debug\test.exe debug/main.o  -LF:\Qt5.12.3\5.12.3\mingw73_64\lib F:\Qt5.12.3\5.12.3\mingw73_64\lib\libQt5OpenGLd.a F:\Qt5.12.3\5.12.3\mingw73_64\lib\libQt5Widgetsd.a F:\Qt5.12.3\5.12.3\mingw73_64\lib\libQt5Guid.a F:\Qt5.12.3\5.12.3\mingw73_64\lib\libQt5Cored.a   
debug/main.o: In function `main':
D:\qt-workspace\build-test-Desktop_Qt_5_12_3_MinGW_64_bit-Debug/../test/main.cpp:12: undefined reference to `__imp__ZN4QtAV14WidgetRendererC1EP7QWidget6QFlagsIN2Qt10WindowTypeEE'
D:\qt-workspace\build-test-Desktop_Qt_5_12_3_MinGW_64_bit-Debug/../test/main.cpp:14: undefined reference to `__imp__ZN4QtAV7Widgets17registerRenderersEv'
D:\qt-workspace\build-test-Desktop_Qt_5_12_3_MinGW_64_bit-Debug/../test/main.cpp:15: undefined reference to `__imp__ZN4QtAV8AVPlayerC1EP7QObject'
D:\qt-workspace\build-test-Desktop_Qt_5_12_3_MinGW_64_bit-Debug/../test/main.cpp:16: undefined reference to `__imp__ZN4QtAV8AVPlayer11setRendererEPNS_13VideoRendererE'
D:\qt-workspace\build-test-Desktop_Qt_5_12_3_MinGW_64_bit-Debug/../test/main.cpp:17: undefined reference to `__imp__ZN4QtAV8AVPlayer4playERK7QString'
D:\qt-workspace\build-test-Desktop_Qt_5_12_3_MinGW_64_bit-Debug/../test/main.cpp:15: undefined reference to `__imp__ZN4QtAV8AVPlayerD1Ev'
D:\qt-workspace\build-test-Desktop_Qt_5_12_3_MinGW_64_bit-Debug/../test/main.cpp:15: undefined reference to `__imp__ZN4QtAV8AVPlayerD1Ev'
debug/main.o: In function `QtAV::QPainterRenderer::~QPainterRenderer()':
F:/Qt5.12.3/5.12.3/mingw73_64/include/QtAV/QPainterRenderer.h:31: undefined reference to `__imp__ZTVN4QtAV16QPainterRendererE'
F:/Qt5.12.3/5.12.3/mingw73_64/include/QtAV/QPainterRenderer.h:31: undefined reference to `__imp__ZN4QtAV13VideoRendererD2Ev'
debug/main.o: In function `QtAV::WidgetRenderer::~WidgetRenderer()':
F:/Qt5.12.3/5.12.3/mingw73_64/include/QtAVWidgets/WidgetRenderer.h:35: undefined reference to `__imp__ZTVN4QtAV14WidgetRendererE'
F:/Qt5.12.3/5.12.3/mingw73_64/include/QtAVWidgets/WidgetRenderer.h:35: undefined reference to `__imp__ZTVN4QtAV14WidgetRendererE'
F:/Qt5.12.3/5.12.3/mingw73_64/include/QtAVWidgets/WidgetRenderer.h:35: undefined reference to `__imp__ZTVN4QtAV14WidgetRendererE'
collect2.exe: error: ld returned 1 exit status
mingw32-make[1]: *** [Makefile.Debug:65: debug/test.exe] Error 1
mingw32-make: *** [Makefile:38: debug] Error 2
mingw32-make[1]: Leaving directory 'D:/qt-workspace/build-test-Desktop_Qt_5_12_3_MinGW_64_bit-Debug'
23:18:26: 进程"F:\Qt5.12.3\Tools\mingw730_64\bin\mingw32-make.exe"退出,退出代码 2 。
Error while building/deploying project test (kit: Desktop Qt 5.12.3 MinGW 64-bit)
When executing step "Make"

编译完成以后,把ffmpeg的动态库复制到应用的目录下,参照1.2小节运行Demo的作法
若是运行的时候报错QWidget: Must construct a QApplication before a QWidget

23:47:18: Starting D:\qt-workspace\build-test1-Desktop_Qt_5_12_3_MinGW_64_bit-Debug\debug\test1.exe ...
QWidget: Must construct a QApplication before a QWidget
23:47:24: 程序异常结束。
23:47:24: The process was ended forcefully.
23:47:24: D:/qt-workspace/build-test1-Desktop_Qt_5_12_3_MinGW_64_bit-Debug/debug/test1.exe crashed.

多是应用编译成debug版本的了,QtAV库是release版本的,把应用编译成release版本便可

2 Ubuntu

2.1 依赖环境

安装如下包,其中libopenal和libpulse是两个音频输出库

sudo apt-get install libglu1-mesa-dev freeglut3-dev mesa-common-dev
sudo apt-get install libavutil-dev libavcodec-dev libavformat-dev libswscale-dev

sudo apt-get install libopenal-dev libpulse-dev libva-dev libxv-dev libass-dev libegl1-mesa-dev

而后下载ffmpeg3.4.6,解压获得ffmpeg-3.4.6,在解压目录里执行

./configure --enable-shared --disable-x86asm --prefix=/youpath/ffmpeg-3.4.6/install

2.2 QtAV编译

下载QtAV-1.12.0,解压获得QtAV-1.12.0,在Qt Creator中导入QtAV项目
Qt Creator导入QtAV
须要注意的是在qmake以前,必须安装libopenal等库,否则会没有声音输出
而后在Qt Creator设置编译时候的环境变量

变量
CPATH /youpath/ffmpeg-3.4.6/install/include
LD_LIBRARY_PATH /opt/Qt5.12.3/Tools/QtCreator/lib/Qt/lib:/youpath/ffmpeg-3.4.6/install/lib
LIBRARY_PATH /youpath/ffmpeg-3.4.6/install/lib

LD_LIBRARY_PATH这个环境变量可能原本就有,那么在原来的值后面追加ffmpeg lib安装路径便可
QtAv编译环境变量设置
编译的时候报错
error: avutil is required, but compiler can not find it
缘由可能没有安装好ffmpeg或者上述的环境变量设置的路径有误,或者ffmpeg版本不对

编译完成,点击Qt Creator侧边栏的小电脑图标,选择须要运行的程序
QtAV Demo选择
好比选择了player,再点击运行按钮,就能够看到Demo程序了
QtAV Demo player

2.3 QtAV安装

进入QtAV的编译目录,好比个人是

/home/anruliu/Desktop/workspace/sourcecode/qt/build-QtAV-Desktop_Qt_5_12_3_GCC_64bit-Debug

里面有个sdk_install.sh文件,执行

chmod +x sdk_install.sh
sudo ./sdk_install.sh

以后库文件和头文件等就会安装到Qt Sdk相关路径下,其余使用QtAV的应用就能够依赖上了

2.4 QtAV使用

新建一个Demo

#include<WidgetRenderer.h>
#include<QApplication>
#include<QtAV>
#include<QtAVWidgets>
#include<QtAV/AVPlayer.h>

using namespace QtAV;

intmain(int argc,char*argv[]){
    QApplication a(argc, argv);
    WidgetRenderer renderer;
    renderer.show();
    Widgets::registerRenderers();
    AVPlayer player;
    player.setRenderer(&renderer);
    player.play("test.mov");
    return a.exec();
}

在Demo的pro文件中加入

QT += av avwidgets
LIBS += -lQtAV -lQtAVWidgets

再按照2.2小节的步骤添加CPATH、LD_LIBRARY_PATH、LIBRARY_PATH等环境变量,编译运行便可
QtAV Demo
若是Demo的pro文件没有添加LIBS += -lQtAV -lQtAVWidgets,编译的时候可能会报错undefined reference to

g++ -c -pipe -g -std=gnu++11 -Wall -W -D_REENTRANT -fPIC -DQT_DEPRECATED_WARNINGS -DQT_QML_DEBUG -DQT_AVWIDGETS_LIB -DQT_AV_LIB -DQT_OPENGL_LIB -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I../xxx -I. -I/opt/Qt5.12.3/5.12.3/gcc_64/include -I/opt/Qt5.12.3/5.12.3/gcc_64/include/QtAVWidgets -I/opt/Qt5.12.3/5.12.3/gcc_64/include/QtAV -I/opt/Qt5.12.3/5.12.3/gcc_64/include/QtOpenGL -I/opt/Qt5.12.3/5.12.3/gcc_64/include/QtWidgets -I/opt/Qt5.12.3/5.12.3/gcc_64/include/QtGui -I/opt/Qt5.12.3/5.12.3/gcc_64/include/QtCore -I. -isystem /usr/include/libdrm -I/opt/Qt5.12.3/5.12.3/gcc_64/mkspecs/linux-g++ -o main.o ../xxx/main.cpp
g++ -Wl,-rpath,/opt/Qt5.12.3/5.12.3/gcc_64/lib -o xxx main.o   -L/opt/Qt5.12.3/5.12.3/gcc_64/lib -lQt5OpenGL -lQt5Widgets -lQt5Gui -lQt5Core -lGL -lpthread   
main.o: In function `main':
/home/anruliu/Desktop/workspace/sourcecode/qt/build-xxx-Desktop_Qt_5_12_3_GCC_64bit-Debug/../xxx/main.cpp:12: undefined reference to `QtAV::WidgetRenderer::WidgetRenderer(QWidget*, QFlags<Qt::WindowType>)'
/home/anruliu/Desktop/workspace/sourcecode/qt/build-xxx-Desktop_Qt_5_12_3_GCC_64bit-Debug/../xxx/main.cpp:14: undefined reference to `QtAV::Widgets::registerRenderers()'
/home/anruliu/Desktop/workspace/sourcecode/qt/build-xxx-Desktop_Qt_5_12_3_GCC_64bit-Debug/../xxx/main.cpp:15: undefined reference to `QtAV::AVPlayer::AVPlayer(QObject*)'
/home/anruliu/Desktop/workspace/sourcecode/qt/build-xxx-Desktop_Qt_5_12_3_GCC_64bit-Debug/../xxx/main.cpp:16: undefined reference to `QtAV::AVPlayer::setRenderer(QtAV::VideoRenderer*)'
/home/anruliu/Desktop/workspace/sourcecode/qt/build-xxx-Desktop_Qt_5_12_3_GCC_64bit-Debug/../xxx/main.cpp:17: undefined reference to `QtAV::AVPlayer::play(QString const&)'
/home/anruliu/Desktop/workspace/sourcecode/qt/build-xxx-Desktop_Qt_5_12_3_GCC_64bit-Debug/../xxx/main.cpp:15: undefined reference to `QtAV::AVPlayer::~AVPlayer()'
/home/anruliu/Desktop/workspace/sourcecode/qt/build-xxx-Desktop_Qt_5_12_3_GCC_64bit-Debug/../xxx/main.cpp:15: undefined reference to `QtAV::AVPlayer::~AVPlayer()'
main.o: In function `QtAV::QPainterRenderer::~QPainterRenderer()':
/opt/Qt5.12.3/5.12.3/gcc_64/include/QtAV/QPainterRenderer.h:31: undefined reference to `vtable for QtAV::QPainterRenderer'
/opt/Qt5.12.3/5.12.3/gcc_64/include/QtAV/QPainterRenderer.h:31: undefined reference to `QtAV::VideoRenderer::~VideoRenderer()'
main.o: In function `QtAV::WidgetRenderer::~WidgetRenderer()':
/opt/Qt5.12.3/5.12.3/gcc_64/include/QtAVWidgets/WidgetRenderer.h:35: undefined reference to `vtable for QtAV::WidgetRenderer'
/opt/Qt5.12.3/5.12.3/gcc_64/include/QtAVWidgets/WidgetRenderer.h:35: undefined reference to `vtable for QtAV::WidgetRenderer'
/opt/Qt5.12.3/5.12.3/gcc_64/include/QtAVWidgets/WidgetRenderer.h:35: undefined reference to `vtable for QtAV::WidgetRenderer'
collect2: error: ld returned 1 exit status
make: *** [xxx] Error 1
20:05:29: 进程"/usr/bin/make"退出,退出代码 2 。
Error while building/deploying project xxx (kit: Desktop Qt 5.12.3 GCC 64bit)
The kit Desktop Qt 5.12.3 GCC 64bit has configuration issues which might be the root cause for this problem.
When executing step "Make"

参考文献

[1] Qt第三方库QtAV— ubuntu编译与运行
[2] QtAV官方文档

标签:Qt,QtAV,Desktop,编译,64,workspace,使用,qt
来源: https://www.cnblogs.com/warmlight/p/16473246.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有