Skip to content

🎥 Make videos programmatically with React

add `isRendering` to `calculateMetadata` function args

Igor Samokhovetsa928b6099e5f
diff --git a/packages/core/src/Composition.tsx b/packages/core/src/Composition.tsx
index c93b4179cf..ff5e1a1e90 100644
--- a/packages/core/src/Composition.tsx
+++ b/packages/core/src/Composition.tsx
@@ -55,6 +55,7 @@ export type CalculateMetadataFunction<T extends Record<string, unknown>> =
props: T;
abortSignal: AbortSignal;
compositionId: string;
+ isRendering: boolean;
}) => Promise<CalcMetadataReturnType<T>> | CalcMetadataReturnType<T>;
type OptionalDimensions<
diff --git a/packages/core/src/resolve-video-config.ts b/packages/core/src/resolve-video-config.ts
index a270c1b1df..bee946c12e 100644
--- a/packages/core/src/resolve-video-config.ts
+++ b/packages/core/src/resolve-video-config.ts
@@ -3,6 +3,7 @@ import type {
CalcMetadataReturnType,
CalculateMetadataFunction,
} from './Composition.js';
+import {getRemotionEnvironment} from './get-remotion-environment.js';
import {serializeThenDeserializeInStudio} from './input-props-serialization.js';
import type {InferProps} from './props-if-has-props.js';
import {validateCodec} from './validation/validate-default-codec.js';
@@ -111,6 +112,7 @@ export const resolveVideoConfig = ({
props: originalProps,
abortSignal: signal,
compositionId,
+ isRendering: getRemotionEnvironment().isRendering,
})
: null;
diff --git a/packages/docs/docs/calculate-metadata.mdx b/packages/docs/docs/calculate-metadata.mdx
index c526db8da2..0276881999 100644
--- a/packages/docs/docs/calculate-metadata.mdx
+++ b/packages/docs/docs/calculate-metadata.mdx
@@ -53,7 +53,7 @@ import React from 'react';
import {CalculateMetadataFunction, Composition} from 'remotion';
import {MyComponent, MyComponentProps} from './MyComp';
-const calculateMetadata: CalculateMetadataFunction<MyComponentProps> = ({props, defaultProps, abortSignal}) => {
+const calculateMetadata: CalculateMetadataFunction<MyComponentProps> = ({props, defaultProps, abortSignal, isRendering}) => {
return {
// Change the metadata
durationInFrames: props.duration,
@@ -93,6 +93,7 @@ As argument, you get an object with the following properties:
- `props`: The [resolved props](/docs/props-resolution), taking input props into account.
- `abortSignal`: An [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) which you can use to abort network requests if [the default props have been changed](/docs/data-fetching#aborting-stale-requests) in the meanwhile.
- `compositionId` (_available from v4.0.98_): The ID of the current composition
+- `isRendering` (_available from v4.0.342_): A boolean indicating whether the function is being called during rendering (`true`) or in other contexts like the Studio (`false`)
The function must return an pure JSON-serializable object, which can contain the following properties:
diff --git a/packages/docs/docs/get-remotion-environment.mdx b/packages/docs/docs/get-remotion-environment.mdx
index 6e9837ea82..212296ac8e 100644
--- a/packages/docs/docs/get-remotion-environment.mdx
+++ b/packages/docs/docs/get-remotion-environment.mdx
@@ -15,7 +15,7 @@ Consider using the [`useRemotionEnvironment()`](/docs/use-remotion-environment)
It returns an object with the following properties:
- `isStudio`: Whether the function got called in the [Remotion Studio](/docs/cli/studio).
-- `isRendering`: Whether the function got called in a render.
+- `isRendering`: Whether the function got called in a render. Also available in the [`calculateMetadata()`](/docs/calculate-metadata) function.
- `isPlayer`: Whether a [`<Player>`](/docs/player) is mounted on the current page.
- `isReadOnlyStudio`: Whether in a [statically deployed studio](https://www.remotion.dev/docs/studio/deploy-static), where the [`@remotion/studio`](/docs/studio/api) APIs cannot be used (_available from v4.0.238_)