PyQt5/PySide2 播放视频

方案一,使用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)AndroidBlackBerryWinRT
MediaPlayer controlXXXXXXX
URL source (local and remote)XXXXXXX
Stream sourceXXXX
MetadataXXpartialXXX
Playback rateXXXXXXX
Track selectionX
HW decodingXXXXXXX
Video window controlXXXXX
Video widget controlXX
Video renderer control (includes OpenGL textures)XXXXXXX
Audio probeXXX
Video ProbeXXX

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画布上。
问题:视频中的音轨如何同步播放?

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

开源技术

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值