您现在的位置是:首页 > 技术教程 正文

Linux Qt5.15.2 编译QWebEngine源码支持音视频H264

admin 阅读: 2024-03-31
后台-插件-广告管理-内容页头部广告(手机)

背景

默认自带的QWebEngine 因版权问题不支持音视频功能,需要自己编译源码以支持。

平台:Linux(UOS V20 1050)
Qt:5.15.2

准备工作

  1. 下载 Qt 5.15.2 对应版本源码,使用镜像网站或者Qt Maintenance Tool工具下载。
  2. 配置 Qt 环境变量
vim ~/.bashrc
  • 1

将以下内容追加到bashrc文件后

#QT ENV export PATH=/home/Leou/Qt/5.15.2/gcc_64/bin:$PATH export LD_LIBRARY_PATH=/home/Leou/Qt/5.15.2/gcc_64/lib:$LD_LIBRARY_PATH export QT_PLUGIN_PATH=/home/Leou/Qt/5.15.2/gcc_64/plugins:$QT_PLUGIN_PATH export QML2_PATH=/home/Leou/Qt/5.15.2/gcc_64/qml:$QML2_PATH
  • 1
  • 2
  • 3
  • 4
  • 5

刷新使其生效

source ~/.bashrc
  • 1

这个阶段可以预先安装所需的库:

On all platforms, the following tools are required at build time:

  • Python 2.7.5 or later. Python 3 is not supported.
  • Bison, Flex
  • GPerf
  • Node.js version 8 or later (version 12 or later is recommended)

这些是最基本的要求,实际上还有很多库需要安装,可参考qtwebengine-platform-notes

编译

创建build目录,并使用qmake ../qtwebengine.pro -- -webengine-proprietary-codecs命令

Leou@Leou-PC:/media/Leou/qtwebengine$ mkdir build Leou@Leou-PC:/media/Leou/qtwebengine$ cd build/ Leou@Leou-PC:/media/Leou/qtwebengine/build$ qmake ../qtwebengine.pro -- -webengine-proprietary-codecs
  • 1
  • 2
  • 3

输出信息:

Info: creating stash file /media/Leou/qtwebengine/build/.qmake.stash Info: creating cache file /media/Leou/qtwebengine/build/.qmake.cache Running configuration tests... Checking for architecture supported... yes Checking for bison... no Checking for submodule initialized... yes Checking for build path without whitespace... yes Checking for platform supported... Checking for gperf... yes Checking for flex... no Checking for host pkg-config... /usr/bin/pkg-config Checking for jumbo build merge limit... 8 Checking for linker supports -z noexecstack... yes Checking for x11... yes Checking for libdrm... yes Checking for xcomposite... yes Checking for xcursor... yes Checking for xi... yes Checking for xtst... yes Checking for python2... /usr/bin/python2 Checking for d-bus... yes Checking for fontconfig... yes Checking for freetype >= 2.4.2... yes Checking for glib-2.0 >= 2.32.0... yes Checking for glibc > 2.16... yes Checking for jsoncpp... no Checking for khr... yes Checking for lcms2... no Checking for libevent... no Checking for libvpx... no Checking for libwebp, libwebpmux and libwebpdemux... no Checking for compatible libxml2 and libxslt... no Checking for minizip... no Checking for system ninja... no Checking for nss >= 3.26... yes Checking for opus... no Checking for protobuf... no Checking for re2... no Checking for snappy... no Checking for zlib... yes Done running configuration tests. Configure summary: Qt WebEngine Build Tools: Use System Ninja ....................... no Use System Gn .......................... no Jumbo Build Merge Limit ................ 8 Developer build ........................ no Sanitizer .............................. no QtWebEngine required system libraries: fontconfig ........................... yes dbus ................................. yes nss .................................. yes khr .................................. yes glibc ................................ yes QtWebEngine required system libraries for qpa-xcb: x11 .................................. yes libdrm ............................... yes xcomposite ........................... yes xcursor .............................. yes xi ................................... yes xtst ................................. yes Optional system libraries used: re2 .................................. no icu .................................. no libwebp, libwebpmux and libwebpdemux . no opus ................................. no ffmpeg ............................... no libvpx ............................... no snappy ............................... no glib ................................. yes zlib ................................. yes minizip .............................. no libevent ............................. no jsoncpp .............................. no protobuf ............................. no libxml2 and libxslt .................. no lcms2 ................................ no png .................................. no JPEG ................................. no harfbuzz ............................. no freetype ............................. yes Note: The following modules are not being compiled in this configuration: webenginecore webengine webenginewidgets pdf pdfwidgets WARNING: Tool bison is required to build QtWebEngine. WARNING: Tool bison is required to build QtPdf. WARNING: QtWebEngine will not be built. WARNING: QtPdf will not be built. Qt is now configured for building. Just run 'make'. Once everything is built, you must run 'make install'. Qt will be installed into '/home/Leou/Qt/5.15.2/gcc_64'. Prior to reconfiguration, make sure you remove any leftovers from the previous build.
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107

