尝试使用pyglet在pygame中嵌入视频

时间:2013-11-03 00:46:30

标签: python pygame playback pyglet movies

我试图在pygame表面上显示视频,使用pyglet库导入,播放然后将帧转换为图像。我设法通过安装avbin战斗我的方式,但现在我用我的代码

遇到类型错误
def cutscene(window_surface, filename):
player = pyglet.media.Player()
source = pyglet.media.load(filename)
player.queue(source)
player.play()

pygame.display.flip()   

while True:

    window_surface.fill(0)

    player.dispatch_events()

    tex = player.get_texture()
    raw = tex.get_image_data().get_data('RGBA',tex.width*4)
    raw = ctypes.string_at(ctypes.addressof(raw), ctypes.sizeof(raw))
    img = pygame.image.frombuffer(raw, (tex.width, tex.height), 'RGBA')
    window_surface.blit(img, (0,0))

    pygame.display.flip()

当我跑步时,我收到以下错误

    Traceback (most recent call last):
  File "dino_game.py", line 348, in <module>
    main()
  File "dino_game.py", line 45, in main
    cutscene(window_surface, "Cutscenes/Cutscene1.mov")
  File "dino_game.py", line 68, in cutscene
    raw = tex.get_image_data().get_data('RGBA',tex.width*4)
AttributeError: 'NoneType' object has no attribute 'get_image_data'

我所做的一切似乎都无法解决它

编辑:所以在测试了这个文件和pyglet提供的示例文件之后,无论我使用什么文件类型,似乎都会出现此错误,这可能是pyglet或AVbin的安装错误吗?

1 个答案:

答案 0 :(得分:1)

试图使用pyglet并交换到VLC,我只需要传递游戏的窗口ID,然后为我做其余的事情

VLC脚本:https://wiki.videolan.org/Python_bindings/