QtAV的编译与使用(MSVC2015+Qt5.9.8)

0.前言

本文主要是记录QtAV的编译及使用过程,在MSVC2015-2019搭配Qt5.9-5.12这个版本范围内使用过,没有出现编译错误或编译出来的动态库无法使用的情况。

《门前》----顾城

... 草在结它的种子

风在摇它的叶子

我们站着,不说话

就十分美好 ...

本文目录

1.准备工作

2.编译

3.简单使用 

4.参考


1.准备工作

QtAV的源码

下载链接:https://github.com/wang-bin/QtAV

git clone https://github.com/wang-bin/QtAV.git
cd QtAV && git submodule update --init

FFmpeg库

(其实可以用作者编译好的,如果环境和版本符合要求的话,地址http://sourceforge.net/projects/qtav/files/depends

下载链接:https://ffmpeg.zeranoe.com/builds/

需要下载shared运行依赖库和dev开发依赖库,我下的4.1.3-windows32bit的,因为我编译器是msvc2015-32bit。把ffmpeg的库下下来后,解压,然后将库文件放到Qt的环境中去。

将xxx-dev\include下所有文件,拷贝到Qt环境的include下(如:D:\Qt\Qt5.9.8\5.9.8\msvc2015\include)。

将xxx-dev\lib下所有lib,拷贝到Qt环境的lib下(如:D:\Qt\Qt5.9.8\5.9.8\msvc2015\lib)。

 因为我要在Qt里调试,所以把xx-shared\bin下的文件也拷贝到Qt目录下(如:D:\Qt\Qt5.9.8\5.9.8\msvc2015\bin)。

2.编译

其实编译挺简单的,不过我试了好几次才成功的编译出能用的。

用QtCreator打开QtAV.pro工程文件,直接构建就行了。我先构建的debug版本(出了点小问题),然后又构建的release版本一切正常,我又再次构建debug版本,这次都是正常的了。(建议就用默认的影子构建,这样编译出来的东西好找一点)

编译完成后,库在xxx\lib_win_x86文件夹下(如:E:\git_space\build-QtAV-Desktop_Qt_5_9_8_MSVC2015_32bit-Debug\lib_win_x86),示例程序在xxx\bin文件夹下(如:E:\git_space\build-QtAV-Desktop_Qt_5_9_8_MSVC2015_32bit-Debug\bin),不过示例可能需要用windeployqt打一下包,也可能需要把提示缺的库文件拷贝过去。

库文件不用自己拷贝到环境中,点击目录下的sdk_install.bat脚本自动把文件放到对应的目录。(debug和release的我都点了,如果需要重新编译点sdk_uninstall.bat,免得冲突的话还要手动去删之前的文件)

3.简单使用 

参考QtAV\examples目录下的例子以及readme的说明构建简单的应用,源码文件夹下xxx\QtAV\doc\UseQtAVinYourProjects-zh_CN.md文档也可以参考。

(一开始我遇到QtAV文件不存在的错误,然后重新编译好几次才正常了,也不知道啥原因)

Widgets中的使用:

(摘自文档)自 QtAV 1.5 基于 QWidget 的渲染器被移到了新模块 QtAVWidgets, 若需要使用这些渲染器比如 OpenGLWidgetRenderer,在pro工程文件加入:

QT += avwidgets

C++ 代码中加入:

#include <QtAV>

#include <QtAVWidgets>

因为ui布局文件看起来不方便的原因所以我没把代码完整贴出来,可以参照simpleplayer例子,不过例子中的VideoOutput类型我用不了,会异常结束,我用的VideoRenderer。另外,main.cpp中的registerRenderers可以去掉,貌似没影响。

Qml中的使用:

//QML的话可以不用在pro中添加别的模块

//main.qml
import QtQuick 2.9
import QtQuick.Window 2.2
import QtQuick.Controls 2.2
import QtAV 1.7

Window {
    id:item_root
    visible: true
    width: 640
    height: 480
    title: qsTr("Hello World")
    color: "gray"

    VideoOutput2 {
        id: item_video
        source: item_player
        anchors.fill: parent
        anchors.bottomMargin: 30

        Slider{
            id:item_slider
            anchors.left: parent.left
            anchors.right: parent.right
            anchors.bottom: parent.bottom
            from:0
            value:0
            to:1
            onValueChanged: {
                if(item_slider.pressed)
                    item_player.seek(item_player.duration*value)
                //console.log(item_player.duration)
            }
        }
    }

    MediaPlayer{
        id:item_player
        //替换成自己的文件或者网络视频流
        source: "F:/test.mp4"
        onPaused: {
            console.log("----------paused")
        }
        onPlaying: {
            console.log("----------playing")
        }
        onStopped: {
            console.log("----------stopped")
        }
        onPositionChanged: {
            if(!item_slider.pressed)
                item_slider.value=position/duration
            console.log("----------buffer position",position)
        }
    }


    Row{
        anchors.left: parent.left
        anchors.bottom: parent.bottom
        anchors.margins: 2
        height: 30
        spacing: 2
        Button{
            anchors.verticalCenter: parent.verticalCenter
            width: 60
            height: 26
            text: "play"
            onClicked: {
                console.log("-------------play clicked")
                item_player.play()
            }
        }

        Button{
            anchors.verticalCenter: parent.verticalCenter
            width: 60
            height: 26
            text: "pause"
            onClicked: {
                console.log("-------------pause clicked")
                item_player.pause()
            }
        }
        Button{
            anchors.verticalCenter: parent.verticalCenter
            width: 60
            height: 26
            text: "stop"
            onClicked: {
                console.log("-------------stop clicked")
                item_player.stop()
                item_slider.value=0
            }
        }
    }
}

效果如下: 

到此,编译与基本的使用也就走完一遍了,剩下的就是摸索这个库,进行定制。 

(2019-11-27)今天用 QML 版本打包发布才发现,除了 qml文件夹 下的 QtAV ,还得把 QtAV1.dll 这个动态库一起发布,不然加载失败。

(2020-01-01)在 Win10 上生成的 QML 程序放到 Win7 上,释放组件时程序直接崩溃,并且视频暂停播放音调会停在那里一直响。

4.参考

作者文档:https://github.com/wang-bin/QtAV/wiki/Build-QtAV 

博客-编译:https://www.cnblogs.com/motadou/p/9310560.html

博客-编译使用:https://blog.csdn.net/wuchalilun/article/details/74981736

博客-编译使用:https://blog.csdn.net/mccoy39082/article/details/82818716

博客-编译安装:https://blog.csdn.net/qq_36372055/article/details/93380298

  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

龚建波

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值