查看输出信息并安装缺失的库:

安装bison

sudo apt install bison
  • 1

安装flex

sudo apt install flex
  • 1

安装后,疑似有缓存,所以导致未更新,可删除build下的产物,再运行一次qmake ../qtwebengine.pro -- -webengine-proprietary-codecs

输出信息:

Leou@Leou-PC:/media/Leou/QtSrc/Src/qtwebengine/build$ qmake ../qtwebengine.pro -- -webengine-proprietary-codecs Running configuration tests... Done running configuration tests. Configure summary: Qt WebEngine Build Tools: Use System Ninja ....................... no Use System Gn .......................... no Jumbo Build Merge Limit ................ 8 Developer build ........................ no Sanitizer .............................. no QtWebEngine required system libraries: fontconfig ........................... yes dbus ................................. yes nss .................................. yes khr .................................. yes glibc ................................ yes QtWebEngine required system libraries for qpa-xcb: x11 .................................. yes libdrm ............................... yes xcomposite ........................... yes xcursor .............................. yes xi ................................... yes xtst ................................. yes Optional system libraries used: re2 .................................. no icu .................................. no libwebp, libwebpmux and libwebpdemux . no opus ................................. no ffmpeg ............................... no libvpx ............................... no snappy ............................... no glib ................................. yes zlib ................................. yes minizip .............................. no libevent ............................. no jsoncpp .............................. no protobuf ............................. no libxml2 and libxslt .................. no lcms2 ................................ no png .................................. no JPEG ................................. no harfbuzz ............................. no freetype ............................. yes Qt WebEngineCore: Embedded build ......................... no Full debug information ................. no Pepper Plugins ......................... yes Printing and PDF ....................... yes Proprietary Codecs ..................... yes Spellchecker ........................... yes Native Spellchecker .................... no WebRTC ................................. yes PipeWire over GIO ...................... no Geolocation ............................ yes WebChannel support ..................... yes Kerberos Authentication ................ no Extensions ............................. yes Node.js ................................ no Support qpa-xcb ........................ yes Use ALSA ............................... yes Use PulseAudio ......................... yes Qt WebEngineQml: Support Qt WebEngine Qml ............... yes UI Delegates ........................... yes Test Support ........................... no Qt WebEngineWidgets: Support Qt WebEngine Widgets ........... yes Qt PDF: Support V8 ............................. no Support XFA ............................ no Support XFA-BMP ........................ no Support XFA-GIF ........................ no Support XFA-PNG ........................ no Support XFA-TIFF ....................... no Qt PDF Widgets: Support Qt PDF Widgets ................. yes WARNING: Building without node.js will disable some features of QtWebEngine DevTools. Qt is now configured for building. Just run 'make'. Once everything is built, you must run 'make install'. Qt will be installed into '/home/Leou/Qt/5.15.2/gcc_64'. Prior to reconfiguration, make sure you remove any leftovers from the previous build.
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88

执行make

make -j14
  • 1

如果出错,则多执行几次make命令
在这里插入图片描述

执行结束后:

