You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Kivy VideoPlayer无法运行:ffpyplayer被忽略问题排查求助

Kivy VideoPlayer组件无法正常工作问题排查

我正在用Kivy开发第一个应用,但VideoPlayer组件无法正常运行。出现错误提示:Provider: ffpyplayer(['video_ffmpeg'] ignored),这似乎是问题根源。我已通过pip安装了ffpyplayer及Pillow。

运行以下代码:

import kivy
print(kivy.kivy_options['VIDEO'])

得到输出:('gstplayer', 'ffmpeg', 'ffpyplayer', 'null')

最小可复现示例代码

from kivy.app import App
from kivy.uix.widget import Widget
from kivy.uix.videoplayer import VideoPlayer


class VideoPlayerWindow(Widget):

    def __init__(self, **kwargs):
        super(VideoPlayerWindow, self).__init__(**kwargs)
        self.player = VideoPlayer(
            source=r"D:\kivy-thelab\resources\commercial_free\videos\pilates1.mp4",
            state='play',
        )

class MainApp(App):
    def build(self):
        return VideoPlayerWindow()

if __name__ == "__main__":
    MainApp().run()

完整调试输出

[INFO   ] [Logger      ] Record log in C:\Users\Home\.kivy\logs\kivy_23-05-08_10.txt
[INFO   ] [deps        ] Successfully imported "kivy_deps.angle" 0.3.3
[INFO   ] [deps        ] Successfully imported "kivy_deps.glew" 0.3.1
[INFO   ] [deps        ] Successfully imported "kivy_deps.sdl2" 0.4.5
[INFO   ] [Kivy        ] v2.1.0
[INFO   ] [Kivy        ] Installed at "C:\Users\Home\miniconda3\envs\kivy_env\lib\site-packages\kivy\__init__.py"
[INFO   ] [Python      ] v3.9.0 | packaged by conda-forge | (default, Nov 26 2020, 07:53:15) [MSC v.1916 64 bit (AMD64)]
[INFO   ] [Python      ] Interpreter at "C:\Users\Home\miniconda3\envs\kivy_env\python.exe"
[INFO   ] [Logger      ] Purge log fired. Processing...
[INFO   ] [Logger      ] Purge finished!
[INFO   ] [Factory     ] 189 symbols loaded
[INFO   ] [ImageLoaderFFPy] Using ffpyplayer 4.5.0
[INFO   ] [Image       ] Providers: img_tex, img_dds, img_sdl2, img_pil, img_ffpyplayer 
[INFO   ] [Text        ] Provider: sdl2
[INFO   ] [VideoFFPy   ] Using ffpyplayer 4.5.0
[INFO   ] [Video       ] Provider: ffpyplayer(['video_ffmpeg'] ignored)
[INFO   ] [Window      ] Provider: sdl2
[INFO   ] [GL          ] Using the "OpenGL" graphics system
[INFO   ] [GL          ] GLEW initialization succeeded
[INFO   ] [GL          ] Backend used <glew>
[INFO   ] [GL          ] OpenGL version <b'4.6.0 - Build 27.20.100.8682'>
[INFO   ] [GL          ] OpenGL vendor <b'Intel'>
[INFO   ] [GL          ] OpenGL renderer <b'Intel(R) HD Graphics 620'>
[INFO   ] [GL          ] OpenGL parsed version: 4, 6
[INFO   ] [GL          ] Shading version <b'4.60 - Build 27.20.100.8682'>
[INFO   ] [GL          ] Texture max size <16384>
[INFO   ] [GL          ] Texture max units <32>
[INFO   ] [Window      ] auto add sdl2 input provider
[INFO   ] [Window      ] virtual keyboard not allowed, single mode, not docked
[INFO   ] [Base        ] Start application main loop
[ERROR  ] [Image       ] Error loading <D:\kivy-thelab\resources\commercial_free\videos\pilates1.mp4>
[INFO   ] [GL          ] NPOT texture support is available

请问我哪里操作出错了?


解决方案
  • 核心问题:未将VideoPlayer添加到界面布局
    你在VideoPlayerWindow的__init__方法中实例化了self.player,但没有调用self.add_widget(self.player)将其添加到Widget的子控件列表中,导致播放器组件不会被渲染显示。

  • 关于video_ffmpeg被忽略的提示
    这个提示只是说明ffmpeg视频提供者不可用,但日志显示Kivy已经成功加载了ffpyplayer作为视频提供者([VideoFFPy ] Using ffpyplayer 4.5.0),因此该提示不是视频无法播放的直接原因。

  • 修改后的可运行代码

from kivy.app import App
from kivy.uix.widget import Widget
from kivy.uix.videoplayer import VideoPlayer


class VideoPlayerWindow(Widget):

    def __init__(self, **kwargs):
        super(VideoPlayerWindow, self).__init__(**kwargs)
        self.player = VideoPlayer(
            source=r"D:\kivy-thelab\resources\commercial_free\videos\pilates1.mp4",
            state='play',
            size_hint=(1, 1)  # 设置尺寸适配,让播放器占满窗口
        )
        self.add_widget(self.player)  # 关键:将播放器添加到界面

class MainApp(App):
    def build(self):
        return VideoPlayerWindow()

if __name__ == "__main__":
    MainApp().run()
  • 额外排查步骤
    1. 验证视频文件路径是否正确,可尝试将视频移到更简单的路径(如D:\test.mp4)测试。
    2. 确认视频格式为ffpyplayer支持的编码(推荐H.264编码的MP4文件),若不确定可转换格式后重试。
    3. 更新ffpyplayer到最新版本:pip install --upgrade ffpyplayer。
    4. 避免conda与pip混合安装依赖,可尝试在纯pip环境中测试,排除环境冲突问题。

内容的提问来源于stack exchange,提问作者jamesB

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.22 09:27:54