我正在尝试使用 pyglet 库在 pygame 表面上显示视频,以导入、播放然后将帧转换为图像。我设法通过安装 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 的安装错误吗?