🎥 Make videos programmatically with React
docs: migrate 14 docs to twoslash
Frencoc2b821866b4c
diff --git a/packages/docs/docs/audio-visualization.md b/packages/docs/docs/audio-visualization.mdindex 54dc6de73f..47269cfd57 100644--- a/packages/docs/docs/audio-visualization.md+++ b/packages/docs/docs/audio-visualization.md@@ -23,7 +23,7 @@ Using the [`visualizeAudio()`](/docs/visualize-audio) API, you can get an audioRefer to the documentation of the above mentioned functions to learn more.-```tsx+```tsx twoslashimport {useCurrentFrame, useVideoConfig, Audio} from 'remotion';import {useAudioData, visualizeAudio} from '@remotion/media-utils';import music from './music.mp3';diff --git a/packages/docs/docs/config.mdx b/packages/docs/docs/config.mdxindex 99700d4dc9..6f2616d3a5 100644--- a/packages/docs/docs/config.mdx+++ b/packages/docs/docs/config.mdx@@ -9,10 +9,10 @@ These options will apply to CLI commands such as `npm start` and `npm run build`You can control several behaviors of Remotion here.-```tsx+```ts twoslashimport {Config} from 'remotion';-Config.Rendering.Concurrency(8);+Config.Rendering.setConcurrency(8);Config.Output.setPixelFormat('yuv444p');Config.Output.setCodec('h265');```@@ -25,9 +25,15 @@ _Available from Version 1.1._Allows you to insert your custom Webpack config. [See the page about custom Webpack configs](/docs/webpack) for more information.-```tsx+```ts twoslash+import {Config} from 'remotion';+// ---cut---Config.Bundling.overrideWebpackConfig((currentConfiguration) => {// Return a new Webpack configuration+ return {+ ...currentConfiguration,+ // new configuration+ };});```@@ -37,7 +43,9 @@ _Available from Version 2.0._Enable or disable webpack caching. Default is `true` which will make the Webpack step in the first run a bit slower but will massively speed up subsequent runs. We recommend to keep this option enabled in all cases and encourage to report issues on Github if you encounter some.-```tsx+```ts twoslash+import {Config} from 'remotion';+// ---cut---Config.Bundling.setCachingEnabled(false);```@@ -49,7 +57,9 @@ Define on which port Remotion should start it's HTTP servers during preview andBy default, Remotion will try to find a free port.If you specify a port, but it's not available, Remotion will throw an error.-```tsx+```ts twoslash+import {Config} from 'remotion';+// ---cut---Config.Bundling.setPort(3003);```@@ -69,7 +79,9 @@ Acceptable values:- `info` (_default_): Default output - besides errors and warnings, prints progress and output location.- `verbose`: All of the above, plus browser logs and other debug info.-```tsx+```ts twoslash+import {Config} from 'remotion';+// ---cut---Config.Log.setLevel('verbose');```@@ -83,7 +95,9 @@ _Available from Version 2.1.10._Set how many tracks are being displayed in the timeline at most. This does not affect your video, just the amount of tracks shown when previewing. Default `15`.-```ts+```ts twoslash+import {Config} from 'remotion';+// ---cut---Config.Preview.setMaxTimelineTracks(20);```@@ -95,7 +109,9 @@ _Available from Version 1.5._Set a custom Chrome or Chromium executable path. By default Remotion will try to find an existing version of Chrome on your system and if not found, it will download one. This flag is useful if you don't have Chrome installed in a standard location and you want to prevent downloading an additional browser or need [support for the H264 codec](/docs/video#codec-support).-```ts+```ts twoslash+import {Config} from 'remotion';+// ---cut---Config.Puppeteer.setBrowserExecutable('/usr/bin/google-chrome-stable');```@@ -108,7 +124,9 @@ The [command line flag](/docs/cli#--browser-executable) `--browser-executable` wSets how many Puppeteer instances will work on rendering your video in parallel.Default: `null`, meaning **half of the threads** available on your CPU.-```ts+```ts twoslash+import {Config} from 'remotion';+// ---cut---Config.Rendering.setConcurrency(8)```@@ -128,7 +146,9 @@ Determines which in which image format to render the frames. Either:- `png` - slower, but supports transparency- `none` - don't render images, just calculate audio information (available from v2.0)-```tsx+```ts twoslash+import {Config} from 'remotion';+// ---cut---Config.Rendering.setImageFormat('png')```@@ -140,13 +160,17 @@ _Available from Version 2.0._Pass a number to render a still frame or a tuple to render a subset of a video. The frame sequence is zero-indexed.-```tsx+```ts twoslash+import {Config} from 'remotion';+// ---cut---Config.Rendering.setFrameRange(90); // To render only the 91st frame```or-```tsx+```ts twoslash+import {Config} from 'remotion';+// ---cut---Config.Rendering.setFrameRange([0, 20]); // Render a video only containing the first 21 frames```@@ -156,7 +180,9 @@ The [command line flag](/docs/cli#--frames) `--frames` will take precedence overThe JPEG quality of each frame. Must be a number between 0 and 100. Will not work if you render PNG frames. [Default: 80](https://github.com/chromium/chromium/blob/99314be8152e688bafbbf9a615536bdbb289ea87/headless/lib/browser/protocol/headless_handler.cc#L32).-```tsx+```ts twoslash+import {Config} from 'remotion';+// ---cut---Config.Rendering.setQuality(90);```@@ -166,7 +192,9 @@ The [command line flag](/docs/cli#--quality) `--quality` will take precedence ovSet a custom location for a [`.env`](https://www.npmjs.com/package/dotenv) file. You can specify an absolute path or a relative path in which case it gets resolved based on the current working directory.-```tsx+```ts twoslash+import {Config} from 'remotion';+// ---cut---Config.Rendering.setDotEnvLocation('.my-env')```@@ -178,7 +206,9 @@ The [command line flag](/docs/cli#--env-file) `--env-file` will take precedenceSet this to `false` to prevent overwriting Remotion outputs when they already exists.-```tsx+```ts twoslash+import {Config} from 'remotion';+// ---cut---Config.Output.setOverwriteOutput(false)```@@ -193,7 +223,9 @@ In version 1.x, the default behavior was inverse - Remotion would not override bControls the pixel format in FFMPEG. [Read more about it here.](https://trac.ffmpeg.org/wiki/Chroma%20Subsampling) Acceptable values: `yuv420p`, `yuv422p`, `yuv444p`, `yuv420p10le`, `yuv422p10le`, `yuv444p10le`. Since v1.4, `yuva420p` is also supported for transparent WebM videos. Since v2.1.7, `yuva444p10le` is also supported for transparent ProRes videosDefault value: `yuv420p`-```tsx+```ts twoslash+import {Config} from 'remotion';+// ---cut---Config.Output.setPixelFormat('yuv420p')```@@ -215,7 +247,9 @@ Choose one of the supported codecs: `h264` _(default)_, `h265`, `vp8`, `vp9`.- `aac` will export audio only as an AAC file _(available from v2.0)_- `mkv` will export using H264 codec, MKV container format and WAV audio codec. _(available from v2.1.12)_-```tsx+```ts twoslash+import {Config} from 'remotion';+// ---cut---Config.Output.setCodec('h265');```@@ -232,7 +266,9 @@ Possible values: `4444-xq`, `4444`, `hq`, `standard`, `light`, `proxy`.See [here](https://video.stackexchange.com/a/14715) for explanation of possible values.Default: `hq`-```tsx+```ts twoslash+import {Config} from 'remotion';+// ---cut---Config.Output.setProResProfile('4444');```@@ -246,7 +282,9 @@ _Available from Version 1.4._Set to true if you want to output an image sequence instead of a video.-```tsx+```ts twoslash+import {Config} from 'remotion';+// ---cut---Config.Output.setImageSequence(true);```@@ -258,7 +296,9 @@ _Deprecated_. Use `setCodec()` and `setImageSequence()` instead.Either `'mp4'` or `'png-sequence'`.-```tsx+```ts twoslash+import {Config} from 'remotion';+// ---cut---Config.Output.setOutputFormat('mp4');```@@ -285,7 +325,9 @@ The range is exponential, so increasing the CRF value +6 results in roughly halfChoose the highest CRF value that still provides an acceptable quality. If the output looks good, then try a higher value. If it looks bad, choose a lower value.-```tsx+```ts twoslash+import {Config} from 'remotion';+// ---cut---Config.Output.setCrf(16);```diff --git a/packages/docs/docs/data-fetching.md b/packages/docs/docs/data-fetching.mdindex 4ca0eddcc9..dcfd6fc03a 100644--- a/packages/docs/docs/data-fetching.md+++ b/packages/docs/docs/data-fetching.md@@ -9,11 +9,10 @@ One of the most groundbreaking things about Remotion is that you can fetch dataThere are two functions, [`delayRender`](/docs/delay-render) and [`continueRender`](/docs/continue-render), which you can use to tell Remotion to not yet render the frame. If you want to asynchronously render a frame, you should call `delayRender()` as soon as possible, before the window `onload` event is fired. The function returns a handle that you need to give Remotion the green light to render later using `continueRender()`.-```tsx+```tsx twoslashimport {useEffect, useState} from 'react';import {continueRender, delayRender} from 'remotion';-export const MyVideo = () => {const [data, setData] = useState(null);const [handle] = useState(() => delayRender());diff --git a/packages/docs/docs/dynamic-import.md b/packages/docs/docs/dynamic-import.mdindex 1adce7c9b4..a2c9222ebc 100644--- a/packages/docs/docs/dynamic-import.md+++ b/packages/docs/docs/dynamic-import.md@@ -25,8 +25,7 @@ my-video/Note that the following pattern doesn't work:-```tsx-import React from 'react';+```tsx twoslashimport {Img, useCurrentFrame} from 'remotion';export const DynamicImports: React.FC = () => {@@ -42,8 +41,7 @@ Error: Cannot find module './image0.png'However the following example **does** work:-```tsx-import React from 'react';+```tsx twoslashimport {Img, useCurrentFrame} from 'remotion';export const DynamicImports: React.FC = () => {@@ -60,7 +58,7 @@ Please read [the Webpack documentation page](https://webpack.js.org/api/module-mLet's imagine a scenario where the asset that should be imported is completely unknown and will be read at runtime, for example through an [input prop](/docs/get-input-props):-```tsx+```tsx twoslashimport {Img, getInputProps} from 'remotion';const DynamicAsset: React.FC = () => {@@ -72,7 +70,7 @@ const DynamicAsset: React.FC = () => {This cannot work because Webpack has no ideas which assets it has to bundle. Therefore the import has to fail.Like above, you can force Webpack to bundle the whole assets folder by putting an expression inside the `require()` statement:-```tsx+```tsx twoslashimport {Img, getInputProps} from 'remotion';const DynamicAsset: React.FC = () => {@@ -92,7 +90,7 @@ You can use the following workaround that relies on the fact that Remotion creat2. Copy a new asset into this folder.3. Rely on the fact that the asset is available via the static HTTP server. Since you only want this during rendering, use the `process.env.NODE_ENV === 'production'` statement to differentiate between development and rendering.-```tsx+```tsx twoslashimport {Img, getInputProps} from 'remotion';export const DynamicAsset: React.FC = () => {@@ -118,7 +116,7 @@ As a last resort, you can spin up your own static HTTP server and import the assnpx serve --cors ./src```-```tsx+```tsx twoslashimport {Img, getInputProps} from 'remotion';const HttpAsset: React.FC = () => {diff --git a/packages/docs/docs/dynamic-metadata.md b/packages/docs/docs/dynamic-metadata.mdindex a032962b68..16d5c528e9 100644--- a/packages/docs/docs/dynamic-metadata.md+++ b/packages/docs/docs/dynamic-metadata.md@@ -3,6 +3,19 @@ id: dynamic-metadatatitle: Dynamic duration, FPS & dimensions---+```twoslash include example+export const MyComponent: React.FC<{+ duration: number;+}> = ({duration}) => {+ return (+ <div>props: {duration}</div>+ );+}+// - MyComponent+export const VideoTesting: React.FC = () => <></>+// - VideoTesting+```+## Change metadata based on input props_Available since v2.0._@@ -12,15 +25,19 @@ Using [Input props](parametrized-rendering) you can customize the content of youUse the `getInputProps()` method to retrieve the props that you have passed as an input.For example if you have passed `--props='{"hello": "world"}'` as a command line flag, you can read the value in your Remotion project like this:-```tsx+```tsx twoslash+// It's better to fake type here than to import any+const getInputProps = () => ({hello: "world"} as const)+// ---cut---const {hello} = getInputProps()console.log(hello) // "world"```You can use this technique to dynamically change the frame rate, dimensions or duration of our video as you render. For example, if you pass `--props={"duration": 100}` during rendering, the video will be 100 frames long if you define your composition as followed:-```tsx-+```tsx twoslash+// @include: example-MyComponent+// ---cut---import {getInputProps, Composition} from 'remotion';const inputProps = getInputProps()@@ -35,7 +52,7 @@ export const Index = () => {height={1080}fps={30}durationInFrames={inputProps?.duration ?? 20}- >+ /></>)}@@ -53,7 +70,11 @@ Sometimes you need to calculate metadata programmatically in a non-synchronous mIn this example, we fetch the duration of "Big Buck Bunny" and use it to make our video just that long:-```tsx+```tsx twoslash+// @include: example-VideoTesting+import {useState, useEffect} from "react";+import {Composition, delayRender, continueRender} from "remotion";+// ---cut---export const Index: React.FC = () => {const [handle] = useState(() => delayRender());const [duration, setDuration] = useState(1);@@ -88,7 +109,10 @@ export const Index: React.FC = () => {Both `getCompositions()` and `renderFrames()` functions accept an `inputProps` object as a parameter.-```tsx+```tsx twoslash+import {getCompositions} from "@remotion/renderer"+const bundled: string = ''+// ---cut---getCompositions(bundled, {inputProps: {custom: 'data'@@ -96,7 +120,11 @@ getCompositions(bundled, {})```-```tsx+```tsx twoslash+import {renderFrames as rf} from "@remotion/renderer"+type RenderFramesOptions = Parameters<typeof rf>[0]+const renderFrames = (options: Partial<RenderFramesOptions>): void => {}+// ---cut---renderFrames({// ...inputProps: {diff --git a/packages/docs/docs/importing-assets.md b/packages/docs/docs/importing-assets.mdindex 4e5d46869b..157bb8d77c 100644--- a/packages/docs/docs/importing-assets.md+++ b/packages/docs/docs/importing-assets.md@@ -14,7 +14,7 @@ Remotion allows you to include several types of files in your project:Require images using an `import` statement and pass them to the [`<Img/>`](/docs/img) tag.-```tsx+```tsx twoslashimport {Img} from 'remotion';import logo from './logo.png'@@ -29,7 +29,7 @@ export const MyComp: React.FC = () => {If you have a series of images, for example exported from another program like After Effects or Rotato, you can use a dynamic `require` statement to import the images as they are needed.-```tsx+```tsx twoslashimport {useCurrentFrame} from 'remotion';/*@@ -59,7 +59,7 @@ Avoid writing a require statement that requires a file that doesn't exist. If yoImport your files using an import statement. Use the [`<Video />`/docs/video) component to keep the timeline and your video in sync.-```tsx+```tsx twoslashimport {Video} from 'remotion';import vid from './vid.webm'@@ -76,7 +76,7 @@ Be aware that if you are rendering using Chromium (as opposed to Chrome), the coImport your audio using an `import` statement and pass it to the [`<Audio/ >`](/docs/audio) component.-```tsx+```tsx twoslashimport {Audio} from 'remotion';import tune from './tune.mp3'diff --git a/packages/docs/docs/legacy-babel-loader.md b/packages/docs/docs/legacy-babel-loader.mdindex ce856bdcee..f0459e5ec6 100644--- a/packages/docs/docs/legacy-babel-loader.md+++ b/packages/docs/docs/legacy-babel-loader.md@@ -13,7 +13,7 @@ This should not be necessary in general, it is encouraged to [report issues](htt## Example-console+`console````npm i @remotion/babel-loader@@ -21,7 +21,9 @@ npm i @remotion/babel-loader`remotion.config.ts`-```tsx+```ts twoslash+import {Config} from 'remotion'+// ---cut---import {replaceLoadersWithBabel} from '@remotion/babel-loader';Config.Bundling.overrideWebpackConfig((currentConfiguration) => {diff --git a/packages/docs/docs/overwriting-webpack-config.md b/packages/docs/docs/overwriting-webpack-config.mdindex 5e74c4a6d3..74e0126706 100644--- a/packages/docs/docs/overwriting-webpack-config.md+++ b/packages/docs/docs/overwriting-webpack-config.md@@ -17,7 +17,8 @@ In your `remotion.config.ts` file, you can call `Config.Bundler.overrideWebpackCOverriding the Webpack config uses the reducer pattern - pass in a function that takes as it's argument a Webpack configuration and return a new Webpack configuration.-```tsx+```ts twoslash+// @errors: 2532 2488import {Config} from 'remotion';Config.Bundling.overrideWebpackConfig((currentConfiguration) => {@@ -44,41 +45,42 @@ Using the reducer pattern will help with type safety, give you auto-complete, enThe following `remotion.config.ts` file shows how to enable support for MDX. Installation of `mdx-loader babel-loader @babel/preset-env @babel/preset-react` is required.-```ts+```ts twoslash+import { Config } from "remotion";+// ---cut---Config.Bundling.overrideWebpackConfig((currentConfiguration) => {- return {- ...currentConfiguration,- module: {- ...currentConfiguration.module,- rules: [- ...(currentConfiguration.module?.rules- ? currentConfiguration.module.rules- : []),- {- test: /\.mdx?$/,- use: [- {- loader: 'babel-loader',- options: {- presets: [- '@babel/preset-env',- [- '@babel/preset-react',- {- runtime: 'automatic',- },- ],- ],- },- },- 'mdx-loader',- ],- },- ],- },- };+ return {+ ...currentConfiguration,+ module: {+ ...currentConfiguration.module,+ rules: [+ ...(currentConfiguration.module?.rules+ ? currentConfiguration.module.rules+ : []),+ {+ test: /\.mdx?$/,+ use: [+ {+ loader: 'babel-loader',+ options: {+ presets: [+ '@babel/preset-env',+ [+ '@babel/preset-react',+ {+ runtime: 'automatic',+ },+ ],+ ],+ },+ },+ 'mdx-loader',+ ],+ },+ ],+ },+ };});-```:::info@@ -115,7 +117,9 @@ yarn add postcss-loader postcss postcss-preset-env tailwindcss autoprefixer2. Add the following to your [`remotion.config.ts`](/docs/config) file:-```ts+```ts twoslash+import {Config} from "remotion";+// ---cut---Config.Bundling.overrideWebpackConfig((currentConfiguration) => {return {...currentConfiguration,@@ -203,36 +207,38 @@ yarn add sass sass-loader2. Add the following to your [`remotion.config.ts`](/docs/config) file:-```tsx+```ts twoslash+import {Config} from "remotion";+// ---cut---Config.Bundling.overrideWebpackConfig((currentConfiguration) => {- return {- ...currentConfiguration,- module: {- ...currentConfiguration.module,- rules: [- ...(currentConfiguration.module?.rules- ? currentConfiguration.module.rules- : []),- {- test: /\.s[ac]ss$/i,- use: [- {- loader: 'style-loader',- },- {- loader: 'css-loader',- },- {- loader: 'sass-loader',- options: {- sourceMap: true,- },- },- ],- },- ],- },- };+ return {+ ...currentConfiguration,+ module: {+ ...currentConfiguration.module,+ rules: [+ ...(currentConfiguration.module?.rules+ ? currentConfiguration.module.rules+ : []),+ {+ test: /\.s[ac]ss$/i,+ use: [+ {+ loader: 'style-loader',+ },+ {+ loader: 'css-loader',+ },+ {+ loader: 'sass-loader',+ options: {+ sourceMap: true,+ },+ },+ ],+ },+ ],+ },+ };});```diff --git a/packages/docs/docs/parametrized-rendering.md b/packages/docs/docs/parametrized-rendering.mdindex b90daea8ca..d09ddb732d 100644--- a/packages/docs/docs/parametrized-rendering.md+++ b/packages/docs/docs/parametrized-rendering.md@@ -3,13 +3,7 @@ id: parametrized-renderingtitle: Parametrized rendering----Parametrized rendering is the idea of creating a video template once and then render as many videos as you want with different parameters. Just like in regular React, we use props to reuse and customize components!--## Defining accepted props--To define which props your video accepts, simply give your component the `React.FC` type and pass in a generic argument describing the shape of the props you want to accept.--```tsx {2-3}+```twoslash include exampleexport const MyComponent: React.FC<{propOne: string;propTwo: number;@@ -18,6 +12,17 @@ export const MyComponent: React.FC<{<div>props: {propOne}, {propTwo}</div>);}+// - MyComponent+```++Parametrized rendering is the idea of creating a video template once and then render as many videos as you want with different parameters. Just like in regular React, we use props to reuse and customize components!++## Defining accepted props++To define which props your video accepts, simply give your component the `React.FC` type and pass in a generic argument describing the shape of the props you want to accept.++```tsx twoslash {1-2}+// @include: example-MyComponent```## Define default props@@ -121,6 +126,8 @@ _Available since v2.0._: You can also use the `getInputProps()` function to retrEven if you have registered a component as a sequence,you can still use it as normal in your videos and pass it's props directly. Default props don't apply in this case.-```tsx+```tsx twoslash+// @include: example-MyComponent+// ---cut---<MyComponent propOne="hi" propTwo={10} />```diff --git a/packages/docs/docs/sequences.md b/packages/docs/docs/sequences.mdindex 7eea0a7f82..adeffddb1a 100644--- a/packages/docs/docs/sequences.md+++ b/packages/docs/docs/sequences.md@@ -4,11 +4,7 @@ title: Reuse components using Sequencessidebar_label: Reuse components----Let's say we want to show two titles that both fade in after each other.--In order to make a title reusable, we first factor it out into it's own component.--```tsx+```twoslash include exampleimport {useCurrentFrame, interpolate} from 'remotion';const Title: React.FC<{title: string;}> = ({title}) => {@@ -19,6 +15,15 @@ const Title: React.FC<{title: string;}> = ({title}) => {<div style={{opacity}}>{title}</div>)}+// - Title+```++Let's say we want to show two titles that both fade in after each other.++In order to make a title reusable, we first factor it out into it's own component.++```tsx twoslash+// @include: example-Titleexport const MyVideo = () => {return (@@ -31,17 +36,10 @@ export const MyVideo = () => {Now we can use the `<Sequence>` component to limit the duration of the first title and time-shift the appearance of the second title.-```tsx-import {useCurrentFrame, interpolate, Sequence} from 'remotion';--const Title: React.FC<{title: string;}> = ({title}) => {- const frame = useCurrentFrame();- const opacity = interpolate(frame, [0, 20], [0, 1], {extrapolateRight: 'clamp'});-- return (- <div style={{opacity, fontSize: 80}} >{title}</div>- )-}+```tsx twoslash+// @include: example-Title+// ---cut---+import {Sequence} from 'remotion';export const MyVideo = () => {return (diff --git a/packages/docs/docs/transparent-videos.mdx b/packages/docs/docs/transparent-videos.mdxindex dec0b0fcc5..0ad1441cf8 100644--- a/packages/docs/docs/transparent-videos.mdx+++ b/packages/docs/docs/transparent-videos.mdx@@ -5,6 +5,19 @@ title: Transparent videosimport { TransparentVideoDemo } from "../components/TransparentVideoDemo";+```twoslash include example+const MyVideo: React.FC<{+ transparent: boolean;+}> = ({transparent}) => {+ return (+ <div style={{backgroundColor: transparent ? undefined : 'white', flex: 1}}>+ {/* Omit opaque background based on `transparent` prop */}+ </div>+ )+}+// - MyVideo+```+Chrome and Firefox support WebM videos with alpha channels. That means that on these browsers, you can embed videos with transparency.If you are lucky enough to visit the website in one of those supported web browsers, check it out:@@ -21,7 +34,7 @@ In order to create a transparent video, you need at least version 1.4 of RemotioIf you want to set these options and persist them, add this to your `remotion.config.ts` file (create it if you don't yet have one);-```tsx+```tsx twoslashimport {Config} from 'remotion';Config.Rendering.setImageFormat('png');@@ -42,7 +55,7 @@ ProRes is supported by Final Cut Pro, Adobe Premiere and Davinci Resolve.Supported since v2.1.7, you can set the codec to `prores` and choose a ProRes profile with alpha support: Either: `4444` or `4444-hq`. The pixel format must be `yuva444p10le`.-```tsx+```tsx twoslashimport {Config} from 'remotion';Config.Rendering.setImageFormat('png');@@ -61,21 +74,16 @@ You can also set the settings on the command line:Given the poor browser support, consider making two versions of a video, one with alpha channel, and an opaque video as a fallback. You can achieve this in Remotion using standard React props:-```tsx {2}-const MyVideo: React.FC<{- transparent: boolean;-}> = ({transparent}) => {- return (- <div style={{backgroundColor: transparent ? undefined : 'white', flex: 1}}>- {/* Omit opaque background based on `transparent` prop */}- </div>- )-}+```tsx twoslash {1}+// @include: example-MyVideo```It's a good practice to set a default when defining the composition:-```tsx {8-10}+```tsx twoslash {7-9}+import { Composition } from "remotion";+// @include: example-MyVideo+// ---cut---<Compositionid="my-video"component={MyVideo}diff --git a/packages/docs/docs/using-audio.md b/packages/docs/docs/using-audio.mdindex 48ebce9404..c1b6a47bb5 100644--- a/packages/docs/docs/using-audio.md+++ b/packages/docs/docs/using-audio.md@@ -13,7 +13,7 @@ import audio from './audio.mp3'You may add an [`<Audio/>`](/docs/audio) tag to your composition to add sound to it.-```tsx {8}+```tsx twoslash {7}import {Audio} from 'remotion';import audio from './audio.mp3'@@ -38,7 +38,7 @@ You can mix multiple tracks together by adding more audio tags.You can use the [`<Sequence />`](/docs/sequence) API to cut and trim audio.As a convienience, the `<Audio />` tag supports the `startFrom` and `endAt` props.-```tsx {10-11}+```tsx twoslash {9-10}import {Audio} from 'remotion';import audio from './audio.mp3'@@ -61,7 +61,7 @@ export const MyVideo = () => {Use a `<Sequence>` with a positive `from` attribute to delay the audio from playing.In the following example, the audio will start playing (from the beginning) after 100 frames.-```tsx {8}+```tsx twoslash {8}import {Audio, Sequence} from 'remotion';import audio from './audio.mp3'@@ -70,7 +70,7 @@ export const MyVideo = () => {<div><div>Hello World!</div><Sequence from={100} durationInFrames={Infinity}>- <Audio src={audio}>+ <Audio src={audio} /></Sequence></div>)@@ -82,7 +82,7 @@ export const MyVideo = () => {You can use the `volume` prop to control the volume.**The simplest way is to pass a number between 0 and 1**. `1` is the maximum volume, values over 1 are allowed but will not increase the volume further. Volumes under 0 are not allowed.-```tsx {8}+```tsx twoslash {7}import {Audio} from 'remotion';import audio from './audio.mp3'@@ -90,7 +90,7 @@ export const MyVideo = () => {return (<div><div>Hello World!</div>- <Audio src={audio} volume={0.5}>+ <Audio src={audio} volume={0.5} /></div>)}@@ -98,7 +98,7 @@ export const MyVideo = () => {You can also **change volume over time**, in this example we are using the [interpolate()](/docs/interpolate) function. Note that because values below 0 are not allowed, we need to set the `extrapolateLeft: 'clamp'` option to ensure no negative values.-```tsx {10}+```tsx twoslash {9}import {Audio, interpolate, useCurrentFrame} from 'remotion';import audio from './audio.mp3'@@ -108,7 +108,7 @@ export const MyVideo = () => {return (<div><div>Hello World!</div>- <Audio src={audio} volume={interpolate(frame, [0, 30], [0,1], {extrapolateLeft: 'clamp'})}>+ <Audio src={audio} volume={interpolate(frame, [0, 30], [0,1], {extrapolateLeft: 'clamp'})} /></div>)}@@ -116,7 +116,7 @@ export const MyVideo = () => {You may also pass a **callback function** that returns the volume based an arbitrary frame number. This has the benefit that Remotion is able to **draw a volume curve in the timeline**!-```tsx {8}+```tsx twoslash {7}import {Audio, interpolate} from 'remotion';import audio from './audio.mp3'@@ -124,7 +124,7 @@ export const MyVideo = () => {return (<div><div>Hello World!</div>- <Audio src={audio} volume={f => interpolate(f, [0, 30], [0,1], {extrapolateLeft: 'clamp'})}>+ <Audio src={audio} volume={f => interpolate(f, [0, 30], [0,1], {extrapolateLeft: 'clamp'})} /></div>)}@@ -136,7 +136,7 @@ Note that if you pass in a callback function, the first frame on which audio isYou may pass in the `muted` and it may change over time. When `muted` is true, audio will be omitted at that time. In the following example, we are muting the track between frame 40 and 60.-```tsx {10}+```tsx twoslash {9}import {Audio, interpolate, useCurrentFrame} from 'remotion';import audio from './audio.mp3'@@ -146,7 +146,7 @@ export const MyVideo = () => {return (<div><div>Hello World!</div>- <Audio src={audio} muted={frame >= 40 && frame <= 60}>+ <Audio src={audio} muted={frame >= 40 && frame <= 60} /></div>)}diff --git a/packages/docs/docs/using-fonts.md b/packages/docs/docs/using-fonts.mdindex 29370f52bd..cabe8b9e91 100644--- a/packages/docs/docs/using-fonts.md+++ b/packages/docs/docs/using-fonts.md@@ -15,7 +15,7 @@ You can use fonts by loading them in a CSS file using @font-face. Web fonts ofte`MyComp.tsx`:-```tsx+```tsx twoslashimport './font.css'const MyComp: React.FC = () => {@@ -44,7 +44,7 @@ Google Web Fonts by default appends `?display=swap` to their URLs. Make sure to`MyComp.tsx`:-```tsx+```tsx twoslashimport './font.css'const MyComp: React.FC = () => {diff --git a/packages/docs/docs/using-randomness.md b/packages/docs/docs/using-randomness.mdindex 2a033e3778..b73d064fd8 100644--- a/packages/docs/docs/using-randomness.md+++ b/packages/docs/docs/using-randomness.md@@ -5,17 +5,20 @@ title: Using randomnessThe following thing is an anti-pattern in Remotion:-```tsx+```tsx twoslash+import { useState } from "react";+// ---cut---const MyComp: React.FC = () => {- const randomValues = useState(() => {- return new Array(10).fill(true).map((a, i) => {+ const [randomValues] = useState(() =>+ new Array(10).fill(true).map((a, i) => {return {x: Math.random(),y: Math.random(),};- });+ }));// Do something with coordinates+ return <></>;}```@@ -25,7 +28,9 @@ While this will work during preview, it will break while rendering. The reason iUse the [`random()`](/docs/random) API from Remotion to get deterministic pseudorandom values. Pass in a seed (number or string) and as long as the seed is the same, the return value will be the same.-```tsx {7,8}+```tsx twoslash {6, 7}+import { useState } from "react";+// ---cut---import {random} from 'remotion';const MyComp: React.FC = () => {@@ -36,6 +41,8 @@ const MyComp: React.FC = () => {y: random(`y-${i}`),};});++ return <></>}```