Export the godot camera stream to a virtual camera

Godot Version

v4.3.stable.flathub

Question

Hello, I’m trying to export the stream of a godot camera to a virtual camera such as an OBS Virtual Camera would do. I searched online, but I can’t find any solutions… Is anybody would have an idea or an extension that would help for that?

1 Like
  • Interested in this

Originally I thought that creating a Window object or some Viewport/Subviewport is the way to go

While it may not be idea to spawn multiple windows and add them to OBS (preferring a direct stream into an OBS Scene) this might be the next best option since you can create a borderless window and have it’s viewport be an in-game camera

Looking into it I’ve found some interesting tools and discussions around ‘exporting’ video feeds from within Godot, it mostly revolves around getting data from a viewport and sending it externally over the network

Here’s a Github discussion about this, looks like someone got it to work with NDI.

This is the main code for getting the stream, unsure what Marshal is but I’m assuming that’s where the current frame gets sent (to NDI?)

//This method is called by _Process(double delta)
    public void ProcessFrames()
    {
        //Grab the viewport data as bytes. Godot Docs recommends not doing this every frame
        imageData = subViewport.GetTexture().GetImage().GetData();
    
        //copy the viewport data to the memory allocated for use by NDI
        Marshal.Copy(imageData, 0, bufferPtr, imageData.Length);
    }

And I found an extension someone made for the VideoStream to send to NDI

(NDI - Network Device Interface, it’s used for low latency video transfer)