BGE - Get and use the Blender camera video stream during game

Hello everyone, and thank you for giving me a bit of your time :slight_smile:

I would like to know how I can get the video stream (output) from the active camera during game in realtime, in order to use it (for instance, send it via UDP-Python to an external program which will receive it for treatment) ? Do you have any idea ?

Thanks for your help

Simply, yes.
Look into VideoTexture, getting the image from the scene’s active camera, and using ImageArray (or something named similarly) to convert the image into a serialisable array.
Then, use a socket to send the data outside the Game Engine.
from there you’ll need to know the format of videotexture array in order to correctly reconstruct the image outside of the engine.

Sending game-state and rendering on the receiver would be much more efficient.

If you really need to send a video stream, you’ll probably want to compress it first.

Thanks for yout help :slight_smile:

So I tried to use Texture module (2.63 version) ->

source = texture.imageRender(scene,camera) #to get the active camera screen view, and then :
texture.imageToArray(source) #to transform it in one dimensionnal array

but then, I have no idea how to socket an image. Actually, I have only experience with simple type communication such as int or float from C++/Qt to Python/Socket. How can I send/receive an image containing in an array type using UDP socket ?

@Goran: what do you means by efficiency ? Do you think that direct UDP communication for image will result in low framerate ? I would like to optimize this parameter because it is of first importance in my project.

Thank again for your help