方案一,使用Qt Multimedia
Qt的视频播放目前在Windows平台上有两个plugin: Microsoft DirectShow API或者WMF(Windows Media Foundation)。
Qt Multimedia features for Windows are implemented in two plugins; one using the Microsoft DirectShow API, and another using WMF (Windows Media Foundation) framework. DirectShow API was introduced in Windows 98, and gradually deprecated from Windows XP onwards. Media Foundation framework was introduced in Windows Vista as a replacement for DirectShow and other multimedia APIs. Consequently, WMF plugin in Qt is supported only for Windows Vista and later versions of the operating system.
The environment variable QT_MULTIMEDIA_PREFERRED_PLUGINS can be used to control the priority of the plugins. For example, setting it to “windowsmediafoundation” or “directshow” will cause the corresponding plugin to be the preferred one.
问题1:怎么确认配置生效了?文档没说明。
import os
os.environ['QT_MULTIMEDIA_PREFERRED_PLUGINS'] = 'windowsmediafoundation'
MediaService plugins:
DirectShow (Windows) | Media Foundation (Windows) | AV Foundation (OS X / iOS) | GStreamer (Unix) | Android | BlackBerry | WinRT | |
---|---|---|---|---|---|---|---|
MediaPlayer control | X | X | X | X | X | X | X |
URL source (local and remote) | X | X | X | X | X | X | X |
Stream source | X | X | X | X | |||
Metadata | X | X | partial | X | X | X | |
Playback rate | X | X | X | X | X | X | X |
Track selection | X | ||||||
HW decoding | X | X | X | X | X | X | X |
Video window control | X | X | X | X | X | ||
Video widget control | X | X | |||||
Video renderer control (includes OpenGL textures) | X | X | X | X | X | X | X |
Audio probe | X | X | X | ||||
Video Probe | X | X | X |
PyQt5与PySide2包中又的确有相应的dll,所以怎么生效得研究研究。
同时,默认情况下视频格式系统支持少,没有对应解码器时,QMediaPlayer 不会报错,很尴尬。
第三方解码器推荐:
- K-Lite Codec Pack,(使用 Microsoft DirectShow API)
- LAVFilters,(使用 Microsoft DirectShow API)
Ref:
- https://wiki.qt.io/Qt_5.13_Multimedia_Backends
- https://doc.qt.io/qt-5/qtmultimedia-windows.html
方案二,使用OpenCV
使用 cv2 逐帧读取视频文件,然后渲染在Qt Label画布上。
问题:视频中的音轨如何同步播放?