videoTexture image pixel data

Hi All,

I’m just trying this simple script:

import bge

from bge import texture
from bge import logic
movie = "0001-5039.mp4"

scene = logic.getCurrentScene();
videoObject = scene.objects['DomFront']
lamp1 = scene.lights['Lamp1']
lamp2 = scene.lights['Lamp2']

pixelpos1 = 100*500*3
pixelpos2 = 500*500*3

if not 'video' in videoObject:

    # identify a static texture by name
    matID = texture.materialID(videoObject, 'IMDSC07268_recht.tif')

    # create a dynamic texture that will replace the static texture
    videoObject['video'] = texture.Texture(videoObject, matID)

    # define a source of image for the texture, here a movie
    videoObject['video'].source = texture.VideoFFmpeg(movie)
    videoObject['video'].source.scale = True

    # quick off the movie, but it wont play in the background
    videoObject['video'].source.play()

# you need to call this function every frame to ensure update of the texture.
videoObject['video'].refresh(True)

This works fine.

Now I want the read some pixel colors from the video. I add the following code at the end:

lamp1.color = [videoObject['video'].source.image[pixelpos1]/255.0, videoObject['video'].source.image[pixelpos1+1]/255.0,  videoObject['video'].source.image[pixelpos1+2]/255.0]
lamp2.color = [videoObject['video'].source.image[pixelpos2]/255.0,  videoObject['video'].source.image[pixelpos2+1]/255.0,  videoObject['video'].source.image[pixelpos2+2]/255.0]

This works as well but my framerate drops to about 3fps. Are there any tips into getting this better?

There’s also no logic to find wether a new image is ready or not.
videoObject[‘video’].source.valid always returns false.
Sometimes videoObject[‘video’].source.image returns None. So my workaround was to do

if videoObject['video'].source.image:
    #get pixel data

Rg,

Arnaud