🎥 Make videos programmatically with React
move calculatemetadata function inside the prores + webm sections
Jonny Burger6b7415fcac64
diff --git a/packages/docs/.prettierrc b/packages/docs/.prettierrcnew file mode 100644index 0000000000..37d5071748--- /dev/null+++ b/packages/docs/.prettierrc@@ -0,0 +1,5 @@+{+ "useTabs": false,+ "bracketSpacing": true,+ "tabWidth": 2+}diff --git a/packages/docs/docs/transparent-videos.mdx b/packages/docs/docs/transparent-videos.mdxindex 8a8aa071dd..346c43e181 100644--- a/packages/docs/docs/transparent-videos.mdx+++ b/packages/docs/docs/transparent-videos.mdx@@ -3,10 +3,10 @@ image: /generated/articles-docs-transparent-videos.pngid: transparent-videostitle: Rendering transparent videossidebar_label: Transparent videos-crumb: 'Techniques'+crumb: "Techniques"----import {TransparentVideoDemo} from '../components/TransparentVideoDemo';+import { TransparentVideoDemo } from "../components/TransparentVideoDemo";```twoslash include exampleconst MyVideo: React.FC<{@@ -38,11 +38,11 @@ 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 twoslash-import {Config} from '@remotion/cli/config';+import { Config } from "@remotion/cli/config";-Config.setVideoImageFormat('png');-Config.setPixelFormat('yuva420p');-Config.setCodec('vp8');+Config.setVideoImageFormat("png");+Config.setPixelFormat("yuva420p");+Config.setCodec("vp8");```You can also set the settings on the command line:@@ -51,6 +51,41 @@ You can also set the settings on the command line:--image-format=png --pixel-format=yuva420p --codec=vp8```+or set them as the default export settings for a composition:++```tsx twoslash+import { Composition } from "remotion";++const MyVideo: React.FC = () => {+ return null;+};++type Props = {};+// ---cut---++import { CalculateMetadataFunction } from "remotion";++const calculateMetadata: CalculateMetadataFunction<Props> = async ({+ props,+}) => {+ return {+ defaultCodec: "vp8",+ defaultVideoImageFormat: "png",+ defaultPixelFormat: "yuva420p",+ };+};++<Composition+ id="my-video"+ component={MyVideo}+ durationInFrames={150}+ fps={30}+ width={1920}+ height={1080}+ calculateMetadata={calculateMetadata}+/>;+```+## Creating a ProRes video with Alpha channelsIf you want to export a transparent video for use in another video editing program, Apple ProRes is a more suitable option.@@ -59,12 +94,12 @@ 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-xq`. The pixel format must be `yuva444p10le`.```tsx twoslash-import {Config} from '@remotion/cli/config';+import { Config } from "@remotion/cli/config";-Config.setVideoImageFormat('png');-Config.setPixelFormat('yuva444p10le');-Config.setCodec('prores');-Config.setProResProfile('4444');+Config.setVideoImageFormat("png");+Config.setPixelFormat("yuva444p10le");+Config.setCodec("prores");+Config.setProResProfile("4444");```You can also set the settings on the command line:@@ -73,107 +108,60 @@ You can also set the settings on the command line:--image-format=png --pixel-format=yuva444p10le --codec=prores --prores-profile=4444```-## Enabling transparency when using `<OffthreadVideo>`--By default, the [`<OffthreadVideo>`](/docs/offthreadvideo) does not add an alpha layer during export.-Add the [`transparent`](/docs/offthreadvideo#transparent) prop to flag that the video has an alpha channel.-This slightly reduces the performance of the render.--## Creating a fallback version--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:+or set them as the default export settings for a composition:```tsx twoslash-// @include: example-MyVideo-```--It's a good practice to set a default when defining the composition:+import { Composition } from "remotion";+const MyVideo: React.FC<Props> = () => {+ return null;+};-```tsx twoslash {7-9}-import {Composition} from 'remotion';-// @include: example-MyVideo+type Props = {};// ---cut---+import { CalculateMetadataFunction } from "remotion";++const calculateMetadata: CalculateMetadataFunction<Props> = async ({+ props,+}) => {+ return {+ defaultCodec: "prores",+ defaultVideoImageFormat: "png",+ defaultPixelFormat: "yuva444p10le",+ defaultProResProfile: "4444",+ };+};+<Compositionid="my-video"component={MyVideo}+ durationInFrames={150}+ fps={30}width={1920}height={1080}- fps={30}- durationInFrames={150}- defaultProps={{- transparent: true,- }}+ calculateMetadata={calculateMetadata}/>;```-## Exporting transparent videos by default--Instead of specifying transparency settings via CLI flags or `remotion.config.ts`, you can use [`calculateMetadata`](/docs/dynamic-metadata) to set them as defaults for a specific composition. This approach has several benefits:+## Enabling transparency when using `<OffthreadVideo>`-- **No CLI flags needed** - Settings are embedded in the composition-- **Works everywhere** - Studio, CLI, and programmatic rendering all use the same defaults-- **Composition-specific** - Different compositions can have different transparency settings-- **Type-safe** - Settings are validated at the composition level+By default, the [`<OffthreadVideo>`](/docs/offthreadvideo) does not add an alpha layer during export.+Add the [`transparent`](/docs/offthreadvideo#transparent) prop to flag that the video has an alpha channel.+This slightly reduces the performance of the render.-### Setting default codec and pixel format+## Creating a fallback version-Use `calculateMetadata` to return `defaultCodec` and configure the render settings:+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 twoslash-import {CalculateMetadataFunction} from 'remotion';--type Props = {- transparent: boolean;-};--const calculateMetadata: CalculateMetadataFunction<Props> = async ({- props,-}) => {- // Only set transparent defaults if the transparent prop is true- if (props.transparent) {- return {- defaultCodec: 'vp9',- // Note: imageFormat and pixelFormat must be set via Config or CLI- // They cannot be set via calculateMetadata- };- }-- return {};-};+// @include: example-MyVideo```-### Complete example with transparency--Here's a complete example showing how to set up a composition with transparency as the default:--```tsx twoslash {18-26}-import {Composition} from 'remotion';-import type {CalculateMetadataFunction} from 'remotion';--const MyVideo: React.FC<{transparent: boolean}> = ({transparent}) => {- return (- <div- style={{- backgroundColor: transparent ? undefined : 'white',- flex: 1,- }}- >- {/* Your content */}- </div>- );-};--const calculateMetadata: CalculateMetadataFunction<{- transparent: boolean;-}> = async ({props}) => {- if (props.transparent) {- return {- defaultCodec: 'vp9',- };- }- return {};-};+It's a good practice to set a default when defining the composition:+```tsx twoslash {7-9}+import { Composition } from "remotion";+// @include: example-MyVideo+// ---cut---<Compositionid="my-video"component={MyVideo}@@ -184,27 +172,9 @@ const calculateMetadata: CalculateMetadataFunction<{defaultProps={{transparent: true,}}- calculateMetadata={calculateMetadata}/>;```-When rendering, you still need to specify the image format and pixel format:--```bash-remotion render --image-format=png --pixel-format=yuva420p my-video video.webm-```--Or set them in `remotion.config.ts`:--```tsx-import {Config} from '@remotion/cli/config';--Config.setVideoImageFormat('png');-Config.setPixelFormat('yuva420p');-```--The codec will automatically be `vp9` based on the `calculateMetadata` function, so you don't need to specify `--codec=vp9` on the command line.-You can then have separate render commands in your package.json:```json