Render video faster than realtime

Hello,

I’m using NatCorder plugin to record an mp4 of a simple cutscene, with no output to the screen. The goal is to render and save the file as quickly as possible, and since the scenes I’m using are very lightweight, I believe 10 seconds of video can be rendered on my RTX 2070 almost in an instant, plus perhaps some overhead of encoding the video.

If I simply increase timeScale (and bring up video framerate, and keep timestamps corrected to the scale), the video will have crippled framerate, as frames will be skipped.

To work around it, I’m running a separate thread that sleeps for [(1 second / desiredFPS) / desiredTimeScale] milliseconds, and then invokes custom Update methods across a list of subscribed objects, making them advance “custom” time. Works fine - my components dependencies is mostly animators and timeline directors, so it’s easy to evaluate each step. Resulting video has expected framerate and duration, no problems there either.

First problem is that my background thread that counts time and broadcasts updates cannot interact with monobehavior objects - it’s only possible from the main thread, so instead it creates a task in the main sync context, and the task actually updates gameobjects (advances time on timeline directors, etc). Thus, a single frame is:

  • background thread sleeps for N ms
  • it creates a task in unity main task schedule (read, “in the main thread”), and stands by
  • the task “in the main thread” broadcasts all time-dependant calls
  • when the background thread sees that the task is completed, it advances time further and continues the loop, moving to the next frame

The issue here is that the task takes too long to complete. It cannot be a performance restriction, there’s no way, so I suspect that it’s because task pooling and completion is tied to the engine’s own understanding of time, by making my background thread wait, I effectively tie it back to regular Update calls.
In the end, 12 seconds video is saved at 10x speed in 7.6 seconds. Actually, no matter what the time scale is, 12 seconds cutscene always ends up taking ~7.6 seconds to render.

Lastly, it’s really not a question of how NatCorder works. It consumes frames as fast as one can feed them to it.

Ooph, hope it makes sense. Anything?

Hey LeamSDev,
I am also working on a project to speed up the recording of the timeline. I would like to know how to do it. Can you provide a simple demo, thank you