How to Access ImageUser Data of a Texture

I have a video playing with VideoFFmpeg, and I’d like the texture to be the first frame of the video before it starts, and remain on the last frame when it ends after loading a new scene in which the video persists. I’m able to accomplish the former by setting the texture that VideoFFmpeg() replaces to the same video file that it plays, setting the “offset” in the “Image” panel of the texture’s properties (which seems to control which frame of the video is statically displayed) to 0.

So later, when I want to change this to the last frame, how do I access it from Python? The tooltip says that the offset is “ImageUser.frame_offset” and I’d also need to access ImageUser.frame_duration to find out what the last frame is so I can set frame_offset to it, but I don’t see any documentation on how to access the ImageUser properties when you have a material ID. (I’ve also checked dir() of the return value of bge.texture.Texture() and don’t see ImageUser in there.)


imgUser =['Texture'].image_user     #'Texture' would be the name of the texture containing the image
fd = imgUser.frame_duration    #get the duration
imgUser.frame_offset = fd    #set duration as offset

Hope that helps.

Cool. I’ll just need to get that texture name given the material id and object. What I have now is:

    materialID=bge.texture.materialID(obj,"MA"+"Material Name") #get material ID
    tex=bge.texture.Texture(obj,materialID,0) #get the material's first texture

I’m not seeing a “name” property of the return value of bge.texture.Texture.

I don’t know much about the bge side of the API, but:

mat =['MA'+'Material Name']    #get material
tex = mat.texture_slots[0].texture    #get the material's first texture

Nice, so that’s how you access the data. I ended up hacking the object to replace it with another one whose material is set to the frame I want, but if that works it should be a lot more elegant.