Skip to content

🎥 Make videos programmatically with React

update post

Jonny Burger0631a07b8ff3
diff --git a/packages/docs/blog/2024-03-11-faster-lambda-renders.mdx b/packages/docs/blog/2024-03-20-faster-lambda-renders.mdx
similarity index 52%
rename from packages/docs/blog/2024-03-11-faster-lambda-renders.mdx
rename to packages/docs/blog/2024-03-20-faster-lambda-renders.mdx
index 3784b63a7c..1004f9ac38 100644
--- a/packages/docs/blog/2024-03-11-faster-lambda-renders.mdx
+++ b/packages/docs/blog/2024-03-20-faster-lambda-renders.mdx
@@ -12,8 +12,9 @@ import { AacFile } from "../components/Aac/AacFile";
import { AacPadding } from "../components/Aac/AacPadding";
import { AacConcatenationProblem } from "../components/Aac/AacConcatenationProblem";
import { AacKeyframes } from "../components/Aac/AacKeyframes";
+import { AacConcatenationSolution } from "../components/Aac/AacConcatenationSolution";
-With Remotion v4.0.123, [Remotion Lambda](/lambda) renders now finish significantly faster!
+With Remotion v4.0.127, [Remotion Lambda](/lambda) renders now finish significantly faster!
- 1 minute video: 15 seconds faster
- 10 minute video: 2 minutes faster
@@ -73,28 +74,40 @@ I went to the [RTC.on](https://rtcon.live/) multimedia conference and talked abo
A few listeners came up to me afterwards and gave me a few ideas. I did a session with [Michał Śledź](https://github.com/mickel8) from [Software Mansion](https://swmansion.com/), all of which helped me even understand the problem we are facing in the first place.
-No immediate solution was found, but the problem was put aside when we realized that the `libfdk-aac` encoder is twice as fast as FFmpeg's native encoder, softened the problem for the moment.
+No immediate solution was found, but the problem was put aside when we realized that the [`libfdk-aac`](https://github.com/mstorsjo/fdk-aac) encoder is twice as fast as FFmpeg's native encoder, softened the problem for the moment.
+
+## An innovative way to concatenate AAC
-## An innovative way to contatenate AAC
+Out of the blue, [Max Schnur](https://github.com/maxpower15) from [Wistia](https://wistia.com/) appeared with a solution and posted it on the [Remotion Discord](https://remotion.dev/discord)!
-Out of the blue, Max Schnur from Wistia appeared with a solution and posted it on the [Remotion Discord](https://remotion.dev/discord)!
+To seamlessly concatenate AAC:
+
+- Each audio segment needs to have a sample count divisible by 1024
+- Each segment should have extra packets at the beginning and the end to not lose the keyframes.
+- The extra padding will be removed when concatenating them together.
<AacConcatenationSolution />
<br />
<br />
-Tricky:
+There are many tricky aspects to implementing this correctly:
-- It's not always 2 extra frames of padding, sometimes 3, sometimes 1
-- Some frames are rendered twice, however no screenshot is taken, only audio
-- `inpoint` and `outpoint` FFmpeg filters need to be nano-second precise
-- All audio needs to be resampled to 48000
-- Remotion supports multiple audio layers, with offsets, volume curve, pitch shifting, and speed correction
-- Rendering only a portion of a video will shift the start timestamp, which changes the math
-- The video frame rate of `1 / 30` and the audio sample rate of `1 / 48000` does not align perfectly. We capture too much padding which needs to be trimmed off for each chunk.
-- FFmpeg `atempo` filter is not perfect
-- AAC has a 512 frame padding in the front.
+- Each audio segment needs to be a bit longer than previously and they need to be slightly overlapping. Extra frames need to be evaluated, but they don't need to be screenshotted.
+- Video chunks should not contain the padding, hence audio and video need to be separated.
+- Depending on the rounding and the position in the audio, between 1 and 3 extra packets are required.
+- The `inpoint` and `outpoint` FFmpeg filters need to be nano-second precise for correct trimming.
+- All audio layers should be resampled to be the same sample rate (we decided for 48000 Hz)
+- Our timeline positioning, volume curves, pitch correction, playback rate capabilities need to continue working.
+- Rendering only a portion of the timeline will shift the start timestamp, which changes the math for each chunk.
+- The video frame rate of (commonly 30fps) and the audio sample rate of (commonly 48000Hz) do seldomly align. By capturing extra frames, we get too much padding which needs to be trimmed off again for each chunk.
+- The FFmpeg `atempo` filter is imprecise: For example, speeding up 80.000 audio samples by 2x will lead to 40.014 audio samples. Tiny imperfections will lead to seamless concatenation not working at all. To fix this, we had to flip the order of trimming and speeding up audio.
+- Not pictured above, each AAC file has a silence of 512 samples at the beginning of the file. This delays all audio slightly, but by adding a negative offset to the MP4 container, this is usually balanced out.
-## Benchmarks
+If all of these factors are accounted for, concatenating AAC chunks will be completely seamless!
-import { AacConcatenationSolution } from "../components/Aac/AacConcatenationSolution";
+<AacFile />
+<br />
+<br />
+
+Upgrade to Remotion 4.0.127 or later to benefit from the faster rendering on Lambda.
+We look forward to engineer even more performance improvements in the future for lower costs and better user experience!