Videotextue from memory file (io.StringIO)

Hi

I’m doing some tests in order to evaluate the game engine for an interactive art installation and I hit a problem that I can’t understand, because no error is returned. The setup is complicated - the image is loaded and converted to string then converted back to image and saved to io.StringIO.

Then the memory file would be sent to VideoFFmpeg who would display it as a videotexture on a plane. The simplified version of this would be:


import io
import pygame
# import other stuff
#
# load image
# convert to string
mem_file = io.StringIO()
pg_img = pygame.image.frombuffer(data, (120,90), "RGB")
pygame.image.save(pg_img,mem_file)
logic.video.source = texture.VideoFFmpeg(mem_file.getvalue())

The code works outside Blender (whitin Pygame) and the plane texture displays a black color when I hit play, so some texture switching is occurring but no error is displayed. Any hint about what’s happening would be great.

Thanks

Video texture will support from a buffer; bge.texture.ImageBuff
Also, why use VideoFFmpeg and not bge.texture.ImageFFmpeg(file)

If I understand correctly, your suggestion is to scrap pygame and call the var “data” on ImageBuff directly?

I tested it on other part of the project where textures are sourced from whitin the network.

The last part should be familiar because is the ImageFFmpeg example from the documentation.


import socket
import bge


data = ""


try:
  client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  client_socket.connect(("192.168.0.12",50007))
  data = client_socket.recv(1024000)
  client_socket.setblocking(0)
  client_socket.close()
except:
  pass


cont = bge.logic.getCurrentController()
obj = cont.owner


def createTexture(cont):
    """Create a new Dynamic Texture"""
    obj = cont.owner


    # get the reference pointer (ID) of the internal texture
    ID = bge.texture.materialID(obj, 'IMmat.png')


    # create a texture object
    object_texture = bge.texture.Texture(obj, ID)


    # create a new source with an external image
    new_source = bge.texture.ImageBuff(data)


    # the texture has to be stored in a permanent Python object
    bge.logic.texture = object_texture


    # update/replace the texture
    bge.logic.texture.source = new_source
    bge.logic.texture.refresh(False)




def removeTexture(cont):
    """Delete the Dynamic Texture, reversing back the final to its original state."""
    try:
        del bge.logic.texture
    except:
        pass


createTexture(cont)
# removeTexture(cont)

Same result, texture switches to black. From the docs it should return an error because ImageBuff takes a bgl.Buff type as first parameter and “data” is of type bytes.

In my previous post I set the VideoFFmpeg from the documentation because in that part of the project the data are still frames from a video.

Have you verified it working with a standard image file?

I’m sorry, I’m not sure if I understand what you are asking.

The data variable is being populated by an image through the network that’s for sure. As for using ImageBuff with an image, I fail to see the point because otherwise it would be better using ImageFFmpeg directly.