Recording player In-Game with two camera nodes?

Godot Version

4.6.3

Question

Hello,

I have more of a theoretical question: is it possible, to have two cameras, one being the player view and the other one recording what it sees following the player via script and saving the record to a file (starting and stoping the recording by pressing keys for example)?

I’m new to Godot and trying to figure out limitations and mechanics.

Thanks in advance!

In theory, most likely yeah. But in practice… well, in Godot, you can do almost anything with extensions if there aren’t any ready-made solutions.

But it’s an interesting question — I’ve got it on my list to look into.

Oh, it’s already been resolved :backhand_index_pointing_down:

Hacky way taking png screenshots:

@onready var sub: SubViewport = $RecordViewport
@onready var rec_cam: Camera3D = $RecordViewport/RecordCamera
@onready var player: Node3D = $Player
var frame := 0

func _ready() -> void:
  sub.render_target_update_mode = SubViewport.UPDATE_ALWAYS
   _record_loop()

func _record_loop() -> void:
  while true:
    await RenderingServer.frame_post_draw
    sub.get_texture().get_image().save_png("user://rec/frame_%04d.png" % frame)
    frame += 1

I then combined it with ffmpeg to make a video:

It’s saved as a PNG, which can be a bit resource-intensive in some cases. But the main thing is that it works. :movie_camera:

@dginovker’s approach will be fine if your viewport resolution is relatively small. Otherwise, if the image data throughput is large and cannot keep up with the frame rate, you might need to cycle through several viewports and transfer data from gpu to cpu asynchronously using RenderingDevice::texture_get_data_async(). Although even that might exceed the bandwidth, depending on framerate, resolution and hardware.

This plugin might help achieve this more efficiently: GitHub - unvermuthet/godot-ndi: Integrates the NDI® SDK with Godot · GitHub

What to do if:

:exclamation_question_mark:

As far as I understand, this plugin generates a video stream, but it doesn’t capture (record) anything.

And its license is incredibly complicated. I’m even tired of reading it. But there’s a reference to U.S. laws. And the laws in that country are wild — it’s not like civilized Europe.

Since you broadcast the viewport, it’s easier to capture it with OBS, for example, and get a smoother experience.

Then there’s the question of purpose: watching replays in a separate program after the game, or watching them directly from within the game using its own tools? The second option is more interesting.

As far as I understand, Godot has less support for encoding and decoding video than OBS.

Yeah, that’s true. The video in Godot is pretty sad. But it’s nice to know they’re thinking about it and maybe working on it. :hammer_and_wrench:

Well, there’s no other choice than to change one or more of those parameters - lower the resolutions/framerate and/or record on better hardware.

Then we need to clarify the question

Just treat it like any other performance bottleneck. Profile it to determine the exact cause and act accordingly.