How to make a Remotion render lighter without rewriting the video
Article by Pedro Henrique Lahr
If you use Remotion, you can cut a large share of the processor's work without rewriting a single scene: just change three official settings. On a 15 second stretch of a presenter video, measured by Konecz, CPU time fell 65%: from 346.0 to 121.1 seconds. The three steps are the <Video> component, Remotion's direct MP4 output and the graphics card's NVENC encoder.
Why is a Remotion render heavy?
Because it opens a hidden browser and takes a picture of the page for every frame. When the scene has a recorded video inside, such as a presenter talking, the browser also has to open that video, frame by frame.
In the stretch we measured, the scene code (React and layout) was only 4% of the CPU. Opening the recorded video was 54% and taking the picture of each frame, 42%. So optimizing components helps little. What costs is the video and the capture.
What are the three settings?
We measured each step on the same 15 second stretch (vertical 1080 × 1920 video, presenter filmed at 25 frames per second, output at 30), with two rounds per setting:
| Step | CPU (mean) | Wait time | Peak memory |
|---|---|---|---|
Starting point: <OffthreadVideo>, frames as JPEG on disk, NVENC separately |
346.0 s | 53.4 s | 6.3 GB |
1. <Video> instead of <OffthreadVideo> |
209.7 s | 58.0 s | 3.7 GB |
| 2. Remotion's direct MP4, with x264 | 176.8 s | 33.7 s | 3.7 GB |
| 3. Remotion's direct MP4, with NVENC | 121.1 s | 29.9 s | 3.2 GB |
By the means, each step cut:
<Video>: 39% of the CPU. It is the video component from the@remotion/mediapackage, which Remotion itself recommends.- Direct MP4: another 16%. Instead of writing frames as JPEG and assembling the video afterwards, Remotion delivers the MP4 itself.
- NVENC: another 32%. Compression moves off the processor and onto the NVIDIA card's encoder.
Peak memory fell too, from 6.3 to 3.2 GB. On a server running other things, that counts.
What do these settings not solve?
The recorded video is still opened by the browser, in software. In the rounds we measured, the card's decoder sat at 0% use: Remotion's headless browser did not use the card to open the video, with either <OffthreadVideo> or <Video>. That is what we measured on this machine, not a general rule.
To take that work out of the browser as well, you have to go beyond settings. That is what remotion-gpu did: it separates the recorded video from the graphics and lets the card open, place and combine the two layers. On the full 75 second video, CPU went from 460 to 112 seconds.
When should you stick with the official settings?
The remotion-gpu guide says when the simple path (the three settings, called P1) is best:
- No recorded video inside the composition. Only typography, graphics or slides.
- Several videos on screen at once, such as a grid or picture-in-picture.
- A mask, rotation or blur on the recorded video.
In those cases, splitting into layers does not pay off or does not work, and the official path wins. Layers are worth it when there is one take at a time, as a rectangle on screen.
How do you measure it in your own project?
Three precautions that made a difference to our numbers:
- Measure the CPU of every process. Remotion opens several Chrome processes. A tool that measured only the main process counted less than half.
- Alternate the rounds. Run before and after interleaved, because the machine's load changes.
- Compare only within the same window. Numbers from a 15 second stretch are not divided by numbers from the whole video.
Frequently asked questions
Do I need an NVIDIA card for these settings? For the third, yes: NVENC is NVIDIA's. The first two work without a card and already deliver more than half of the total cut.
Do the settings change the picture? The video is still drawn by the same browser. What changes is how the recorded video comes in and how the MP4 is compressed.
Does this apply to videos without a presenter?
The <Video> gain comes from opening the recorded video better. Without recorded video, NVENC and the direct MP4 still help, but less.
Is Remotion free? Remotion has its own license; companies above a certain size pay. Konecz is not affiliated with Remotion.
The next step, with layers on the GPU, is in the remotion-gpu post. Konecz now renders its videos in its own engine, Kodecz.