🎥 Make videos programmatically with React
distributed rendering code
Jonny Burgerbe7ca12bdb98
diff --git a/packages/docs/components/TableOfContents/api.tsx b/packages/docs/components/TableOfContents/api.tsxindex f7bf794a04..4007392d5f 100644--- a/packages/docs/components/TableOfContents/api.tsx+++ b/packages/docs/components/TableOfContents/api.tsx@@ -9,6 +9,7 @@ import {TableOfContents as LicensingTableOfContents} from '../../docs/licensing/import {TableOfContents as MediaParserTableOfContents} from '../../docs/media-parser/TableOfContents';import {TableOfContents as OpenAiWhisperTableOfContents} from '../../docs/openai-whisper/TableOfContents';import {PlayerTableOfContents} from '../../docs/player/TableOfContents';+import {TableOfContents as RendererTableOfContents} from '../../docs/renderer/TableOfContents';import {TableOfContents as SkiaTableOfContents} from '../../docs/skia/TableOfContents';import {TableOfContents as StudioTableOfContents} from '../../docs/studio/TableOfContents';import {TableOfContents as TailwindV4TableOfContents} from '../../docs/tailwind-v4/TableOfContents';@@ -28,7 +29,6 @@ import {TableOfContents as NoiseTableOfContents} from '../TableOfContents/noise'import {TableOfContents as PathsTableOfContents} from '../TableOfContents/paths';import {TableOfContents as PreloadTableOfContents} from '../TableOfContents/preload';import {TableOfContents as RemotionTableOfContents} from '../TableOfContents/remotion';-import {TableOfContents as RendererTableOfContents} from '../TableOfContents/renderer';import {TableOfContents as RiveTableOfContents} from '../TableOfContents/rive';import {TableOfContents as ShapesTableOfContents} from '../TableOfContents/shapes';import {TableOfContents as TransitionsTableOfContents} from '../TableOfContents/transitions';diff --git a/packages/docs/components/TableOfContents/renderer.tsx b/packages/docs/components/TableOfContents/renderer.tsxdeleted file mode 100644index 3f8e17f374..0000000000--- a/packages/docs/components/TableOfContents/renderer.tsx+++ /dev/null@@ -1,75 +0,0 @@-import React from "react";-import { Grid } from "./Grid";-import { TOCItem } from "./TOCItem";--export const TableOfContents: React.FC = () => {- const offthreadComponent = "<OffthreadVideo>";- return (- <div>- <Grid>- <TOCItem link="/docs/renderer/get-compositions">- <strong>getCompositions()</strong>- <div>List available compositions</div>- </TOCItem>- <TOCItem link="/docs/renderer/select-composition">- <strong>selectComposition()</strong>- <div>Get a composition</div>- </TOCItem>- <TOCItem link="/docs/renderer/render-media">- <strong>renderMedia()</strong>- <div>Render a video or audio</div>- </TOCItem>- <TOCItem link="/docs/renderer/render-frames">- <strong>renderFrames()</strong>- <div>Render a series of images</div>- </TOCItem>- <TOCItem link="/docs/renderer/render-still">- <strong>renderStill()</strong>- <div>Render a single image</div>- </TOCItem>- <TOCItem link="/docs/renderer/stitch-frames-to-video">- <strong>stitchFramesToVideo()</strong>- <div>Turn images into a video</div>- </TOCItem>- <TOCItem link="/docs/renderer/open-browser">- <strong>openBrowser()</strong>- <div>Open a Chrome browser to reuse across renders</div>- </TOCItem>- <TOCItem link="/docs/renderer/ensure-browser">- <strong>ensureBrowser()</strong>- <div>Open a Chrome browser to reuse across renders</div>- </TOCItem>- <TOCItem link="/docs/renderer/make-cancel-signal">- <strong>makeCancelSignal()</strong>- <div>Create token to later cancel a render</div>- </TOCItem>- <TOCItem link="/docs/renderer/get-video-metadata">- <strong>getVideoMetadata()</strong>- <div>Get metadata from a video file in Node.js</div>- </TOCItem>- <TOCItem link="/docs/renderer/get-silent-parts">- <strong>getSilentParts()</strong>- <div>Obtain silent portions of a video or audio</div>- </TOCItem>- <TOCItem link="/docs/renderer/ensure-ffmpeg">- <strong style={{ textDecoration: "line-through" }}>- ensureFfmpeg()- </strong>- <div>Check for ffmpeg binary and install if not existing</div>- </TOCItem>- <TOCItem link="/docs/renderer/ensure-ffprobe">- <strong style={{ textDecoration: "line-through" }}>- ensureFfprobe()- </strong>- <div>Check for ffprobe binary and install if not existing</div>- </TOCItem>- <TOCItem link="/docs/renderer/get-can-extract-frames-fast">- <strong style={{ textDecoration: "line-through" }}>- getCanExtractFramesFast()- </strong>- <div>Probes for fast extraction for {offthreadComponent}</div>- </TOCItem>- </Grid>- </div>- );-};diff --git a/packages/docs/docs/distributed-rendering.mdx b/packages/docs/docs/distributed-rendering.mdxnew file mode 100644index 0000000000..1ea2b7bcc3--- /dev/null+++ b/packages/docs/docs/distributed-rendering.mdx@@ -0,0 +1,112 @@+---+image: /generated/articles-docs-distributed-rendering.png+id: distributed-rendering+title: Distributed rendering+crumb: 'Advanced rendering'+---++[Remotion Lambda](/docs/lambda) is our recommended solution if you are looking for a way to split up renders into chunks that run on different machines.++It takes care of a lot of engineering work that you would have to undergo yourself otherwise:++- Orchestrating the distributed render: Defining how work gets split up, keeping track of the progress, merging the chunks, saving it to cloud storage.+- Streaming chunks and progress over one connection to enable smooth progress progress reporting+- Bundling Chrome, Remotion binaries, necessary fonts and a custom Emoji font so they fit in a Lambda function.+- Cleaning up all the created resources after a function invocation to avoid memory leaks when functions are reused.+- Enabling logs, group them by renders and chunks, collect and surface errors, symbolicate stack traces to aid [debugging Lambda renders](/docs/lambda/troubleshooting/debug)+- Supporting multiple media types: Rendering videos, images, GIFs and audio+- Implementing retry mechanisms for nearly all AWS operations (invoking functions, reading and writing objects)+- Warning you about bad configuration (Resources, credentials, permissions, payloads)+- Working around Lambda payload size limits by saving them to S3+- Keeping browser instances open inbetween function invocations so they are ready on the next invocation, but un-referencing them so you don't get billed for it.+- Using special options to seamlessly concatenating video and audio without artifacts showing up+- Implementing clients for Node, Go, Ruby, Python and PHP+- Implementing Webhooks++## You might not want a custom distributed renderer++We think Lambda is the best balance between speed, cost, scalability and ease of use.++Many users are setting the memory too high for their Lambda cost and are unnecessarily causing their renders to be way too expensive.+See how to [optimize a Lambda render](/docs/lambda/optimizing-cost).++Before proceeding with building your own distributed rendering solution, consider how much money you are going to save and weigh it against the cost of implementation, given the complexity.++Also consider how much savings you are getting by Lambda functions shutting down immediately after renders are finished.++## Implementing a distributed renderer++Should you have come to the conclusion that you still need a distributed rendering solution, here is how to do it.+[Remotion Lambda](/docs/lambda) is following the same blueprint as well.++### 1. Splitting up the work++We're calling the machine which orchestrates the render the "main routine".++- You must first determine the length of the video that you want to render by calling [`selectComposition()`](/docs/renderer/select-composition).+- Consider the `frameRange` and `everyNthFrame` options if necessary to determine how many frames you are actually rendering.+- Decide on how many frames you want to render per chunk. **Every chunk must render the same amount of frames, except the last one.** Violating this rule might lead to audio artifacts if you are using the `aac` audio codec.+- Group the render into an array of ranges, which you will use as the [`frameRange`](/docs/renderer/render-media#framerange) argument when rendering chunks.+ Remember that frame ranges start at `0`, and end at `durationInFrames - 1`. Passing values too small or too big will cause an error to be thrown.++### 2. Invoking render functions++- Invoke, in some way, some other machine which calls [`renderMedia()`](/docs/renderer/render-media).+- Pass the [`frameRange`](/docs/renderer/render-media#framerange) of this chunk that you have calculated before to your render call.+- Pass as the [`composition`](/docs/renderer/render-media#composition) the value you retrieved in the main routine.+- Pass any other options to the [`renderMedia()`](/docs/renderer/render-media) call, but you **must pass the same options for every chunk**.+- Ensure you are not caught by HTTP body payload limits that for example Lambda has. Otherwise, you might fail to invoke a render if the input props / resolved props payload is too big.+- Pass the same [`inputProps`](/docs/renderer/render-media#inputprops) that you passed to [`selectComposition()`](/docs/renderer/select-composition#inputprops).+- Set the [`numberOfGifLoops`](/docs/renderer/render-media#numberofgifloops) always to `null` for the chunk.+- Set the [`enforceAudioTrack`](/docs/renderer/render-media#enforceaudiotrack) option always to `true`.+- Set the [`outputLocation`](/docs/renderer/render-media#outputlocation) to a+- Set the [`compositionStart`](/docs/renderer/render-media#compositionstart) to the first frame of overall range of frames that are being rendered.+ - Example 1: If you are rendering a full composition, every [`renderMedia()`](/docs/renderer/render-media) invocation should have `0` as `compositionStart`.+ - Example 2: If your goal is to render a portion of a composition, say `frameRange: [100, 199]`, and you split this up into 4 chunks: `[100, 124], [125, 149], [150, 174], [175, 199]`, every chunk should have `100` as the value for `compositionStart`+- IF you want to render with the codec `h264` (default and recommended), or you want to render a GIF, **set the codec to `h264-ts` instead of `h264`**.+- IF you are rendering:+ - At least 4 frames per chunk AND+ - NOT with audio codec `aac` (which would be default and recommended),+- Then:+ - set the [`audioCodec`](/docs/renderer/render-media#audiocodec) to `pcm-16` instead of the audio codec.+ - set the [`forSeamlessAacConcatenation`](/docs/renderer/render-media#forseamlessaaconcatenation) option to `false`.+- Else:+ - Set the [`audioCodec`](/docs/renderer/render-media#audiocodec) to the same value you would pass to a regular [`renderMedia()`](/docs/renderer/render-media) call, which might be `null`.+ - set the [`forSeamlessAacConcatenation`](/docs/renderer/render-media#forseamlessaaconcatenation) option to `true`.+- If you are rendering audio, use the [`separateAudioTo`](/docs/renderer/render-media#separateaudioto) option to render the audio to a separate file.+- Handle [artifacts](/docs/artifacts) if desired and store them somewhere, or send them to the main routine.+- The parameters [`concurrency`](/docs/renderer/render-media#concurrency) and [`offthreadVideoThreads`](/docs/renderer/render-media#offthreadvideothreads) may be adjusted if desired, but leaving the defaults is also fine.++Following these instructions and passing the right values is crucial for aligning the audio correctly when concatenating it in the end.++Pass the video and audio chunks, and [artifacts](/docs/artifacts) that you have received, to the machine running the main routine.++### 3. Concatenate the chunks++Collect all the audio and video chunks. Once you have all of them, you can call [`combineChunks()`](/docs/renderer/combine-chunks) with the following parameters:++- [`videoFiles`](/docs/combine-chunks#videofiles): An array of absolute paths to video chunks, must be in order.+- [`audioFiles`](/docs/combine-chunks#audiofiles): An array of absolute paths to audio chunks, must be in order.+- [`outputLocation`](/docs/combine-chunks#outputlocation): An absolute file path where the combined chunks are stored.+- [`onProgress`](/docs/combine-chunks#onprogress): See documentation for `combineChunks()`.+- [`codec`](/docs/combine-chunks#codec): The final codec of the media. If you want to render `h264`, you should now pass `h264`, not `h264-ts`.+- [`framesPerChunk`](/docs/combine-chunks#framesperchunk): The amount of frames that were rendered per chunk. The `everyNthFrame` option will be applied only afterwards, so don't calculate it in.+- [`fps`](/docs/combine-chunks#fps): Must be the value of `fps` that you got from [`selectComposition`](/docs/renderer/select-composition).+- [`preferLossless`](/docs/renderer/combine-chunks#preferlossless): Pass it here as well if you passed it to [`renderMedia()`](/docs/renderer/render-media#preferlossless).+- [`compositionDurationInFrames`](/docs/renderer/combine-chunks#compositiondurationinframes): The total duration of the composition, taken from [`selectComposition()`](/docs/renderer/select-composition). Pass the full duration even if you are only rendering a portion of it.+- [`frameRange`](/docs/renderer/combine-chunks#framerange): If you only rendered a portion of a composition, then you must pass that exact frame range here as well. Remember that frame ranges start at `0`, and end at `durationInFrames - 1`. Passing values too small or too big will cause an error to be thrown.++If you have changed the defaults of a [`renderMedia()`](/docs/renderer/render-media) call, you may also have to pass additional parameters:++- [`audioCodec`](/docs/combine-chunks#audiocodec): If you passed a custom `audioCodec` to the render routines, then you should also pass it here. Otherwise, should be `null`. If the default for the video codec would have been `aac` and you passed `pcm-16` to the render routine, you can now pass `null` again.+- [`audioBitrate`](/docs/combine-chunks#audiobitrate): The bitrate that you would target. Since you might have rendered+- [`numberOfGifLoops`](/docs/combine-chunks#numberofgifloops): If you are rendering a GIF, you can now set the number of loops (remember that for each chunk it must be `null`)+- [`everyNthFrame`](/docs/combine-chunks#everynthframe): If you passed it to each [`renderMedia()`](/docs/renderer/render-media) call, pass it here again.++Furthermore, you can use the [`logLevel`](/docs/renderer/combine-chunks#loglevel), [`metadata`](/docs/renderer/combine-chunks#metadata), [`cancelSignal`](/docs/renderer/combine-chunks#cancelsignal) and [`binariesDirectory`](/docs/renderer/combine-chunks#binariesdirectory) options as you would use with [`renderMedia`](/docs/renderer/render-media).++## See also++- [`combineChunks`](/docs/renderer/combine-chunks)+- [`renderMedia`](/docs/renderer/render-media)+- [`selectComposition`](/docs/renderer/select-composition)diff --git a/packages/docs/docs/lambda/cost.mdx b/packages/docs/docs/lambda/cost.mdxindex cd84da1bce..5d9256aed4 100644--- a/packages/docs/docs/lambda/cost.mdx+++ b/packages/docs/docs/lambda/cost.mdx@@ -8,6 +8,10 @@ crumb: 'Lambda'On this page, a few strategies for optimizing the cost of using Remotion Lambda are presented.+## Less memory++Reducing the memory will linearly decrease the cost. Try out different values for the memory when deploying a Lambda function and see how low you can set it without experiencing a crash.+## Lower concurrencyA lot of compute time is spent on warming up the Lambda function, opening browsers, uploading and downloading assets. By using less Lambda functions, less overhead is being produced which will ultimately result in lower cost, however also in slower render speeds. See the [Lambda Concurrency](/docs/lambda/concurrency) page for more information.@@ -20,10 +24,6 @@ Not all AWS regions have the same cost. See the [AWS Lambda](https://aws.amazon.Consider whether your computation will run on every invoked Lambda function. If possible, pre-compute data once and pass it as [input props](/docs/passing-props#passing-input-props-in-the-cli) to the render.-## Less memory--Reducing the memory will linearly decrease the cost. Try out different values for the memory when deploying a Lambda function and see how low you can set it without experiencing a crash.-## Make the render more performantMaking your render more efficient will also reduce the cost of using Lambda. See the [general performance tips](/docs/performance).diff --git a/packages/docs/docs/renderer.mdx b/packages/docs/docs/renderer.mdxindex 8cef8f1d35..ebf944dcaf 100644--- a/packages/docs/docs/renderer.mdx+++ b/packages/docs/docs/renderer.mdx@@ -2,10 +2,10 @@image: /generated/articles-docs-renderer.pngslug: renderersidebar_label: Overview-title: "@remotion/renderer"+title: '@remotion/renderer'----import { TableOfContents } from "../components/TableOfContents/renderer";+import {TableOfContents} from './renderer/TableOfContents';The `@remotion/renderer` package provides APIs for rendering video server-side.The package is also internally used by the Remotion CLI and [Remotion Lambda](/docs/lambda).diff --git a/packages/docs/docs/renderer/TableOfContents.tsx b/packages/docs/docs/renderer/TableOfContents.tsxnew file mode 100644index 0000000000..71551f8ac4--- /dev/null+++ b/packages/docs/docs/renderer/TableOfContents.tsx@@ -0,0 +1,79 @@+import React from 'react';+import {Grid} from '../../components/TableOfContents/Grid';+import {TOCItem} from '../../components/TableOfContents/TOCItem';++export const TableOfContents: React.FC = () => {+ const offthreadComponent = '<OffthreadVideo>';+ return (+ <div>+ <Grid>+ <TOCItem link="/docs/renderer/get-compositions">+ <strong>getCompositions()</strong>+ <div>List available compositions</div>+ </TOCItem>+ <TOCItem link="/docs/renderer/select-composition">+ <strong>selectComposition()</strong>+ <div>Get a composition</div>+ </TOCItem>+ <TOCItem link="/docs/renderer/render-media">+ <strong>renderMedia()</strong>+ <div>Render a video or audio</div>+ </TOCItem>+ <TOCItem link="/docs/renderer/render-frames">+ <strong>renderFrames()</strong>+ <div>Render a series of images</div>+ </TOCItem>+ <TOCItem link="/docs/renderer/render-still">+ <strong>renderStill()</strong>+ <div>Render a single image</div>+ </TOCItem>+ <TOCItem link="/docs/renderer/stitch-frames-to-video">+ <strong>stitchFramesToVideo()</strong>+ <div>Turn images into a video</div>+ </TOCItem>+ <TOCItem link="/docs/renderer/open-browser">+ <strong>openBrowser()</strong>+ <div>Open a Chrome browser to reuse across renders</div>+ </TOCItem>+ <TOCItem link="/docs/renderer/ensure-browser">+ <strong>ensureBrowser()</strong>+ <div>Open a Chrome browser to reuse across renders</div>+ </TOCItem>+ <TOCItem link="/docs/renderer/make-cancel-signal">+ <strong>makeCancelSignal()</strong>+ <div>Create token to later cancel a render</div>+ </TOCItem>+ <TOCItem link="/docs/renderer/get-video-metadata">+ <strong>getVideoMetadata()</strong>+ <div>Get metadata from a video file in Node.js</div>+ </TOCItem>+ <TOCItem link="/docs/renderer/get-silent-parts">+ <strong>getSilentParts()</strong>+ <div>Obtain silent portions of a video or audio</div>+ </TOCItem>+ <TOCItem link="/docs/renderer/combine-chunks">+ <strong>combineChunks()</strong>+ <div>Combine chunks of partial renders</div>+ </TOCItem>+ <TOCItem link="/docs/renderer/ensure-ffmpeg">+ <strong style={{textDecoration: 'line-through'}}>+ ensureFfmpeg()+ </strong>+ <div>Check for ffmpeg binary and install if not existing</div>+ </TOCItem>+ <TOCItem link="/docs/renderer/ensure-ffprobe">+ <strong style={{textDecoration: 'line-through'}}>+ ensureFfprobe()+ </strong>+ <div>Check for ffprobe binary and install if not existing</div>+ </TOCItem>+ <TOCItem link="/docs/renderer/get-can-extract-frames-fast">+ <strong style={{textDecoration: 'line-through'}}>+ getCanExtractFramesFast()+ </strong>+ <div>Probes for fast extraction for {offthreadComponent}</div>+ </TOCItem>+ </Grid>+ </div>+ );+};diff --git a/packages/docs/docs/renderer/combine-chunks.mdx b/packages/docs/docs/renderer/combine-chunks.mdxindex 61cda14724..e0ec696535 100644--- a/packages/docs/docs/renderer/combine-chunks.mdx+++ b/packages/docs/docs/renderer/combine-chunks.mdx@@ -1,4 +1,5 @@---+image: /generated/articles-docs-renderer-combine-chunks.pngid: combine-chunkstitle: combineChunks()crumb: '@remotion/renderer'@@ -8,6 +9,14 @@ crumb: '@remotion/renderer'Combine multiple video or audio chunks into a single output file. This function is useful for decentralized rendering workflows where different parts of a video are rendered separately and need to be combined.+[Remotion Lambda](/docs/lambda) uses this API under the hood to combine chunks that were rendered on individual Lambda functions.++:::note+**Advanced API:** This is a hard-to-use API that most people should not use directly. Misusage of this API might lead to unpredictable behavior and potential audio and video artifacts. If you want a distributed rendering solution, use [`renderMediaOnLambda()`](/docs/lambda/render-media-on-lambda). If you just want to render a video with multithreading enabled, use [`renderMedia()`](/docs/renderer/render-media).+:::++## Example+```tsx twoslash title="combine.mjs"import {combineChunks} from '@remotion/renderer';@@ -26,7 +35,7 @@ await combineChunks({framesPerChunk: 100,audioCodec: 'aac',preferLossless: false,- totalDurationInFrames: 300,+ compositionDurationInFrames: 300,});```@@ -38,37 +47,37 @@ An object with the following properties:_string_-Where to save the output media file. Must be an absolute path or a relative path that will be resolved relative to the current working directory.+Where to save the output media file. Must be an absolute path.### `videoFiles`_string[]_-An array of file paths pointing to the video chunks to be combined. These should be in the correct order for combining.+An array of absolute file paths pointing to the video chunks to be combined. These should be in the correct order for combining.### `audioFiles`_string[]_-An array of file paths pointing to the audio chunks to be combined. These should be in the correct order for combining.+An array of absolute file paths pointing to the audio chunks to be combined. These should be in the correct order for combining.### `codec`_"h264" | "h265" | "vp8" | "vp9" | "mp3" | "aac" | "wav" | "prores" | "h264-mkv" | "gif"_-The codec to use for the output file. Must match the codec used to create the chunks.+The codec to use for the output file. See the distributed rendering guide to see which parameter to set.### `fps`_number_-The frames per second of the video.+The frames per second of the video. Must be set to the `fps` value returned by [`selectComposition()`](/docs/renderer/select-composition).### `framesPerChunk`_number_-The number of frames in each chunk. This is used to calculate timing for proper audio synchronization.+The number of frames in each chunk. All chunks must have the same number of frames, except the last one.### `audioCodec`@@ -80,13 +89,28 @@ Audio codec to use for the output file. If not specified, it will be determined_boolean_-Whether to prefer lossless audio when possible.+Must be the same value that you passed to each [`renderMedia()`](/docs/renderer/render-media) call.-### `totalDurationInFrames`+### `compositionDurationInFrames`_number_-The total duration of the video in frames.+The total duration of the composition. Must be set to the `durationInFrames` value returned by [`selectComposition()`](/docs/renderer/select-composition).+Do not change the value, even if you use the `frameRange` or `everyNthFrame` options.++### `frameRange?`++_number | [number, number] | null - optional_++Like [`frameRange`](/docs/renderer/render-media#framerange) that you would pass to [`renderMedia()`](/docs/renderer/render-media) or [`renderMediaOnLambda()`](/docs/renderer/render-media-on-lambda). The range of frames of which the video exists once all chunks are combined.++### `everyNthFrame?`++_number - optional_++Like [`everyNthFrame`](/docs/renderer/render-media#everynthframe) that you would pass to [`renderMedia()`](/docs/renderer/render-media) or [`renderMediaOnLambda()`](/docs/renderer/render-media-on-lambda).++Must be the same value that you passed to each [`renderMedia()`](/docs/renderer/render-media) call.### `onProgress?`@@ -107,13 +131,13 @@ const onProgress: CombineChunksOnProgress = ({totalProgress, frames}) => {_string | null - optional_-The bitrate to use for audio encoding, for example `"128k"`.+Must be the same value that you passed to each [`renderMedia()`](/docs/renderer/render-media) call.### `numberOfGifLoops?`_number | null - optional_-Only applies when codec is 'gif'. Controls how many times the GIF will loop (use 0 for infinite loop).+Must be the same value that you passed to each [`renderMedia()`](/docs/renderer/render-media) call.### `logLevel?`@@ -135,22 +159,8 @@ A token that allows the combining process to be cancelled. See: [`makeCancelSign### `metadata?`-_Record<string, string> | null - optional_-Metadata to add to the output file, in the format of key-value pairs.-### `frameRange?`--_number | [number, number] | null - optional_--Specify a single frame or a range of frames to be included in the output.--### `everyNthFrame?`--_number - optional_--Include only every nth frame in the output. Useful for GIF rendering. Default is 1 (include all frames).-## Return ValueThe function returns a Promise that resolves when the combining process is complete.diff --git a/packages/docs/docs/renderer/render-media.mdx b/packages/docs/docs/renderer/render-media.mdxindex d6c921a6bb..b5bf8daa28 100644--- a/packages/docs/docs/renderer/render-media.mdx+++ b/packages/docs/docs/renderer/render-media.mdx@@ -471,6 +471,10 @@ _boolean - default `false`_<Options id="for-seamless-aac-concatenation" />+### `compositionStart?`<AvailableFrom v="4.0.279"/>++An option to be used only if implementing a distributed renderer, see [Distributed rendering](/docs/distributed-rendering#2-invoking-render-functions) for what to set it to.+### `onBrowserDownload?`<AvailableFrom v="4.0.137" /><Options id="on-browser-download" />diff --git a/packages/docs/docs/ssr.mdx b/packages/docs/docs/ssr.mdxindex 2f720a025b..fc001b61da 100644--- a/packages/docs/docs/ssr.mdx+++ b/packages/docs/docs/ssr.mdx@@ -6,7 +6,7 @@ crumb: 'The power of'sidebar_label: Overview----import {TableOfContents} from '../components/TableOfContents/renderer';+import {TableOfContents} from './renderer/TableOfContents';Remotion's rendering engine is built with Node.JS, which makes it easy to render a video in the cloud.@@ -78,10 +78,14 @@ jobs:path: out/video.mp4```-<Step>1</Step> Commit the template to a GitHub repository.<br />-<Step>2</Step> On GitHub, click the <code>Actions</code> tab.<br />-<Step>3</Step> Select the <code>Render video</code> workflow on the left.<br />-<Step>4</Step> A <code>Run workflow</code> button should appear. Click it.<br />+<Step>1</Step> Commit the template to a GitHub repository.+<br />+<Step>2</Step> On GitHub, click the <code>Actions</code> tab.+<br />+<Step>3</Step> Select the <code>Render video</code> workflow on the left.+<br />+<Step>4</Step> A <code>Run workflow</code> button should appear. Click it.+<br /><Step>5</Step> Fill in the props of the root component and click <code>Run workflow</code>.<br /><Step>6</Step> After the rendering is finished, you can download the video under <code>Artifacts</code>.<br />diff --git a/packages/docs/sidebars.js b/packages/docs/sidebars.jsindex e9442446d5..e475631d81 100644--- a/packages/docs/sidebars.js+++ b/packages/docs/sidebars.js@@ -152,6 +152,7 @@ module.exports = {'renderer/get-can-extract-frames-fast','renderer/get-video-metadata','renderer/get-silent-parts',+ 'renderer/combine-chunks','renderer/extract-audio',],},@@ -790,6 +791,7 @@ module.exports = {'miscellaneous/cloud-gpu','miscellaneous/cloud-gpu-docker','compare-ssr',+ 'distributed-rendering',],},{diff --git a/packages/docs/src/data/articles.ts b/packages/docs/src/data/articles.tsindex ac34ab569e..db4d12ba34 100644--- a/packages/docs/src/data/articles.ts+++ b/packages/docs/src/data/articles.ts@@ -1034,6 +1034,15 @@ export const articles = [noAi: false,slug: 'deno',},+ {+ id: 'distributed-rendering',+ title: 'Distributed rendering',+ relativePath: 'docs/distributed-rendering.mdx',+ compId: 'articles-docs-distributed-rendering',+ crumb: 'Advanced rendering',+ noAi: false,+ slug: 'distributed-rendering',+ },{id: 'docker',title: 'Dockerizing a Remotion app',@@ -4001,6 +4010,15 @@ export const articles = [noAi: false,slug: 'renderer',},+ {+ id: 'combine-chunks',+ title: 'combineChunks()',+ relativePath: 'docs/renderer/combine-chunks.mdx',+ compId: 'articles-docs-renderer-combine-chunks',+ crumb: '@remotion/renderer',+ noAi: false,+ slug: 'renderer/combine-chunks',+ },{id: 'ensure-browser',title: 'ensureBrowser()',diff --git a/packages/docs/static/generated/articles-docs-distributed-rendering.png b/packages/docs/static/generated/articles-docs-distributed-rendering.pngnew file mode 100644index 0000000000..6b84491970Binary files /dev/null and b/packages/docs/static/generated/articles-docs-distributed-rendering.png differdiff --git a/packages/docs/static/generated/articles-docs-renderer-combine-chunks.png b/packages/docs/static/generated/articles-docs-renderer-combine-chunks.pngnew file mode 100644index 0000000000..c5e4652e07Binary files /dev/null and b/packages/docs/static/generated/articles-docs-renderer-combine-chunks.png differdiff --git a/packages/renderer/src/combine-chunks.ts b/packages/renderer/src/combine-chunks.tsindex 178805ecfe..8b57e06efb 100644--- a/packages/renderer/src/combine-chunks.ts+++ b/packages/renderer/src/combine-chunks.ts@@ -34,9 +34,8 @@ type MandatoryCombineChunksOptions = {videoFiles: string[];fps: number;framesPerChunk: number;- audioCodec: AudioCodec | null;preferLossless: boolean;- totalDurationInFrames: number;+ compositionDurationInFrames: number;};type CombineChunksProgress = {@@ -50,9 +49,9 @@ type OptionalCombineChunksOptions = {onProgress: CombineChunksOnProgress;audioBitrate: string | null;numberOfGifLoops: number | null;- indent: boolean;logLevel: LogLevel;binariesDirectory: string | null;+ audioCodec: AudioCodec | null;cancelSignal: CancelSignal | undefined;metadata: Record<string, string> | null;frameRange: FrameRange | null;@@ -100,8 +99,10 @@ export const internalCombineChunks = async ({preferLossless,everyNthFrame,frameRange,- totalDurationInFrames,-}: AllCombineChunksOptions) => {+ compositionDurationInFrames,+}: AllCombineChunksOptions & {+ indent: boolean;+}) => {const filelistDir = tmpDir(REMOTION_FILELIST_TOKEN);const shouldCreateVideo = !isAudioCodec(codec);@@ -122,7 +123,10 @@ export const internalCombineChunks = async ({framesPerChunk,);- const realFrameRange = getRealFrameRange(totalDurationInFrames, frameRange);+ const realFrameRange = getRealFrameRange(+ compositionDurationInFrames,+ frameRange,+ );const numberOfFrames = getFramesToRender(realFrameRange,@@ -255,12 +259,12 @@ export const combineChunks = (options: CombineChunksOptions) => {return internalCombineChunks({audioBitrate: options.audioBitrate ?? null,numberOfGifLoops: options.numberOfGifLoops ?? null,- indent: options.indent ?? false,+ indent: false,logLevel: options.logLevel ?? 'info',binariesDirectory: options.binariesDirectory ?? null,cancelSignal: options.cancelSignal,metadata: options.metadata ?? null,- audioCodec: options.audioCodec,+ audioCodec: options.audioCodec ?? null,preferLossless: options.preferLossless,audioFiles: options.audioFiles,codec: options.codec,@@ -271,6 +275,6 @@ export const combineChunks = (options: CombineChunksOptions) => {videoFiles: options.videoFiles,everyNthFrame: options.everyNthFrame ?? 1,frameRange: options.frameRange ?? null,- totalDurationInFrames: options.totalDurationInFrames,+ compositionDurationInFrames: options.compositionDurationInFrames,});};diff --git a/packages/renderer/src/render-media.ts b/packages/renderer/src/render-media.tsindex 76d1ae7218..89c5b9d296 100644--- a/packages/renderer/src/render-media.ts+++ b/packages/renderer/src/render-media.ts@@ -185,6 +185,7 @@ export type RenderMediaOptions = Prettify<{binariesDirectory?: string | null;onArtifact?: OnArtifact;metadata?: Record<string, string> | null;+ compositionStart?: number;}> &Partial<MoreRenderMediaOptions>;@@ -905,6 +906,7 @@ export const renderMedia = ({hardwareAcceleration,chromeMode,offthreadVideoThreads,+ compositionStart,}: RenderMediaOptions): Promise<RenderMediaResult> => {const indent = false;const logLevel =@@ -987,8 +989,7 @@ export const renderMedia = ({}),onArtifact: onArtifact ?? null,metadata: metadata ?? null,- // TODO: In the future, introduce this as a public API when launching the distributed rendering API- compositionStart: 0,+ compositionStart: compositionStart ?? 0,hardwareAcceleration: hardwareAcceleration ?? 'disable',chromeMode: chromeMode ?? 'headless-shell',});diff --git a/packages/serverless/src/concat-videos.ts b/packages/serverless/src/concat-videos.tsindex 2cb80a7d5a..fad2705815 100644--- a/packages/serverless/src/concat-videos.ts+++ b/packages/serverless/src/concat-videos.ts@@ -31,7 +31,7 @@ export const concatVideos = async <Provider extends CloudProvider>({insideFunctionSpecifics,everyNthFrame,frameRange,- totalDurationInFrames,+ compositionDurationInFrames,}: {onProgress: CombineChunksOnProgress;codec: ServerlessCodec;@@ -48,7 +48,7 @@ export const concatVideos = async <Provider extends CloudProvider>({preferLossless: boolean;metadata: Record<string, string> | null;insideFunctionSpecifics: InsideFunctionSpecifics<Provider>;- totalDurationInFrames: number;+ compositionDurationInFrames: number;everyNthFrame: number;frameRange: FrameRange | null;}) => {@@ -78,7 +78,7 @@ export const concatVideos = async <Provider extends CloudProvider>({framesPerChunk: framesPerLambda,audioCodec,preferLossless,- totalDurationInFrames,+ compositionDurationInFrames,everyNthFrame,frameRange,});diff --git a/packages/serverless/src/merge-chunks.ts b/packages/serverless/src/merge-chunks.tsindex d4824aba51..0d20f0cffb 100644--- a/packages/serverless/src/merge-chunks.ts+++ b/packages/serverless/src/merge-chunks.ts@@ -89,7 +89,7 @@ export const mergeChunksAndFinishRender = async <preferLossless: options.preferLossless,metadata: options.renderMetadata.metadata,insideFunctionSpecifics: options.insideFunctionSpecifics,- totalDurationInFrames: options.numberOfFrames,+ compositionDurationInFrames: options.numberOfFrames,everyNthFrame: options.everyNthFrame,frameRange: options.frameRange,});