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

Windows10下Pyglet播放视频仅出声无画面问题求助

Fixing Pyglet Video Display Issue (Sound Plays, No Video)

Hey there, let's get your Pyglet video playback showing actual frames instead of just sound. I've gone through your code and spotted a few key issues, plus some extra tips to make it work smoothly:

Key Problems in Your Code

  • Typos break rendering: You wrote player.get_texture().bilt(50,50) — that's a typo! The correct method name is blit (missing an 'l'). This is why the video frame never gets drawn.
  • Unbound draw event: You defined an on_draw function, but never told Pyglet's window to use it. Without binding this function to the window's on_draw event, Pyglet has no idea it needs to run your rendering logic.
  • No screen clearing: Before drawing the video texture, you need to clear the window first. Skipping this can cause visual glitches or prevent the texture from showing up at all.

Corrected Code

Here's the fixed version with explanations in comments:

import pyglet

vidPath = 'cc.avi'
window = pyglet.window.Window(fullscreen=True)
player = pyglet.media.Player()

# Load your video file
media_source = pyglet.media.load(vidPath)
player.queue(media_source)
player.play()

# Critical: Bind this function to the window's draw event
@window.event
def on_draw():
    window.clear()  # Clear the window before rendering
    if player.source and player.source.video_format:
        texture = player.get_texture()
        # Option 1: Stretch video to fill the fullscreen window
        texture.blit(0, 0, width=window.width, height=window.height)
        # Option 2: Keep fixed position (like your original code)
        # texture.blit(50, 50)

pyglet.app.run()

Extra Troubleshooting Tips

If you still don't see video after fixing the code:

  • Install FFmpeg support: Pyglet relies on FFmpeg to decode most video formats. Reinstall Pyglet with FFmpeg bindings using:
    pip install pyglet[ffmpeg]
    
  • Check video encoding: Some AVI/MP4 files use rare or unsupported codecs. Try converting your video to a standard H.264-encoded MP4 and test again — this is the most widely supported format for Pyglet.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.25 07:43:12