🎥 Make videos programmatically with React
more docs
Jonny Burgerb683fcc2d0d0
diff --git a/packages/docs/docs/composition.md b/packages/docs/docs/composition.mdindex d5e48579b8..ac1ea88482 100644--- a/packages/docs/docs/composition.md+++ b/packages/docs/docs/composition.md@@ -81,7 +81,11 @@ Type your components using the `React.FC<{}>` type and the `defaultProps` prop wPassing huge objects to `defaultProps` can be slow. [Learn how to avoid it.](/docs/troubleshooting/defaultprops-too-big):::-### `calculateMetadata()`+### `calculateMetadata`++TODO++### `schema`TODOdiff --git a/packages/docs/docs/dynamic-metadata-v2.md b/packages/docs/docs/dynamic-metadata-v2.mddeleted file mode 100644index 6920b88537..0000000000--- a/packages/docs/docs/dynamic-metadata-v2.md+++ /dev/null@@ -1,39 +0,0 @@-----id: dynamic-metadata-v2-title: Dynamic duration, FPS & dimensions-crumb: "How To"------To dynamically set the `width`, `height`, `durationInFrames` or `fps` of a video, you can use the `calculateMetadata()` option of a [`<Composition>`](/docs/composition).--```tsx twoslash title="Root.tsx"-import React from "react";-const MyComp: React.FC = () => null;--import { Composition } from "remotion";--// ---cut----<Composition- id="my-comp"- component={MyComp}- durationInFrames={100}- fps={30}- width={1080}- height={1080}- calculateMetadata={async ({ defaultProps }) => {- return {- fps: 30,- width: 1080,- height: 1080,- durationInFrames: 100,- props: defaultProps,- };- }}-/>;-```--## Data loading--## How props flow--## In a `<Player>`diff --git a/packages/docs/docs/parametrized-rendering.md b/packages/docs/docs/parametrized-rendering.mdindex ea12e94e11..6b295bd584 100644--- a/packages/docs/docs/parametrized-rendering.md+++ b/packages/docs/docs/parametrized-rendering.md@@ -75,152 +75,31 @@ Default props are useful so you don't preview your video with no data. [Default## Define a schema<AvailableFrom v="4.0.0"/>-You can use [Zod](https://github.com/colinhacks/zod) to define a typesafe schema for your composition.--Install Zod using:--import Tabs from '@theme/Tabs';-import TabItem from '@theme/TabItem';--<Tabs-defaultValue="npm"-values={[-{ label: 'npm', value: 'npm', },-{ label: 'yarn', value: 'yarn', },-{ label: 'pnpm', value: 'pnpm', },-]-}>-<TabItem value="npm">--```bash-npm i zod @remotion/zod-types-```-- </TabItem>-- <TabItem value="yarn">--```bash-yarn add zod @remotion/zod-types-```-- </TabItem>-- <TabItem value="pnpm">--```bash-pnpm i zod @remotion/zod-types-```-- </TabItem>-</Tabs>--```tsx twoslash title="MyComp.tsx"-import { z } from "zod";--export const myCompSchema = z.object({- propOne: z.string(),- propTwo: z.string(),-});--export const MyComp: React.FC<z.infer<typeof myCompSchema>> = ({- propOne,- propTwo,-}) => {- return (- <div>- props: {propOne}, {propTwo}- </div>- );-};-```--To define a schema, create a type using Zod and infer the props in your component using `z.infer`.-Then, export the schema, and import it in your root file:--```tsx twoslash title="src/Root.tsx" {14-18}-// @filename: MyComponent.tsx-import React from "react";-import { z } from "zod";--export const myCompSchema = z.object({- propOne: z.string(),- propTwo: z.string(),-});--export const MyComponent: React.FC<z.infer<typeof myCompSchema>> = ({- propOne,- propTwo,-}) => {- return (- <div>- <h1>{propOne}</h1>- <h2>{propTwo}</h2>- </div>- );-};--// @filename: Root.tsx-// organize-imports-ignore-// ---cut----import React from "react";-import { Composition } from "remotion";-import { MyComponent, myCompSchema } from "./MyComponent";--export const RemotionRoot: React.FC = () => {- return (- <Composition- id="my-video"- component={MyComponent}- durationInFrames={100}- fps={30}- width={1920}- height={1080}- schema={myCompSchema}- defaultProps={{- propOne: "Hello World",- propTwo: "Welcome to Remotion",- }}- />- );-};-```--If you define a schema, you will be able to visually manipulate the props in the Remotion Preview and render a parametrized video by filling out a form.--:::note-The schema must use an object `{}` as the top-level type because React props are passed as an object.-:::+You can use [Zod](https://github.com/colinhacks/zod) to [define a typesafe schema for your composition](/docs/schemas).## Input props-Input props are props that are passed in externally while rendering that can replace or override the default props.+Input props are props that are passed in while invoking a render that can replace or override the default props.:::note-Input props must be an object and serializable.+Input props must be an object and serializable to JSON.:::### Passing input props in the CLI-When rendering (for example using the `npm run build` script defined in `package.json`), you can override some or all default props by passing a CLI flag. It must be either valid JSON or a path to a file that contains valid JSON. Using this technique, type safety cannot be guaranteed.--**Using inline JSON**+When rendering, you can override default props by passing a [CLI](/docs/cli/render) flag. It must be either valid JSON or a path to a file that contains valid JSON.-```bash+```bash title="Using inline JSON"npx remotion render HelloWorld out/helloworld.mp4 --props='{"propOne": "Hi", "propTwo": 10}'```-**Using a file path:**--```bash+```bash title="Using a file path"npx remotion render HelloWorld out/helloworld.mp4 --props=./path/to/props.json```-[See also: CLI flags](/docs/cli)--### Passing input props when server rendering+### Passing input props when using server-side rendering-When server-rendering using [`renderMedia()`](/docs/renderer/render-media), you can pass props using the [`inputProps`](/docs/renderer/render-media#inputprops) option:+When server-rendering using [`renderMedia()`](/docs/renderer/render-media) or [`renderMediaOnLambda()`](/docs/lambda/rendermediaonlambda), you can pass props using the [`inputProps`](/docs/renderer/render-media#inputprops) option:```tsx twoslash {8-10}// @module: esnext@@ -270,14 +149,13 @@ workflow_dispatch:### Retrieve input props-Input props are passed to the component of your composition directly and you can access as regular React component props.+Input props are passed to the [`component`](/docs/composition#component) of your [`<Composition>`](/docs/composition) directly and you can access them like regular React component props.-_Available since v2.0._: You can also use the `getInputProps()` function to retrieve props that you have given as an input. This is useful if you need to retrieve the props in a position where you are not inside your component, such as when determining the video duration, dimensions or frame rate.+If you need the input props in your root component, use the [`getInputProps()`](/docs/get-input-props) function to retrieve input props.-## You can still use components as normal+## You can still use components normally-Even if you have registered a component as a composition,-you can still use it normally in your React markup and pass its props directly. Default props don't apply in this case.+Even if a component is registered as a composition, you can still use it like a regular React component and pass the props directly:```tsx twoslash// @include: example-MyComponent@@ -285,6 +163,32 @@ you can still use it normally in your React markup and pass its props directly.<MyComponent propOne="hi" propTwo={10} />```+This is useful if you want to concatenate multiple scenes together. You can use a [`<Series>`](/docs/series) to play two components after each other:++```tsx twoslash title="ChainedScenes.tsx"+// @include: example-MyComponent+const AnotherComponent: React.FC = () => {+ return null;+};+// ---cut---+import { Series } from "remotion";++const ChainedScenes = () => {+ return (+ <Series>+ <Series.Sequence durationInFrames={90}>+ <MyComponent propOne="hi" propTwo={10} />+ </Series.Sequence>+ <Series.Sequence durationInFrames={90}>+ <AnotherComponent />+ </Series.Sequence>+ </Series>+ );+};+```++You may then register this "Master" component as an additional [`<Composition>`](/docs/the-fundamentals#compositions).+## See also- [Avoid huge payloads for `defaultProps`](/docs/troubleshooting/defaultprops-too-big)diff --git a/packages/docs/docs/schemas.md b/packages/docs/docs/schemas.mdnew file mode 100644index 0000000000..deb71cadf5--- /dev/null+++ b/packages/docs/docs/schemas.md@@ -0,0 +1,148 @@+---+id: schemas+title: Defining a schema for your props+sidebar_label: Defining a schema+crumb: "How To"+---++As an alternative to [using TypeScript types](/docs/parametrized-rendering) to define the shape of the props your composition accepts, you may use [Zod](https://zod.dev/) to define a schema for your props. You may do so if you want to:++<Step>1</Step> Validate the props during rendering. [TODO] <br/>+<Step>2</Step> Edit the props visually in the Remotion Preview.++## Prerequisites++If you want to use this feature, install `zod` and `@remotion/zod-types` for Remotion-specific types:++import Tabs from '@theme/Tabs';+import TabItem from '@theme/TabItem';++<Tabs+defaultValue="npm"+values={[+{ label: 'npm', value: 'npm', },+{ label: 'yarn', value: 'yarn', },+{ label: 'pnpm', value: 'pnpm', },+]+}>+<TabItem value="npm">++```bash+npm i zod @remotion/zod-types+```++ </TabItem>++ <TabItem value="yarn">++```bash+yarn add zod @remotion/zod-types+```++ </TabItem>++ <TabItem value="pnpm">++```bash+pnpm i zod @remotion/zod-types+```++ </TabItem>+</Tabs>++## Defining a schema++To define a schema for your props, use [`z.object()`](https://zod.dev/?id=objects):++```tsx twoslash+import { z } from "zod";++export const myCompSchema = z.object({+ propOne: z.string(),+ propTwo: z.string(),+});+```++Using `z.infer()`, you can turn the schema into a type:++```tsx twoslash+import { z } from "zod";++export const myCompSchema = z.object({+ propOne: z.string(),+ propTwo: z.string(),+});+// ---cut---+export const MyComp: React.FC<z.infer<typeof myCompSchema>> = ({+ propOne,+ propTwo,+}) => {+ return (+ <div>+ props: {propOne}, {propTwo}+ </div>+ );+};+```++## Adding a schema to your composition++Use the [`schema`](/docs/composition#schema) prop to attach the schema to your [`<Composition>`](/docs/composition). Remotion will require you to specify matching [`defaultProps`](/docs/composition#schema).++```tsx twoslash title="src/Root.tsx" {3,14-18}+// @filename: MyComponent.tsx+import React from "react";+import { z } from "zod";++export const myCompSchema = z.object({+ propOne: z.string(),+ propTwo: z.string(),+});++export const MyComponent: React.FC<z.infer<typeof myCompSchema>> = ({+ propOne,+ propTwo,+}) => {+ return (+ <div>+ <h1>{propOne}</h1>+ <h2>{propTwo}</h2>+ </div>+ );+};++// @filename: Root.tsx+// organize-imports-ignore+// ---cut---+import React from "react";+import { Composition } from "remotion";+import { MyComponent, myCompSchema } from "./MyComponent";++export const RemotionRoot: React.FC = () => {+ return (+ <Composition+ id="my-video"+ component={MyComponent}+ durationInFrames={100}+ fps={30}+ width={1920}+ height={1080}+ schema={myCompSchema}+ defaultProps={{+ propOne: "Hello World",+ propTwo: "Welcome to Remotion",+ }}+ />+ );+};+```++## Supported types++All schemas that are supported by [Zod](https://zod.dev/) are supported by Remotion.++Remotion requires that the top-level type is a `z.object()`, because the collection of props of a React component is always an object.++## Editing props visually++When you have defined a schema for your props, you can [edit them visually in the Remotion Preview](/docs/visual-editing). This is useful if you want to quickly try out different values for your props.diff --git a/packages/docs/sidebars.js b/packages/docs/sidebars.jsindex bd5d3448af..9ed8d4b884 100644--- a/packages/docs/sidebars.js+++ b/packages/docs/sidebars.js@@ -374,7 +374,7 @@ module.exports = {{type: "category",label: "Parametrized videos",- items: ["parametrized-rendering", "props-resolution"],+ items: ["parametrized-rendering", "schemas", "props-resolution"],},"use-img-and-iframe","using-audio",@@ -385,7 +385,6 @@ module.exports = {"encoding","transparent-videos","dynamic-metadata",- "dynamic-metadata-v2","ssr","webpack","tailwind",