Skip to content

🎥 Make videos programmatically with React

stitchFramesToVideo docs

Jonny Burger52ca48c7aa70
diff --git a/packages/docs/docs/config.md b/packages/docs/docs/config.md
index bf08a40af2..7be49fba7d 100644
--- a/packages/docs/docs/config.md
+++ b/packages/docs/docs/config.md
@@ -5,6 +5,8 @@ title: Configuration file
To configure Remotion, create a `remotion.config.ts` file in the root of your Remotion project.
+These options will apply to CLI commands such as `npm start` and `npm run build`, but have no effect in the Node.JS API.
+
You can control several behaviors of Remotion here.
```tsx
@@ -96,7 +98,11 @@ Try to set your concurrency to `os.cpus().length` to all the threads available o
_Available from Version 1.4._
-Determines which in which image format to render the frames. Either `jpeg` _(default since v1.1)_ or `png`. PNG is considerably slower, but supports transparency.
+Determines which in which image format to render the frames. Either:
+
+- `jpeg` - the fastest option (default from v1.1)
+- `png` - slower, but supports transparency
+- `none` - don't render images, just calculate audio information (available from v2.0)
```tsx
Config.Rendering.setImageFormat('png')
diff --git a/packages/docs/docs/get-compositions.md b/packages/docs/docs/get-compositions.md
index 624760d840..d11431e388 100644
--- a/packages/docs/docs/get-compositions.md
+++ b/packages/docs/docs/get-compositions.md
@@ -18,17 +18,21 @@ const getCompositions: (bundle: string, options: {
A string pointing to a Webpack bundle generated by `@remotion/bundler`.
-### `options`
+### `options?`
_optional_
An object containing one or more of the following options:
-#### `inputProps`
+#### `inputProps?`
+
+_optional_
Define custom props that can be retrieved using [`getInputProps()`](/docs/get-input-props) at runtime. Useful for [setting a dynamic duration or dimensions](/docs/dynamic-metadata) for your video.
-#### `browserInstance`
+#### `browserInstance?`
+
+_optional_
An already open Puppeteer [`Browser`](https://pptr.dev/#?product=Puppeteer&version=main&show=api-class-browser) instance. Reusing a browser across multiple function calls can speed up the rendering process. You are responsible for opening and closing the browser yourself. If you don't specify this option, a new browser will be opened and closed at the end.
@@ -57,3 +61,4 @@ Returns a promise that resolves to an array of available compositions. Example v
- [Server-Side rendering](/docs/ssr)
- [renderFrames()](/docs/render-frames)
+- [stitchFramesToVideo()](/docs/stitch-frames-to-video)
diff --git a/packages/docs/docs/render-frames.md b/packages/docs/docs/render-frames.md
index a1fb568164..a52929761b 100644
--- a/packages/docs/docs/render-frames.md
+++ b/packages/docs/docs/render-frames.md
@@ -81,13 +81,13 @@ A `string` which must be either `png`, `jpeg` or `none`.
- Choose `png` if you want your image sequence to have an alpha channel (for transparency).
- Choose `none` if you only want to render audio.
-### `parallelism`
+### `parallelism?`
_optional_
A `number` specifying how many frames should be rendered in parallel or `null` to let Remotion decide based on the CPU of the host machine. Default is half of the CPU threads available.
-### `quality`
+### `quality?`
_optional_
@@ -95,19 +95,19 @@ Sets the quality of the generated JPEG images. Must be an integer between 0 and
Only applies if `imageFormat` is `'jpeg'`, otherwise this option is invalid.
-### `frameRange`
+### `frameRange?`
_optional_
Specify a single frame (passing a `number`) or a range of frames (passsing a tuple `[number, number]`) to be rendered. By passing `null` (default) all frames of a composition get rendered.
-### `dumpBrowserLogs`
+### `dumpBrowserLogs?`
_optional_
Passes the `dumpio` flag to Puppeteer which will log all browser logs to the console. Useful for debugging. `boolean` flag, default is `false`.
-### `puppeteerInstance`
+### `puppeteerInstance?`
_optional_
@@ -124,3 +124,4 @@ A promise resolving to an object containing the following properties:
- [Server-Side rendering](/docs/ssr)
- [getCompositions()](/docs/get-compositions)
+- [stitchFramesToVideo()](/docs/stitch-frames-to-video)
diff --git a/packages/docs/docs/stitch-frames-to-video.md b/packages/docs/docs/stitch-frames-to-video.md
new file mode 100644
index 0000000000..3e615fa670
--- /dev/null
+++ b/packages/docs/docs/stitch-frames-to-video.md
@@ -0,0 +1,123 @@
+---
+id: stitch-frames-to-video
+title: stitchFramesToVideo()
+---
+
+Takes a series of images and audio information generated by [`renderFrames()`](/docs/render-frames) and encodes it to a video.
+
+```ts
+const stitchFramesToVideo: (options: {
+ dir: string;
+ fps: number;
+ width: number;
+ height: number;
+ outputLocation: string;
+ force: boolean;
+ assetsInfo: RenderAssetInfo;
+ imageFormat?: 'png' | 'jpeg' | 'none';
+ pixelFormat?: PixelFormat;
+ codec?: Codec;
+ crf?: number;
+ onProgress?: (progress: number) => void;
+ onDownload?: (src: number) => void;
+ verbose?: boolean;
+}) => Promise<void>
+```
+
+## Arguments
+
+An object with the following properties:
+
+### `dir`
+
+A `string` containing the absolute path of the directory where the frames are located. This will be the directory where the `ffmepg` command will be executed.
+
+### `fps`
+
+A `number` specifying the desired frame rate of the output video.
+
+### `width`
+
+A `number` specifying the desired output width in pixels for the video.
+
+### `height`
+
+A `number` specifying the desired output height in pixels for the video.
+
+### `outputLocation`
+
+An absolute path specify where the output file should be written to.
+
+### `force`
+
+Whether in case of an existing file in `outputLocation` it should be overwritten. Type `boolean`.
+
+### `assetsInfo`
+
+Information about the audio mix. This is part of the return value of [renderFrames()](/docs/render-frames#return-value).
+
+### `imageFormat?`
+
+_optional_
+
+Either `jpeg`, `png` or `none`. It should match what you passed into the [renderFrames()](/docs/render-frames#imageformat) function.
+
+:::info
+For backwards compatibility, if you omit this parameter, it will use `'png'`. Make sure to explicitly set this to `jpeg` to take advantage of faster rendering.
+:::
+
+### `pixelFormat?`
+
+_optional_
+
+Sets the pixel format. See [here](/docs/config#setpixelformat) for available values. The default is `yuv420p`.
+
+### `codec?`
+
+_optional_
+
+Set a codec. See the [encoding guide](/docs/encoding) for available values and guidance on which one to choose. The default is `h264`.
+
+### `crf?`
+
+_optional_
+
+The constant rate factor of the output, a parameter which controls quality. See [here](/docs/config#setcrf) for more information about this parameter. Default is depending on the codec.
+
+### `onProgress?`
+
+_optional_
+
+Callback function which informs about the encoding progress. The `progress` value is a `number` between 0 and 1.
+
+```ts
+const onProgress = (progress: number) => {
+ console.log(`Encoding progress: ${progress * 100}%`)
+}
+```
+
+### `onDownload?`
+
+_optional_
+
+Notifies when a remote asset needs to be downloaded in order to extract the audio track.
+
+```ts
+const onDownload = (src: string) => {
+ console.log(`Downloading ${src}...`)
+}
+```
+
+### `verbose`
+
+A boolean value that when set to `true`, will log all kinds of debug information. Default `false`
+
+## Return value
+
+`stitchFramesToVideo()` returns a promise which resolves to nothing. If everything goes well, the output will be placed in `outputLocation`.
+
+## See also
+
+- [Server-Side rendering](/docs/ssr)
+- [getCompositions()](/docs/get-compositions)
+- [renderFrames()](/docs/render-frames)
diff --git a/packages/docs/sidebars.js b/packages/docs/sidebars.js
index 0a03748391..a6b28424e7 100644
--- a/packages/docs/sidebars.js
+++ b/packages/docs/sidebars.js
@@ -33,12 +33,12 @@ module.exports = {
"legacy-babel",
],
},
+ "cli",
+ "config",
{
type: "category",
label: "API - Core",
items: [
- "cli",
- "config",
"continue-render",
"delay-render",
"interpolate",
@@ -75,7 +75,7 @@ module.exports = {
{
type: "category",
label: "API - @remotion/renderer",
- items: ["get-compositions", "render-frames"],
+ items: ["get-compositions", "render-frames", "stitch-frames-to-video"],
},
"2-0-migration",
"license",
diff --git a/packages/renderer/src/stitcher.ts b/packages/renderer/src/stitcher.ts
index 233f3c3656..d51334af0b 100644
--- a/packages/renderer/src/stitcher.ts
+++ b/packages/renderer/src/stitcher.ts
@@ -56,13 +56,15 @@ export const stitchFramesToVideo = async (options: {
height: number;
outputLocation: string;
force: boolean;
+ assetsInfo: RenderAssetInfo;
+ // TODO: Let's make this parameter mandatory in the next major release
imageFormat?: ImageFormat;
pixelFormat?: PixelFormat;
codec?: Codec;
crf?: number;
- assetsInfo: RenderAssetInfo;
+ // TODO: Do we want a parallelism flag for stitcher?
parallelism?: number | null;
- onProgress?: (num: number) => void;
+ onProgress?: (progress: number) => void;
onDownload?: (src: string) => void;
verbose?: boolean;
}): Promise<void> => {