mv -f libqwebengineview.so ../../../plugins/designer/libqwebengineview.so objcopy --only-keep-debug ../../../plugins/designer/libqwebengineview.so ../../../plugins/designer/libqwebengineview.so.debug && objcopy --strip-debug ../../../plugins/designer/libqwebengineview.so && objcopy --add-gnu-debuglink=../../../plugins/designer/libqwebengineview.so.debug ../../../plugins/designer/libqwebengineview.so && chmod -x ../../../plugins/designer/libqwebengineview.so.debug make[3]: 离开目录“/media/Leou/QtSrc/Src/qtwebengine/build/src/plugins/qwebengineview” make[2]: 离开目录“/media/Leou/QtSrc/Src/qtwebengine/build/src/plugins” rm -f libQt5PdfWidgets.so.5.15.2 libQt5PdfWidgets.so libQt5PdfWidgets.so.5 libQt5PdfWidgets.so.5.15 g++ -Wl,--no-undefined -Wl,--version-script,QtPdfWidgets.version -Wl,--enable-new-dtags -Wl,-z,origin -Wl,-rpath,\$ORIGIN -Wl,-rpath,\$ORIGIN -Wl,-rpath-link,/home/Leou/Qt/5.15.2/gcc_64/lib -shared -Wl,-Bsymbolic-functions -Wl,-soname,libQt5PdfWidgets.so.5 -o libQt5PdfWidgets.so.5.15.2 .obj/qpdfview.o -L/home/qt/openssl-1.1.1g/lib /media/Leou/QtSrc/Src/qtwebengine/build/lib/libQt5Pdf.so /home/Leou/Qt/5.15.2/gcc_64/lib/libQt5Widgets.so /home/Leou/Qt/5.15.2/gcc_64/lib/libQt5Gui.so /home/Leou/Qt/5.15.2/gcc_64/lib/libQt5Core.so -lpthread -lGL ln -s libQt5PdfWidgets.so.5.15.2 libQt5PdfWidgets.so ln -s libQt5PdfWidgets.so.5.15.2 libQt5PdfWidgets.so.5 ln -s libQt5PdfWidgets.so.5.15.2 libQt5PdfWidgets.so.5.15 rm -f ../../lib/libQt5PdfWidgets.so.5.15.2 mv -f libQt5PdfWidgets.so.5.15.2 ../../lib/libQt5PdfWidgets.so.5.15.2 rm -f ../../lib/libQt5PdfWidgets.so rm -f ../../lib/libQt5PdfWidgets.so.5 rm -f ../../lib/libQt5PdfWidgets.so.5.15 mv -f libQt5PdfWidgets.so ../../lib/libQt5PdfWidgets.so mv -f libQt5PdfWidgets.so.5 ../../lib/libQt5PdfWidgets.so.5 mv -f libQt5PdfWidgets.so.5.15 ../../lib/libQt5PdfWidgets.so.5.15 objcopy --only-keep-debug ../../lib/libQt5PdfWidgets.so.5.15.2 ../../lib/libQt5PdfWidgets.so.5.15.2.debug && objcopy --strip-debug ../../lib/libQt5PdfWidgets.so.5.15.2 && objcopy --add-gnu-debuglink=../../lib/libQt5PdfWidgets.so.5.15.2.debug ../../lib/libQt5PdfWidgets.so.5.15.2 && chmod -x ../../lib/libQt5PdfWidgets.so.5.15.2.debug make[2]: 离开目录“/media/Leou/QtSrc/Src/qtwebengine/build/src/pdfwidgets” make[1]: 离开目录“/media/Leou/QtSrc/Src/qtwebengine/build/src”
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20

可以看到lib下的产物
在这里插入图片描述

安装

直接替换安装当前Qt 的 QWebEngine

make install
  • 1

测试

使用Qt的simplebrowser demo程序打开 html5test 网站测试功能:
在这里插入图片描述
可见已经支持了h264、mp3等音视频功能。

总结

在Linux上编译QWebEngine总体上比较容易,没有编译chromium那么困难。

https://doc.qt.io/qt-5/qtwebengine-platform-notes.html

标签:
声明

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

在线投稿:投稿 站长QQ:1888636

后台-插件-广告管理-内容页尾部广告(手机)
关注我们

扫一扫关注我们,了解最新精彩内容

搜索
排行榜