QtAV编译及使用

QtAV编译及使用


参考地址:
https://github.com/wang-bin/QtAV/wiki/Build-QtAV

Prerequisites

  1. Get QtAV source code
git clone https://github.com/wang-bin/QtAV.git
cd QtAV && git submodule update --init
  1. FFmpeg>=1.0/Libav>=9.0. The latest release is recommended.
    You can download latest prebuilt FFmpeg, or build yourself.(下载对应版本的ffmpeg )

Setup the environment

  1. 推荐 使用 将对应版本的ffmpeg 拷贝一份到对应的qt安装路径里(放在对应的头文件 和链接文件)
    It’s the simplest and best way. Qt include and lib dir are always searched in QtAV. It should work for all platforms, including android, iOS, WinRT and meego etc.

Take Windows for example, Qt is installed in C:\Qt\5.7\msvc2015_64\ . Goto that dir and put ffmpeg headers to include, libs to lib\

  1. 将ffmpeg添加到源码文件夹下 设置.qmake.conf 文件配置
(Recommended) Edit .qmake.conf (if use qmake)
Extract ffmpeg to QtAV source dir. add 2 lines in .qmake.conf

INCLUDEPATH += $$PWD/ffmpeg/include
LIBS += -L$$PWD/ffmpeg/lib
  1. 编译即可 (推荐使用qtcreator 进行编译)

  2. 可能问题 (mingw 编译器路径设置不对)
    You may get qmake error libavutil is required, but compiler can not find it. That’s because mingw32-make.exe can not be found in the config test step. An workaround is put your mingw32-make.exe to one of %PATH% dirs

  3. 编译完成 点击对应生成目录生成的sdk_install.bat 实现将对应文件(头文件 和库文件)拷贝到qt安装目录里

qtav 使用(参考列子使用,主要有几点注意事项)

  1. 将qtav的lib和 bin文件 拷贝到项目目录下(最好将对应的ffmpeg bin文件也拷贝过去), 修改pro文件 例如:
greaterThan(QT_MAJOR_VERSION, 4) {
  QT += avwidgets
  QT += widgets
} else {
  CONFIG += avwidgets
}
CONFIG += c++11
LIBS += -L$$PWD/"3rdparty/qtav/lib" -llibQtAV1 -llibQtAVWidgets1

  1. 运行时 将对应的 qtav bin 文件依赖和 ffmpeg bin 拷贝到对应运行目录下
    使用windeployqt查找依赖库, 点击exe 运行 (将其他缺少的库拷贝过来) 运行qtav编译后例子同理

qtav 部分参数 调整

  1. 播放实时流时 设置 连接方式为tcp 连接(默认使用udp 可能会 出现丢包,卡顿 ,出视频慢,无法穿透防火墙 不能播视频等)
  m_player = new AVPlayer(this);
  QHash dict;
    //    dict.insert("probesize", 5000000);
    //    dict.insert("analyzeduration", 5000000);
    //    dict.insert("avioflags", "direct");
    dict.insert("rtsp_transport", "tcp");
    m_player->setOptionsForFormat(dict);
  1. 硬解
QStringList  strList;
    strList <<"DXVA"<< "D3D11"<<"VAAPI"<< "CUDA" << "FFmpeg";
    m_player->setVideoDecoderPriority(strList);
  1. 0 拷贝
QApplication::setAttribute(Qt::AA_UseOpenGLES);  // 使用openGles

 QVariantHash dec_opt( m_player->optionsForVideoCodec());
 dec_opt["copyMode"] = "OptimizedCopy"; // or "GenericCopy"
    m_player->setOptionsForVideoCodec(dec_opt);
 VideoRenderer *vo = VideoRenderer::create(VideoRendererId_GLWidget2); // 参考player 例子

你可能感兴趣的:(qt,软件安装与使用)