您现在的位置是:首页 > 名人名句

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

作者:淼淼时间:2024-03-29 09:40:35分类:名人名句

简介  文章浏览阅读1.9k次。在Linux上编译QWebEngine 支持h264等音视频功能_qtwebengine required system libraries:

点击全文阅读

背景

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

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

准备工作

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

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

#QT ENVexport PATH=/home/Leou/Qt/5.15.2/gcc_64/bin:$PATHexport LD_LIBRARY_PATH=/home/Leou/Qt/5.15.2/gcc_64/lib:$LD_LIBRARY_PATHexport QT_PLUGIN_PATH=/home/Leou/Qt/5.15.2/gcc_64/plugins:$QT_PLUGIN_PATHexport QML2_PATH=/home/Leou/Qt/5.15.2/gcc_64/qml:$QML2_PATH

刷新使其生效

source ~/.bashrc

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

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

Python 2.7.5 or later. Python 3 is not supported.Bison, FlexGPerfNode.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 buildLeou@Leou-PC:/media/Leou/qtwebengine$ cd build/Leou@Leou-PC:/media/Leou/qtwebengine/build$ qmake ../qtwebengine.pro -- -webengine-proprietary-codecs

输出信息:

Info: creating stash file /media/Leou/qtwebengine/build/.qmake.stashInfo: creating cache file /media/Leou/qtwebengine/build/.qmake.cacheRunning configuration tests...Checking for architecture supported... yesChecking for bison... noChecking for submodule initialized... yesChecking for build path without whitespace... yesChecking for platform supported... Checking for gperf... yesChecking for flex... noChecking for host pkg-config... /usr/bin/pkg-configChecking for jumbo build merge limit... 8Checking for linker supports -z noexecstack... yesChecking for x11... yesChecking for libdrm... yesChecking for xcomposite... yesChecking for xcursor... yesChecking for xi... yesChecking for xtst... yesChecking for python2... /usr/bin/python2Checking for d-bus... yesChecking for fontconfig... yesChecking for freetype >= 2.4.2... yesChecking for glib-2.0 >= 2.32.0... yesChecking for glibc > 2.16... yesChecking for jsoncpp... noChecking for khr... yesChecking for lcms2... noChecking for libevent... noChecking for libvpx... noChecking for libwebp, libwebpmux and libwebpdemux... noChecking for compatible libxml2 and libxslt... noChecking for minizip... noChecking for system ninja... noChecking for nss >= 3.26... yesChecking for opus... noChecking for protobuf... noChecking for re2... noChecking for snappy... noChecking for zlib... yesDone 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 ............................. yesNote: The following modules are not being compiled in this configuration:    webenginecore    webengine    webenginewidgets    pdf    pdfwidgetsWARNING: 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 fromthe previous build.

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

安装bison

sudo apt install bison

安装flex

sudo apt install flex

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

输出信息:

Leou@Leou-PC:/media/Leou/QtSrc/Src/qtwebengine/build$ qmake ../qtwebengine.pro -- -webengine-proprietary-codecsRunning 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 ............................. yesQt 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 ......................... yesQt WebEngineQml:  Support Qt WebEngine Qml ............... yes  UI Delegates ........................... yes  Test Support ........................... noQt WebEngineWidgets:  Support Qt WebEngine Widgets ........... yesQt PDF:  Support V8 ............................. no  Support XFA ............................ no  Support XFA-BMP ........................ no  Support XFA-GIF ........................ no  Support XFA-PNG ........................ no  Support XFA-TIFF ....................... noQt PDF Widgets:  Support Qt PDF Widgets ................. yesWARNING: 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 fromthe previous build.

执行make

make -j14

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

执行结束后:

mv -f libqwebengineview.so ../../../plugins/designer/libqwebengineview.soobjcopy --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.debugmake[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.15g++ -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.soln -s libQt5PdfWidgets.so.5.15.2 libQt5PdfWidgets.so.5ln -s libQt5PdfWidgets.so.5.15.2 libQt5PdfWidgets.so.5.15rm -f ../../lib/libQt5PdfWidgets.so.5.15.2mv -f libQt5PdfWidgets.so.5.15.2 ../../lib/libQt5PdfWidgets.so.5.15.2rm -f ../../lib/libQt5PdfWidgets.sorm -f ../../lib/libQt5PdfWidgets.so.5rm -f ../../lib/libQt5PdfWidgets.so.5.15mv -f libQt5PdfWidgets.so ../../lib/libQt5PdfWidgets.somv -f libQt5PdfWidgets.so.5 ../../lib/libQt5PdfWidgets.so.5mv -f libQt5PdfWidgets.so.5.15 ../../lib/libQt5PdfWidgets.so.5.15objcopy --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.debugmake[2]: 离开目录“/media/Leou/QtSrc/Src/qtwebengine/build/src/pdfwidgets”make[1]: 离开目录“/media/Leou/QtSrc/Src/qtwebengine/build/src”

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

安装

直接替换安装当前Qt 的 QWebEngine

make install

测试

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

总结

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

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

点击全文阅读

郑重声明:

本站所有活动均为互联网所得,如有侵权请联系本站删除处理

我来说两句