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

打印 上一主题 下一主题

主题 867|帖子 867|积分 2601

配景

默认自带的QWebEngine 因版权问题不支持音视频功能,须要本身编译源码以支持。
平台:Linux(UOS V20 1050)
Qt:5.15.2
准备工作


  • 下载 Qt 5.15.2 对应版本源码,使用镜像网站或者Qt Maintenance Tool工具下载。
  • 设置 Qt 环境变量
  1. vim ~/.bashrc
复制代码
将以下内容追加到bashrc文件后
  1. #QT ENV
  2. export PATH=/home/Leou/Qt/5.15.2/gcc_64/bin:$PATH
  3. export LD_LIBRARY_PATH=/home/Leou/Qt/5.15.2/gcc_64/lib:$LD_LIBRARY_PATH
  4. export QT_PLUGIN_PATH=/home/Leou/Qt/5.15.2/gcc_64/plugins:$QT_PLUGIN_PATH
  5. export QML2_PATH=/home/Leou/Qt/5.15.2/gcc_64/qml:$QML2_PATH
复制代码
革新使其生效
  1. 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, Flex
  • GPerf
  • Node.js version 8 or later (version 12 or later is recommended)
这些是最基本的要求,实际上另有很多库须要安装,可参考qtwebengine-platform-notes
编译

创建build目录,并使用qmake ../qtwebengine.pro -- -webengine-proprietary-codecs下令
  1. Leou@Leou-PC:/media/Leou/qtwebengine$ mkdir build
  2. Leou@Leou-PC:/media/Leou/qtwebengine$ cd build/
  3. Leou@Leou-PC:/media/Leou/qtwebengine/build$ qmake ../qtwebengine.pro -- -webengine-proprietary-codecs
复制代码
输出信息:
  1. Info: creating stash file /media/Leou/qtwebengine/build/.qmake.stash
  2. Info: creating cache file /media/Leou/qtwebengine/build/.qmake.cache
  3. Running configuration tests...
  4. Checking for architecture supported... yes
  5. Checking for bison... no
  6. Checking for submodule initialized... yes
  7. Checking for build path without whitespace... yes
  8. Checking for platform supported...
  9. Checking for gperf... yes
  10. Checking for flex... no
  11. Checking for host pkg-config... /usr/bin/pkg-config
  12. Checking for jumbo build merge limit... 8
  13. Checking for linker supports -z noexecstack... yes
  14. Checking for x11... yes
  15. Checking for libdrm... yes
  16. Checking for xcomposite... yes
  17. Checking for xcursor... yes
  18. Checking for xi... yes
  19. Checking for xtst... yes
  20. Checking for python2... /usr/bin/python2
  21. Checking for d-bus... yes
  22. Checking for fontconfig... yes
  23. Checking for freetype >= 2.4.2... yes
  24. Checking for glib-2.0 >= 2.32.0... yes
  25. Checking for glibc > 2.16... yes
  26. Checking for jsoncpp... no
  27. Checking for khr... yes
  28. Checking for lcms2... no
  29. Checking for libevent... no
  30. Checking for libvpx... no
  31. Checking for libwebp, libwebpmux and libwebpdemux... no
  32. Checking for compatible libxml2 and libxslt... no
  33. Checking for minizip... no
  34. Checking for system ninja... no
  35. Checking for nss >= 3.26... yes
  36. Checking for opus... no
  37. Checking for protobuf... no
  38. Checking for re2... no
  39. Checking for snappy... no
  40. Checking for zlib... yes
  41. Done running configuration tests.
  42. Configure summary:
  43. Qt WebEngine Build Tools:
  44.   Use System Ninja ....................... no
  45.   Use System Gn .......................... no
  46.   Jumbo Build Merge Limit ................ 8
  47.   Developer build ........................ no
  48.   Sanitizer .............................. no
  49.   QtWebEngine required system libraries:
  50.     fontconfig ........................... yes
  51.     dbus ................................. yes
  52.     nss .................................. yes
  53.     khr .................................. yes
  54.     glibc ................................ yes
  55.   QtWebEngine required system libraries for qpa-xcb:
  56.     x11 .................................. yes
  57.     libdrm ............................... yes
  58.     xcomposite ........................... yes
  59.     xcursor .............................. yes
  60.     xi ................................... yes
  61.     xtst ................................. yes
  62.   Optional system libraries used:
  63.     re2 .................................. no
  64.     icu .................................. no
  65.     libwebp, libwebpmux and libwebpdemux . no
  66.     opus ................................. no
  67.     ffmpeg ............................... no
  68.     libvpx ............................... no
  69.     snappy ............................... no
  70.     glib ................................. yes
  71.     zlib ................................. yes
  72.     minizip .............................. no
  73.     libevent ............................. no
  74.     jsoncpp .............................. no
  75.     protobuf ............................. no
  76.     libxml2 and libxslt .................. no
  77.     lcms2 ................................ no
  78.     png .................................. no
  79.     JPEG ................................. no
  80.     harfbuzz ............................. no
  81.     freetype ............................. yes
  82. Note: The following modules are not being compiled in this configuration:
  83.     webenginecore
  84.     webengine
  85.     webenginewidgets
  86.     pdf
  87.     pdfwidgets
  88. WARNING: Tool bison is required to build QtWebEngine.
  89. WARNING: Tool bison is required to build QtPdf.
  90. WARNING: QtWebEngine will not be built.
  91. WARNING: QtPdf will not be built.
  92. Qt is now configured for building. Just run 'make'.
  93. Once everything is built, you must run 'make install
  94. '.
  95. Qt will be installed into '/home/Leou/Qt/5.15.2/gcc_64'.
  96. Prior to reconfiguration, make sure you remove any leftovers from
  97. the previous build.
