🎥 Make videos programmatically with React
Docs: Add a parallel encoding guide
Jonny Burgerb2042a1a0bce
diff --git a/packages/docs/docs/cli/render.mdx b/packages/docs/docs/cli/render.mdxindex 3c414fdbcd..4972f406b9 100644--- a/packages/docs/docs/cli/render.mdx+++ b/packages/docs/docs/cli/render.mdx@@ -172,7 +172,7 @@ For example only every second frame, every third frame and so on. Only works forDisallows the renderer from doing rendering frames and encoding at the same time. This makes the rendering process more memory-efficient, but possibly slower.-See [parallel encoding](/docs/encoding#parallel-encoding) for supported codecs and when it is enabled.+See [parallel encoding](/docs/parallel-encoding) for when it is enabled and how it works.From <AvailableFrom v="4.0.533" inline />, parallel encoding is no longer disabled automatically based on the available memory. Set this flag if the machine runs out of memory while rendering.diff --git a/packages/docs/docs/config.mdx b/packages/docs/docs/config.mdxindex b89fd7022b..1d1850ca79 100644--- a/packages/docs/docs/config.mdx+++ b/packages/docs/docs/config.mdx@@ -558,7 +558,7 @@ The [command line flag](/docs/cli/render#--muted) `--muted` will take precedenceDisallows the renderer from doing rendering frames and encoding at the same time. This makes the rendering process more memory-efficient, but possibly slower. Default `false`.-See [parallel encoding](/docs/encoding#parallel-encoding) for supported codecs and when it is enabled.+See [parallel encoding](/docs/parallel-encoding) for when it is enabled and how it works.From <AvailableFrom v="4.0.533" inline />, parallel encoding is no longer disabled automatically based on the available memory. Set this option if the machine runs out of memory while rendering.diff --git a/packages/docs/docs/encoding.mdx b/packages/docs/docs/encoding.mdxindex 29889e3d3d..fff45d93af 100644--- a/packages/docs/docs/encoding.mdx+++ b/packages/docs/docs/encoding.mdx@@ -114,11 +114,7 @@ You can set a config using [`Config.setCodec()` in the config file](/docs/config## Parallel encoding-With parallel encoding, video frames are encoded while other frames are still being rendered. This is enabled by default for H.264 and H.265, and from <AvailableFrom v="4.0.534" inline /> for VP8, VP9, AV1 and ProRes. GIFs and audio-only renders do not use parallel encoding.--On [supported platforms](/docs/shared-memory-chromium-patch#when-it-is-used), parallel encoding also enables [shared-memory capture](/docs/shared-memory-chromium-patch), which avoids compressing frames into JPEG or PNG images before encoding the video.--The browser and FFmpeg run at the same time, which can increase peak memory usage. To render all frames before encoding, use [`--disallow-parallel-encoding`](/docs/cli/render#--disallow-parallel-encoding), set [`disallowParallelEncoding: true`](/docs/renderer/render-media#disallowparallelencoding), or call [`Config.setDisallowParallelEncoding(true)`](/docs/config#setdisallowparallelencoding).+Remotion can encode video frames while other frames are still being rendered. See [Parallel encoding](/docs/parallel-encoding) for when it is enabled, memory usage and how to opt out.## Controlling quality using the CRF settingdiff --git a/packages/docs/docs/parallel-encoding.mdx b/packages/docs/docs/parallel-encoding.mdxnew file mode 100644index 0000000000..0e086c0f33--- /dev/null+++ b/packages/docs/docs/parallel-encoding.mdx@@ -0,0 +1,74 @@+---+image: /generated/articles-docs-parallel-encoding.png+title: Parallel encoding+crumb: 'Rendering'+---++# Parallel encoding++With parallel encoding, Remotion encodes video frames using FFmpeg while Chromium renders the following frames. Encoding starts as soon as the first frame is available, instead of waiting for all frames to be rendered.++After the frames have been encoded, Remotion combines the video and any audio into the final output file.++## When it is enabled++From <AvailableFrom v="4.0.534" inline />, parallel encoding is enabled by default for every [supported video codec](/docs/encoding#choosing-a-codec). H.264 and H.265 already used parallel encoding before this version.++GIFs, audio-only renders, stills and image sequences do not use parallel encoding. GIF encoding needs a color palette generated from all frames before encoding can start.++This applies to server-side rendering, including [Remotion Lambda](/docs/lambda) and [Cloud Run](/docs/cloudrun). [Client-side rendering](/docs/client-side-rendering) uses a different rendering pipeline.++Parallel encoding is independent of [rendering concurrency](/docs/terminology/concurrency): it also works with a single browser tab. On Lambda, it runs within each render chunk.++## Performance and memory++Overlapping frame rendering and encoding can reduce the total render time. The benefit depends on your composition, encoder and machine.++The browser and FFmpeg need memory at the same time, which can increase peak memory usage. If your render runs out of memory, [disable parallel encoding](#disable-parallel-encoding) to render all frames before starting the encoder. This may make rendering slower.++From <AvailableFrom v="4.0.533" inline />, Remotion no longer disables parallel encoding automatically based on the available memory.++## Shared-memory capture++On [supported platforms](/docs/shared-memory-chromium-patch#when-it-is-used), parallel encoding enables [shared-memory capture](/docs/shared-memory-chromium-patch). Frames are passed directly to FFmpeg as bitmaps, avoiding the extra JPEG or PNG compression step.++Parallel encoding also works with regular JPEG or PNG screenshots on other platforms. Your selected video codec and encoding settings still apply.++## Check whether it is enabled++Render with [verbose logging](/docs/troubleshooting/debug-failed-render):++```bash title="Check parallel encoding"+npx remotion render MyComp --log=verbose+```++Look for `Parallel encoding is enabled.` or `Parallel encoding is disabled.` in the logs. With [`renderMedia()`](/docs/renderer/render-media), set `logLevel: "verbose"` to see the same messages.++Shared-memory capture has a [separate log message](/docs/shared-memory-chromium-patch#check-whether-it-is-active).++## Disable parallel encoding++For CLI renders, pass [`--disallow-parallel-encoding`](/docs/cli/render#--disallow-parallel-encoding):++```bash title="Render frames before encoding"+npx remotion render MyComp --disallow-parallel-encoding+```++With [`renderMedia()`](/docs/renderer/render-media#disallowparallelencoding), set `disallowParallelEncoding: true`.++For CLI and Studio renders, you can also use [`Config.setDisallowParallelEncoding()`](/docs/config#setdisallowparallelencoding):++```ts twoslash title="remotion.config.ts"+import {Config} from '@remotion/cli/config';++Config.setDisallowParallelEncoding(true);+```++Disabling parallel encoding also disables shared-memory capture. Lambda and Cloud Run currently do not expose this option.++## See also++- [Encoding guide](/docs/encoding)+- [Shared-memory Chromium Patch](/docs/shared-memory-chromium-patch)+- [Troubleshooting out-of-memory errors](/docs/troubleshooting/sigkill)+- [Concurrency](/docs/terminology/concurrency)diff --git a/packages/docs/docs/renderer/render-media.mdx b/packages/docs/docs/renderer/render-media.mdxindex 0abd0492fb..d5a33d57db 100644--- a/packages/docs/docs/renderer/render-media.mdx+++ b/packages/docs/docs/renderer/render-media.mdx@@ -462,7 +462,7 @@ Before you use this hack, reach out to the Remotion team on [Discord](https://reDisallows the renderer from doing rendering frames and encoding at the same time. This makes the rendering process more memory-efficient, but possibly slower.-See [parallel encoding](/docs/encoding#parallel-encoding) for supported codecs and when it is enabled.+See [parallel encoding](/docs/parallel-encoding) for when it is enabled and how it works.From <AvailableFrom v="4.0.533" inline />, parallel encoding is no longer disabled automatically based on the available memory. Set this option if the machine runs out of memory while rendering.diff --git a/packages/docs/docs/shared-memory-chromium-patch.mdx b/packages/docs/docs/shared-memory-chromium-patch.mdxindex 428aa0d244..05a2927910 100644--- a/packages/docs/docs/shared-memory-chromium-patch.mdx+++ b/packages/docs/docs/shared-memory-chromium-patch.mdx@@ -18,7 +18,7 @@ Shared-memory capture is enabled automatically when all of these conditions are- You use Remotion v4.0.534 or later on one of the supported platforms below.- You are rendering a video. GIFs, audio-only renders, stills and image sequences are excluded.-- [Parallel encoding](/docs/encoding#parallel-encoding) is enabled: frames are rendered and encoded at the same time. This is the default for video renders.+- [Parallel encoding](/docs/parallel-encoding) is enabled: frames are rendered and encoded at the same time. This is the default for video renders.| Platform | Requirements || --------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |@@ -81,3 +81,4 @@ This also makes frame rendering and encoding happen in separate stages, which ca- [Chrome Headless Shell](/docs/miscellaneous/chrome-headless-shell)- [Quality guide](/docs/quality)- [Encoding guide](/docs/encoding)+- [Parallel encoding](/docs/parallel-encoding)diff --git a/packages/docs/docs/troubleshooting/sigkill.mdx b/packages/docs/docs/troubleshooting/sigkill.mdxindex 942ce8a1a6..d971558225 100644--- a/packages/docs/docs/troubleshooting/sigkill.mdx+++ b/packages/docs/docs/troubleshooting/sigkill.mdx@@ -43,7 +43,7 @@ Set a lower [`concurrency`](/docs/terminology/concurrency) to open less browser## Disallow parallel encoding-[Parallel encoding](/docs/encoding#parallel-encoding) encodes video while frames are still being rendered, so the browser and FFmpeg need memory at the same time. It is enabled by default for H.264 and H.265, and from <AvailableFrom v="4.0.534" inline /> for VP8, VP9, AV1 and ProRes. Use [`--disallow-parallel-encoding`](/docs/cli/render#--disallow-parallel-encoding) or [`disallowParallelEncoding`](/docs/renderer/render-media#disallowparallelencoding) to only start encoding once all frames are rendered. This lowers the peak memory usage, but may make rendering slower.+[Parallel encoding](/docs/parallel-encoding) encodes video while frames are still being rendered, so the browser and FFmpeg need memory at the same time. Use [`--disallow-parallel-encoding`](/docs/cli/render#--disallow-parallel-encoding) or [`disallowParallelEncoding`](/docs/renderer/render-media#disallowparallelencoding) to only start encoding once all frames are rendered. This lowers the peak memory usage, but may make rendering slower.## Allocate more memory to your systemdiff --git a/packages/docs/sidebars.ts b/packages/docs/sidebars.tsindex 19be958acf..8f300c8049 100644--- a/packages/docs/sidebars.ts+++ b/packages/docs/sidebars.ts@@ -1296,6 +1296,7 @@ const sidebars: SidebarsConfig = {'artifacts','metadata','hardware-acceleration',+ 'parallel-encoding','shared-memory-chromium-patch','webgl','hdr',diff --git a/packages/docs/src/data/articles.ts b/packages/docs/src/data/articles.tsindex b7791e7f5c..ae3fc8c0ef 100644--- a/packages/docs/src/data/articles.ts+++ b/packages/docs/src/data/articles.ts@@ -5796,6 +5796,15 @@ export const articles = [noAi: false,slug: 'bundlers',},+ {+ id: 'parallel-encoding',+ title: 'Parallel encoding',+ relativePath: 'docs/parallel-encoding.mdx',+ compId: 'articles-docs-parallel-encoding',+ crumb: 'Rendering',+ noAi: false,+ slug: 'parallel-encoding',+ },{id: 'parameterized-rendering',title: 'Parameterized videos',diff --git a/packages/docs/static/generated/articles-docs-parallel-encoding.png b/packages/docs/static/generated/articles-docs-parallel-encoding.pngnew file mode 100644index 0000000000..e611e90bb6Binary files /dev/null and b/packages/docs/static/generated/articles-docs-parallel-encoding.png differ