0

im trying to display a video on a pygame surface using the pyglet library to import, play and then convert the frames into an image. I managed to battle my way through installing avbin but now I'm hitting a type error with my code

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()

when I run, i get the following error

    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'

Nothing that I do seems to solve it

EDIT: So after testing both this file and the sample files provided by pyglet, it seems that I get this error no matter what filetype I use, could this be an installation error with pyglet or AVbin?

Ingmar Hupp
  • 2,409
  • 18
  • 22
Ryytikki
  • 11
  • 3
  • You don't use the [PyGame library](http://pygame.org), do you? Because that's what "pygame" and the tag of the same name usually mean. I presume you use is as shorthand for "game written in Python", but that's very confusing. –  Nov 03 '13 at 00:49
  • Yes, the surface thats being handed to the function is a Pygame one declared earlier: `window_surface = pygame.display.set_mode((1336,768))` – Ryytikki Nov 03 '13 at 00:51
  • You're using both PyGame and pyglet, in parallel? –  Nov 03 '13 at 01:05
  • Just updated the post to remove ambiguity, hopefully this should make it more clear what I'm doing – Ryytikki Nov 03 '13 at 01:05
  • Yes, I built the entire thing with pygame and have just now hit the roadblock that is pygames rather crappy video playback function. To solve this im simply using pyglets one instead and blitting the end result onto a pygame surface. Know any better ways I can impliment videos that would be too mindblowing? – Ryytikki Nov 03 '13 at 01:06
  • After testing the video files with the example code for pyglet, I've found that its to do with the files themselves, they're .movs that have been converted so I probs just mucked up the conversion somewhere. Documentation and examples for pyglet: https://code.google.com/p/pyglet/downloads/detail?name=pyglet-docs-1.1.4.zip&can=2&q= – Ryytikki Nov 03 '13 at 05:05

1 Answers1

1

Gave up trying to use pyglet and swapped to VLC where I just have to pass the window ID for the game and it does the rest for me

VLC script: https://wiki.videolan.org/Python_bindings/

Ryytikki
  • 11
  • 3