复制代码
查看输出信息并安装缺失的库:
安装bison
  1. sudo apt install bison
复制代码
安装flex
  1. sudo apt install flex
复制代码
安装后,疑似有缓存,所以导致未更新,可删除build下的产物,再运行一次qmake ../qtwebengine.pro -- -webengine-proprietary-codecs
输出信息:
  1. Leou@Leou-PC:/media/Leou/QtSrc/Src/qtwebengine/build$ qmake ../qtwebengine.pro -- -webengine-proprietary-codecs
  2. Running configuration tests...
  3. Done running configuration tests.
  4. Configure summary:
  5. Qt WebEngine Build Tools:
  6.   Use System Ninja ....................... no
  7.   Use System Gn .......................... no
  8.   Jumbo Build Merge Limit ................ 8
  9.   Developer build ........................ no
  10.   Sanitizer .............................. no
  11.   QtWebEngine required system libraries:
  12.     fontconfig ........................... yes
  13.     dbus ................................. yes
  14.     nss .................................. yes
  15.     khr .................................. yes
  16.     glibc ................................ yes
  17.   QtWebEngine required system libraries for qpa-xcb:
  18.     x11 .................................. yes
  19.     libdrm ............................... yes
  20.     xcomposite ........................... yes
  21.     xcursor .............................. yes
  22.     xi ................................... yes
  23.     xtst ................................. yes
  24.   Optional system libraries used:
  25.     re2 .................................. no
  26.     icu .................................. no
  27.     libwebp, libwebpmux and libwebpdemux . no
  28.     opus ................................. no
  29.     ffmpeg ............................... no
  30.     libvpx ............................... no
  31.     snappy ............................... no
  32.     glib ................................. yes
  33.     zlib ................................. yes
  34.     minizip .............................. no
  35.     libevent ............................. no
  36.     jsoncpp .............................. no
  37.     protobuf ............................. no
  38.     libxml2 and libxslt .................. no
  39.     lcms2 ................................ no
  40.     png .................................. no
  41.     JPEG ................................. no
  42.     harfbuzz ............................. no
  43.     freetype ............................. yes
  44. Qt WebEngineCore:
  45.   Embedded build ......................... no
  46.   Full debug information ................. no
  47.   Pepper Plugins ......................... yes
  48.   Printing and PDF ....................... yes
  49.   Proprietary Codecs ..................... yes
  50.   Spellchecker ........................... yes
  51.   Native Spellchecker .................... no
  52.   WebRTC ................................. yes
  53.   PipeWire over GIO ...................... no
  54.   Geolocation ............................ yes
  55.   WebChannel support ..................... yes
  56.   Kerberos Authentication ................ no
  57.   Extensions ............................. yes
  58.   Node.js ................................ no
  59.   Support qpa-xcb ........................ yes
  60.   Use ALSA ............................... yes
  61.   Use PulseAudio ......................... yes
  62. Qt WebEngineQml:
  63.   Support Qt WebEngine Qml ............... yes
  64.   UI Delegates ........................... yes
  65.   Test Support ........................... no
  66. Qt WebEngineWidgets:
  67.   Support Qt WebEngine Widgets ........... yes
  68. Qt PDF:
  69.   Support V8 ............................. no
  70.   Support XFA ............................ no
  71.   Support XFA-BMP ........................ no
  72.   Support XFA-GIF ........................ no
  73.   Support XFA-PNG ........................ no
  74.   Support XFA-TIFF ....................... no
  75. Qt PDF Widgets:
  76.   Support Qt PDF Widgets ................. yes
  77. WARNING: Building without node.js will disable some features of QtWebEngine DevTools.
  78. Qt is now configured for building. Just run 'make'.
  79. Once everything is built, you must run 'make install
  80. '.
  81. Qt will be installed into '/home/Leou/Qt/5.15.2/gcc_64'.
  82. Prior to reconfiguration, make sure you remove any leftovers from
  83. the previous build.
