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 isblit(missing an 'l'). This is why the video frame never gets drawn. - Unbound draw event: You defined an
on_drawfunction, but never told Pyglet's window to use it. Without binding this function to the window'son_drawevent, 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
相关产品推荐
相关产品推荐

