Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

Showing VLC output on a PyGame subsurface?

edited September 2016 in OpenSesame

Hi,

I'm working on an experiment where people watch a video while at the same time use a joystick to rate the video, using PyGame and the VLC bindings. This is the basic setting:
I created two subsurfaces for watching (left) and rating(right). The problem is that I cannot think of a way to play the video on the pygame subsurface on the left. I know the VLC bindings can output the video to a window given its window id, but I wonder if it is possible to output the video to a pygame surface (or subsurface).

I know pyglet can get the image data and show the image by using pygame.image.frombuffer().

Something like this

def draw(self, (width, height), surface, (x, y),fps):
    @self.window.event
    def on_draw():
        # Convert the Pyglet video player's image to a Pygame surface
        tex = self.player.get_texture()
        raw = tex.get_image_data()
        pixels = raw.get_data('RGBA', raw.width * 4)
        video = pygame.image.frombuffer(pixels, (raw.width, raw.height), 'RGBA')
        video_scaled = pygame.transform.scale(video, (width, height))
        # Blit the image to the screen
        surface.blit(video_scaled, (x, y))
        pygame.display.update()

So I wonder if there is a similar way for VLC bindings?

Thank you!!
Han

Comments

  • Hi Han,
    I've been trying to do this for a while now, but haven't succeeded either. The problem is that de vlc bindings for Python are not very well documented, and largely neglected as I see it. There is an API description at http://olivieraubert.net/vlc/python-ctypes/doc/index.html and I got as far as finding out you need vlc.MediaPlayer.video_set_callbacks() to get this to work, but then I got stuck again and stopped trying.
    If you want to do something like this, I think it will be more worth your while to look into libraries such as GStreamer or MoviePy which are much easier to integrate with Python than vlc.

    Buy Me A Coffee

Sign In or Register to comment.