复制代码
执行make
  1. make -j14
复制代码
假如出错,则多执行反复make下令

执行结束后:
  1. mv -f libqwebengineview.so ../../../plugins/designer/libqwebengineview.so
  2. 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
  3. make[3]: 离开目录“/media/Leou/QtSrc/Src/qtwebengine/build/src/plugins/qwebengineview”
  4. make[2]: 离开目录“/media/Leou/QtSrc/Src/qtwebengine/build/src/plugins”
  5. rm -f libQt5PdfWidgets.so.5.15.2 libQt5PdfWidgets.so libQt5PdfWidgets.so.5 libQt5PdfWidgets.so.5.15
  6. 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   
  7. ln -s libQt5PdfWidgets.so.5.15.2 libQt5PdfWidgets.so
  8. ln -s libQt5PdfWidgets.so.5.15.2 libQt5PdfWidgets.so.5
  9. ln -s libQt5PdfWidgets.so.5.15.2 libQt5PdfWidgets.so.5.15
  10. rm -f ../../lib/libQt5PdfWidgets.so.5.15.2
  11. mv -f libQt5PdfWidgets.so.5.15.2 ../../lib/libQt5PdfWidgets.so.5.15.2
  12. rm -f ../../lib/libQt5PdfWidgets.so
  13. rm -f ../../lib/libQt5PdfWidgets.so.5
  14. rm -f ../../lib/libQt5PdfWidgets.so.5.15
  15. mv -f libQt5PdfWidgets.so ../../lib/libQt5PdfWidgets.so
  16. mv -f libQt5PdfWidgets.so.5 ../../lib/libQt5PdfWidgets.so.5
  17. mv -f libQt5PdfWidgets.so.5.15 ../../lib/libQt5PdfWidgets.so.5.15
  18. 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
  19. make[2]: 离开目录“/media/Leou/QtSrc/Src/qtwebengine/build/src/pdfwidgets”
  20. make[1]: 离开目录“/media/Leou/QtSrc/Src/qtwebengine/build/src”
复制代码
可以看到lib下的产物

安装

直接替换安装当前Qt 的 QWebEngine
  1. make install
复制代码
测试

使用Qt的simplebrowser demo程序打开 html5test 网站测试功能:

可见已经支持了h264、mp3等音视频功能。
总结

在Linux上编译QWebEngine总体上比较容易,没有编译chromium那么困难。
   https://doc.qt.io/qt-5/qtwebengine-platform-notes.html

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

用户国营

金牌会员
这个人很懒什么都没写!
快速回复 返回顶部 返回列表