Skip to content

🎥 Make videos programmatically with React

`@remotion/studio`: Infer schemas from default props

JonnyBurger3af35f58be54
diff --git a/packages/studio/src/components/InspectorPanel/CompositionInspector.tsx b/packages/studio/src/components/InspectorPanel/CompositionInspector.tsx
index 8e642b7f1f..c6275cc098 100644
--- a/packages/studio/src/components/InspectorPanel/CompositionInspector.tsx
+++ b/packages/studio/src/components/InspectorPanel/CompositionInspector.tsx
@@ -18,7 +18,7 @@ import {SolidIcon} from '../../icons/solid';
import {FilmIcon} from '../../icons/video';
import {VisualControlsContext} from '../../visual-controls/VisualControls';
import {DefaultPropsEditor} from '../DefaultPropsEditor';
-import {useZodIfPossible} from '../get-zod-if-possible';
+import {useZodIfPossible, useZodTypesIfPossible} from '../get-zod-if-possible';
import {VERTICAL_SCROLLBAR_CLASSNAME} from '../Menu/is-menu-item';
import {showNotification} from '../Notifications/NotificationCenter';
import {ObserveDefaultPropsContext} from '../ObserveDefaultPropsContext';
@@ -27,6 +27,7 @@ import {
useDataEditorWarnings,
useDataEditorWarningVisibility,
} from '../RenderModal/DataEditor';
+import {resolveCompositionSchema} from '../RenderModal/SchemaEditor/infer-zod-schema-from-value';
import type {AnyZodSchema} from '../RenderModal/SchemaEditor/zod-schema-type';
import {getZodSchemaType} from '../RenderModal/SchemaEditor/zod-schema-type';
import type {UpdaterFunction} from '../RenderModal/SchemaEditor/ZodSwitch';
@@ -221,6 +222,7 @@ const CompositionDefaultPropsSection: React.FC<{
readonly setDefaultProps: UpdaterFunction<Record<string, unknown>>;
}> = ({composition, currentDefaultProps, readOnlyStudio, setDefaultProps}) => {
const z = useZodIfPossible();
+ const zodTypes = useZodTypesIfPossible();
const canSaveDefaultProps = useContext(ObserveDefaultPropsContext);
const [defaultPropsMode, setDefaultPropsMode] =
useState<DataEditorMode>('schema');
@@ -251,22 +253,21 @@ const CompositionDefaultPropsSection: React.FC<{
];
}, [defaultPropsMode]);
+ const schema = useMemo(() => {
+ return resolveCompositionSchema({
+ explicitSchema: composition.schema,
+ defaultProps: composition.defaultProps ?? {},
+ z,
+ zodTypes,
+ });
+ }, [composition.defaultProps, composition.schema, z, zodTypes]);
const canShowDefaultPropsSection = useMemo(() => {
- if (!z || !composition.schema || !composition.defaultProps) {
+ if (schema === 'no-schema' || schema === 'no-zod') {
return false;
}
- if (
- !(
- typeof (composition.schema as {safeParse?: unknown}).safeParse ===
- 'function'
- )
- ) {
- return false;
- }
-
- return getZodSchemaType(composition.schema as AnyZodSchema) !== 'any';
- }, [composition.defaultProps, composition.schema, z]);
+ return getZodSchemaType(schema as AnyZodSchema) !== 'any';
+ }, [schema]);
const {setShowWarning, showWarning} = useDataEditorWarningVisibility();
const {warnings: defaultPropsWarnings} = useDataEditorWarnings({
canSaveDefaultProps: canSaveDefaultProps?.canSaveDefaultProps ?? null,
diff --git a/packages/studio/src/components/OptionsPanel.tsx b/packages/studio/src/components/OptionsPanel.tsx
index a6e440250b..3408bff9db 100644
--- a/packages/studio/src/components/OptionsPanel.tsx
+++ b/packages/studio/src/components/OptionsPanel.tsx
@@ -15,8 +15,8 @@ import {showNotification} from './Notifications/NotificationCenter';
import {optionsSidebarTabs} from './options-sidebar-tabs';
import {deepEqual} from './RenderModal/SchemaEditor/deep-equal';
import {extractEnumJsonPaths} from './RenderModal/SchemaEditor/extract-enum-json-paths';
+import {resolveCompositionSchema} from './RenderModal/SchemaEditor/infer-zod-schema-from-value';
import {SchemaResetButton} from './RenderModal/SchemaEditor/SchemaResetButton';
-import type {AnyZodSchema} from './RenderModal/SchemaEditor/zod-schema-type';
import type {UpdaterFunction} from './RenderModal/SchemaEditor/ZodSwitch';
import {RenderQueue} from './RenderQueue';
import {callUpdateDefaultPropsApi} from './RenderQueue/actions';
@@ -113,31 +113,17 @@ export const OptionsPanel: React.FC<{
const noComposition = !composition;
const schema = useMemo(() => {
- if (!z) {
- return 'no-zod' as const;
- }
-
if (noComposition) {
return 'no-composition' as const;
}
- if (!composition.schema) {
- return 'no-schema' as const;
- }
-
- if (
- !(
- typeof (composition.schema as {safeParse?: unknown}).safeParse ===
- 'function'
- )
- ) {
- throw new Error(
- 'A value which is not a Zod schema was passed to `schema`',
- );
- }
-
- return composition.schema as AnyZodSchema;
- }, [composition?.schema, noComposition, z]);
+ return resolveCompositionSchema({
+ explicitSchema: composition.schema,
+ defaultProps: composition.defaultProps ?? {},
+ z,
+ zodTypes,
+ });
+ }, [composition, noComposition, z, zodTypes]);
const currentDefaultProps = useMemo(() => {
if (composition === null) {
diff --git a/packages/studio/src/components/RenderModal/DataEditor.tsx b/packages/studio/src/components/RenderModal/DataEditor.tsx
index 9889d0dffc..296dc6a093 100644
--- a/packages/studio/src/components/RenderModal/DataEditor.tsx
+++ b/packages/studio/src/components/RenderModal/DataEditor.tsx
@@ -5,7 +5,7 @@ import {NoReactInternals} from 'remotion/no-react';
import {StudioServerConnectionCtx} from '../../helpers/client-id';
import {BACKGROUND, BLUE, BLACK_HEX, LIGHT_TEXT} from '../../helpers/colors';
import {CompactExplanation} from '../CompactExplanation';
-import {useZodIfPossible} from '../get-zod-if-possible';
+import {useZodIfPossible, useZodTypesIfPossible} from '../get-zod-if-possible';
import {INSPECTOR_PANEL_HORIZONTAL_PADDING} from '../InspectorPanelLayout';
import {Flex, Spacing} from '../layout';
import {ValidationMessage} from '../NewComposition/ValidationMessage';
@@ -17,6 +17,7 @@ import type {
} from './get-render-modal-warnings';
import {getRenderModalWarnings} from './get-render-modal-warnings';
import {RenderModalJSONPropsEditor} from './RenderModalJSONPropsEditor';
+import {resolveCompositionSchema} from './SchemaEditor/infer-zod-schema-from-value';
import {SchemaEditor} from './SchemaEditor/SchemaEditor';
import {
NoDefaultProps,
@@ -24,10 +25,7 @@ import {
type SchemaErrorMode,
ZodNotInstalled,
} from './SchemaEditor/SchemaErrorMessages';
-import type {
- AnyZodSchema,
- ZodSafeParseResult,
-} from './SchemaEditor/zod-schema-type';
+import type {ZodSafeParseResult} from './SchemaEditor/zod-schema-type';
import {getZodSchemaType, zodSafeParse} from './SchemaEditor/zod-schema-type';
import type {UpdaterFunction} from './SchemaEditor/ZodSwitch';
import {WarningIndicatorButton} from './WarningIndicatorButton';
@@ -281,29 +279,21 @@ export const DataEditor: React.FC<{
}, [setDefaultProps]);
const z = useZodIfPossible();
+ const zodTypes = useZodTypesIfPossible();
const schema = useMemo(() => {
- if (!z) {
- return 'no-zod' as const;
- }
-
- if (!unresolvedComposition.schema) {
- return 'no-schema' as const;
- }
-
- if (
- !(
- typeof (unresolvedComposition.schema as {safeParse?: unknown})
- .safeParse === 'function'
- )
- ) {
- throw new Error(
- 'A value which is not a Zod schema was passed to `schema`',
- );
- }
-
- return unresolvedComposition.schema as AnyZodSchema;
- }, [unresolvedComposition.schema, z]);
+ return resolveCompositionSchema({
+ explicitSchema: unresolvedComposition.schema,
+ defaultProps: unresolvedComposition.defaultProps ?? {},
+ z,
+ zodTypes,
+ });
+ }, [
+ unresolvedComposition.defaultProps,
+ unresolvedComposition.schema,
+ z,
+ zodTypes,
+ ]);
const zodValidationResult = useMemo(() => {
if (schema === 'no-zod') {
diff --git a/packages/studio/src/components/RenderModal/SchemaEditor/infer-zod-schema-from-value.ts b/packages/studio/src/components/RenderModal/SchemaEditor/infer-zod-schema-from-value.ts
new file mode 100644
index 0000000000..208d099453
--- /dev/null
+++ b/packages/studio/src/components/RenderModal/SchemaEditor/infer-zod-schema-from-value.ts
@@ -0,0 +1,147 @@
+import type {
+ ZodType as ZodNamespace,
+ ZodTypesType,
+} from '../../get-zod-if-possible';
+import type {AnyZodSchema} from './zod-schema-type';
+import {zodSafeParse} from './zod-schema-type';
+
+const hasUnambiguousColorSyntax = (value: string) => {
+ return /^(?:#|(?:rgb|hsl|hwb|lab|lch|oklab|oklch|color)\()/i.test(
+ value.trim(),
+ );
+};
+
+const isPlainObject = (value: unknown): value is Record<string, unknown> => {
+ if (value === null || typeof value !== 'object') {
+ return false;
+ }
+
+ const prototype = Object.getPrototypeOf(value);
+ return prototype === Object.prototype || prototype === null;
+};
+
+export function inferZodSchemaFromValue({
+ value,
+ z,
+ zodTypes,
+ path,
+}: {
+ readonly value: unknown;
+ readonly z: ZodNamespace;
+ readonly zodTypes: ZodTypesType | null;
+ readonly path: readonly string[];
+}): AnyZodSchema {
+ if (typeof value === 'string') {
+ const key = path.at(-1)?.toLowerCase();
+ if (key === 'type') {
+ return z.literal(value);
+ }
+
+ const keySuggestsColor = key?.includes('color');
+ if (zodTypes && (keySuggestsColor || hasUnambiguousColorSyntax(value))) {
+ try {
+ zodTypes.ZodZypesInternals.parseColor(value);
+ return zodTypes.zColor();
+ } catch {}
+ }
+
+ return z.string();
+ }
+
+ if (typeof value === 'number') {
+ return z.number();
+ }
+
+ if (typeof value === 'boolean') {
+ return z.boolean();
+ }
+
+ if (value === null) {
+ return z.null();
+ }
+
+ if (typeof value === 'undefined') {
+ return z.undefined();
+ }
+
+ if (value instanceof Date) {
+ return z.date();
+ }
+
+ if (Array.isArray(value)) {
+ if (value.length === 0) {
+ return z.any();
+ }
+
+ const elementSchema = inferZodSchemaFromValue({
+ value: value[0],
+ z,
+ zodTypes,
+ path,
+ });
+ if (!value.every((item) => zodSafeParse(elementSchema, item).success)) {
+ return z.any();
+ }
+
+ return z.array(elementSchema as never);
+ }
+
+ if (isPlainObject(value)) {
+ return z.object(
+ Object.fromEntries(
+ Object.entries(value).map(([key, child]) => [
+ key,
+ inferZodSchemaFromValue({
+ value: child,
+ z,
+ zodTypes,
+ path: [...path, key],
+ }),
+ ]),
+ ) as never,
+ );
+ }
+
+ return z.any();
+}
+
+export type ResolvedCompositionSchema = AnyZodSchema | 'no-schema' | 'no-zod';
+
+export function resolveCompositionSchema({
+ explicitSchema,
+ defaultProps,
+ z,
+ zodTypes,
+}: {
+ readonly explicitSchema: unknown;
+ readonly defaultProps: Record<string, unknown>;
+ readonly z: ZodNamespace | null;
+ readonly zodTypes: ZodTypesType | null;
+}): ResolvedCompositionSchema {
+ if (!z) {
+ return 'no-zod';
+ }
+
+ if (explicitSchema) {
+ if (
+ typeof (explicitSchema as {safeParse?: unknown}).safeParse !== 'function'
+ ) {
+ throw new Error(
+ 'A value which is not a Zod schema was passed to `schema`',
+ );
+ }
+
+ return explicitSchema as AnyZodSchema;
+ }
+
+ if (Object.keys(defaultProps).length === 0) {
+ return 'no-schema';
+ }
+
+ return inferZodSchemaFromValue({
+ value: defaultProps,
+ z,
+ zodTypes,
+ path: [],
+ });
+}
diff --git a/packages/studio/src/test/infer-zod-schema-from-value.test.ts b/packages/studio/src/test/infer-zod-schema-from-value.test.ts
new file mode 100644
index 0000000000..c93b1619e4
--- /dev/null
+++ b/packages/studio/src/test/infer-zod-schema-from-value.test.ts
@@ -0,0 +1,106 @@
+import {expect, test} from 'bun:test';
+// eslint-disable-next-line @typescript-eslint/no-restricted-imports
+import * as zodTypes from '@remotion/zod-types';
+// eslint-disable-next-line @typescript-eslint/no-restricted-imports
+import {z} from 'zod';
+import {
+ inferZodSchemaFromValue,
+ resolveCompositionSchema,
+} from '../components/RenderModal/SchemaEditor/infer-zod-schema-from-value';
+import {
+ getArrayElement,
+ getObjectShape,
+ getZodSchemaDescription,
+ getZodSchemaType,
+} from '../components/RenderModal/SchemaEditor/zod-schema-type';
+
+test('infers primitive and nested object schemas', () => {
+ const schema = inferZodSchemaFromValue({
+ value: {
+ title: 'Hello',
+ count: 2,
+ enabled: true,
+ nested: {type: 'current', label: 'Nested'},
+ nullable: null,
+ missing: undefined,
+ date: new Date('2026-08-22T00:00:00.000Z'),
+ },
+ z,
+ zodTypes,
+ path: [],
+ });
+
+ const shape = getObjectShape(schema);
+ expect(getZodSchemaType(shape.title)).toBe('string');
+ expect(getZodSchemaType(shape.count)).toBe('number');
+ expect(getZodSchemaType(shape.enabled)).toBe('boolean');
+ expect(getZodSchemaType(shape.nested)).toBe('object');
+ expect(getZodSchemaType(getObjectShape(shape.nested).type)).toBe('literal');
+ expect(getZodSchemaType(getObjectShape(shape.nested).label)).toBe('string');
+ expect(getZodSchemaType(shape.nullable)).toBe('null');
+ expect(getZodSchemaType(shape.missing)).toBe('undefined');
+ expect(getZodSchemaType(shape.date)).toBe('date');
+});
+
+test('infers colors without interpreting ambiguous text as a color', () => {
+ const schema = inferZodSchemaFromValue({
+ value: {
+ title: 'red',
+ accent: '#3124',
+ titleColor: 'red',
+ invalidColor: 'not-a-color',
+ },
+ z,
+ zodTypes,
+ path: [],
+ });
+ const shape = getObjectShape(schema);
+
+ expect(getZodSchemaDescription(shape.title)).toBeUndefined();
+ expect(getZodSchemaDescription(shape.accent)).toBe(
+ zodTypes.ZodZypesInternals.REMOTION_COLOR_BRAND,
+ );
+ expect(getZodSchemaDescription(shape.titleColor)).toBe(
+ zodTypes.ZodZypesInternals.REMOTION_COLOR_BRAND,
+ );
+ expect(getZodSchemaDescription(shape.invalidColor)).toBeUndefined();
+});
+
+test('infers homogeneous arrays and leaves ambiguous arrays uneditable', () => {
+ const schema = inferZodSchemaFromValue({
+ value: {
+ numbers: [1, 2, 3],
+ mixed: [1, '2'],
+ empty: [],
+ },
+ z,
+ zodTypes,
+ path: [],
+ });
+ const shape = getObjectShape(schema);
+
+ expect(getZodSchemaType(shape.numbers)).toBe('array');
+ expect(getZodSchemaType(getArrayElement(shape.numbers))).toBe('number');
+ expect(getZodSchemaType(shape.mixed)).toBe('any');
+ expect(getZodSchemaType(shape.empty)).toBe('any');
+});
+
+test('prefers an explicit schema and skips empty default props', () => {
+ const explicitSchema = z.object({title: z.literal('Hello')});
+ expect(
+ resolveCompositionSchema({
+ explicitSchema,
+ defaultProps: {title: 'Hello'},
+ z,
+ zodTypes,
+ }),
+ ).toBe(explicitSchema);
+ expect(
+ resolveCompositionSchema({
+ explicitSchema: null,
+ defaultProps: {},
+ z,
+ zodTypes,
+ }),
+ ).toBe('no-schema');
+});
diff --git a/packages/template-audiogram/src/Audiogram/Main.tsx b/packages/template-audiogram/src/Audiogram/Main.tsx
index e4abb4dd1c..3363fe2eeb 100644
--- a/packages/template-audiogram/src/Audiogram/Main.tsx
+++ b/packages/template-audiogram/src/Audiogram/Main.tsx
@@ -1,6 +1,12 @@
import { Audio } from "@remotion/media";
import React from "react";
-import { AbsoluteFill, Img, Sequence, useVideoConfig } from "remotion";
+import {
+ AbsoluteFill,
+ Img,
+ Interactive,
+ staticFile,
+ useVideoConfig,
+} from "remotion";
import { PaginatedCaptions } from "./Captions";
import { Oscilloscope } from "./Oscilloscope";
import { Spectrum } from "./Spectrum";
@@ -13,20 +19,17 @@ import {
LINES_PER_PAGE,
} from "./constants";
import { FONT_FAMILY } from "./font";
-import { AudiogramCompositionSchemaType } from "./schema";
+import type { AudiogramProps } from "./types";
-export const Audiogram: React.FC<AudiogramCompositionSchemaType> = ({
+export const Audiogram: React.FC<AudiogramProps> = ({
visualizer,
audioFileUrl,
- coverImageUrl,
- titleText,
titleColor,
captionsTextColor,
onlyDisplayCurrentSentence,
- audioOffsetInSeconds,
captions,
}) => {
- const { durationInFrames, fps, width } = useVideoConfig();
+ const { durationInFrames, width } = useVideoConfig();
if (!captions) {
throw new Error(
@@ -34,100 +37,98 @@ export const Audiogram: React.FC<AudiogramCompositionSchemaType> = ({
);
}
- const audioOffsetInFrames = Math.round(audioOffsetInSeconds * fps);
const baseNumberOfSamples = Number(visualizer.numberOfSamples);
const textBoxWidth = width - BASE_SIZE * 2;
return (
<AbsoluteFill>
- <Sequence from={-audioOffsetInFrames}>
- <Audio src={audioFileUrl} />
+ <Audio src={audioFileUrl} />
+ <div
+ style={{
+ display: "flex",
+ flexDirection: "column",
+ width: "100%",
+ height: "100%",
+ color: "white",
+ padding: "48px",
+ backgroundColor: "black",
+ fontFamily: FONT_FAMILY,
+ }}
+ >
<div
style={{
display: "flex",
- flexDirection: "column",
- width: "100%",
- height: "100%",
- color: "white",
- padding: "48px",
- backgroundColor: "black",
- fontFamily: FONT_FAMILY,
+ flexDirection: "row",
+ alignItems: "center",
}}
>
+ <Img
+ style={{
+ borderRadius: "6px",
+ maxHeight: "250px",
+ }}
+ src={staticFile("podcast-cover.jpeg")}
+ />
+ <Interactive.Div
+ style={{
+ marginLeft: "48px",
+ lineHeight: "1.25",
+ fontWeight: 800,
+ color: titleColor,
+ fontSize: "48px",
+ }}
+ name={"Episode Title"}
+ >
+ Ep 550 - Supper Club × Remotion React
+ </Interactive.Div>
+ </div>
+ <div>
+ {visualizer.type === "oscilloscope" ? (
+ <Oscilloscope
+ waveColor={visualizer.color}
+ padding={visualizer.padding}
+ audioSrc={audioFileUrl}
+ key={audioFileUrl}
+ numberOfSamples={baseNumberOfSamples}
+ windowInSeconds={visualizer.windowInSeconds}
+ posterization={visualizer.posterization}
+ amplitude={visualizer.amplitude}
+ />
+ ) : visualizer.type === "spectrum" ? (
+ <Spectrum
+ barColor={visualizer.color}
+ audioSrc={audioFileUrl}
+ key={audioFileUrl}
+ mirrorWave={visualizer.mirrorWave}
+ numberOfSamples={baseNumberOfSamples * 4} // since fft is used, we need to increase the number of samples to get a better resolution
+ freqRangeStartIndex={visualizer.freqRangeStartIndex}
+ waveLinesToDisplay={visualizer.linesToDisplay}
+ />
+ ) : null}
+ </div>
+ <WaitForFonts>
<div
style={{
- display: "flex",
- flexDirection: "row",
- alignItems: "center",
+ lineHeight: `${LINE_HEIGHT}px`,
+ width: textBoxWidth,
+ fontWeight: CAPTIONS_FONT_WEIGHT,
+ fontSize: CAPTIONS_FONT_SIZE,
+ marginTop: BASE_SIZE * 0.5,
}}
>
- <Img
- style={{
- borderRadius: "6px",
- maxHeight: "250px",
- }}
- src={coverImageUrl}
+ <PaginatedCaptions
+ captions={captions}
+ startFrame={0}
+ endFrame={durationInFrames}
+ linesPerPage={LINES_PER_PAGE}
+ subtitlesTextColor={captionsTextColor}
+ onlyDisplayCurrentSentence={onlyDisplayCurrentSentence}
+ textBoxWidth={textBoxWidth}
/>
- <div
- style={{
- marginLeft: "48px",
- lineHeight: "1.25",
- fontWeight: 800,
- color: titleColor,
- fontSize: "48px",
- }}
- >
- {titleText}
- </div>
- </div>
- <div>
- {visualizer.type === "oscilloscope" ? (
- <Oscilloscope
- waveColor={visualizer.color}
- padding={visualizer.padding}
- audioSrc={audioFileUrl}
- key={audioFileUrl}
- numberOfSamples={baseNumberOfSamples}
- windowInSeconds={visualizer.windowInSeconds}
- posterization={visualizer.posterization}
- amplitude={visualizer.amplitude}
- />
- ) : visualizer.type === "spectrum" ? (
- <Spectrum
- barColor={visualizer.color}
- audioSrc={audioFileUrl}
- key={audioFileUrl}
- mirrorWave={visualizer.mirrorWave}
- numberOfSamples={baseNumberOfSamples * 4} // since fft is used, we need to increase the number of samples to get a better resolution
- freqRangeStartIndex={visualizer.freqRangeStartIndex}
- waveLinesToDisplay={visualizer.linesToDisplay}
- />
- ) : null}
</div>
- <WaitForFonts>
- <div
- style={{
- lineHeight: `${LINE_HEIGHT}px`,
- width: textBoxWidth,
- fontWeight: CAPTIONS_FONT_WEIGHT,
- fontSize: CAPTIONS_FONT_SIZE,
- marginTop: BASE_SIZE * 0.5,
- }}
- >
- <PaginatedCaptions
- captions={captions}
- startFrame={audioOffsetInFrames}
- endFrame={audioOffsetInFrames + durationInFrames}
- linesPerPage={LINES_PER_PAGE}
- subtitlesTextColor={captionsTextColor}
- onlyDisplayCurrentSentence={onlyDisplayCurrentSentence}
- textBoxWidth={textBoxWidth}
- />
- </div>
- </WaitForFonts>
- </div>
- </Sequence>
+ </WaitForFonts>
+ </div>
</AbsoluteFill>
);
};
diff --git a/packages/template-audiogram/src/Audiogram/schema.ts b/packages/template-audiogram/src/Audiogram/schema.ts
deleted file mode 100644
index 9b65329dbe..0000000000
--- a/packages/template-audiogram/src/Audiogram/schema.ts
+++ /dev/null
@@ -1,52 +0,0 @@
-import { Caption } from "@remotion/captions";
-import { zColor } from "@remotion/zod-types";
-import { z } from "zod";
-
-const baseVisualizerSchema = z.object({
- color: zColor(),
- numberOfSamples: z.enum(["32", "64", "128", "256", "512"]),
-});
-
-const spectrumVisualizerSchema = baseVisualizerSchema.extend({
- type: z.literal("spectrum"),
- linesToDisplay: z.number().int().min(0).default(65),
- freqRangeStartIndex: z.number().int().min(0).default(0),
- mirrorWave: z.boolean(),
-});
-
-const oscilloscopeVisualizerSchema = baseVisualizerSchema.extend({
- type: z.literal("oscilloscope"),
- windowInSeconds: z.number().min(0.1).default(0.1),
- posterization: z.number().int().min(0.1).default(3),
- amplitude: z.number().int().min(0.1).default(4),
- padding: z.number().int().min(0).default(50),
-});
-
-const visualizerSchema = z.discriminatedUnion("type", [
- spectrumVisualizerSchema,
- oscilloscopeVisualizerSchema,
-]);
-
-export const audiogramSchema = z.object({
- // visualizer settings
- visualizer: visualizerSchema,
- // podcast data
- coverImageUrl: z.string(),
- titleText: z.string(),
- titleColor: zColor(),
- // captions settings
- captionsFileName: z
- .string()
- .refine((s) => s.endsWith(".srt") || s.endsWith(".json"), {
- message: "Subtitles file must be a .srt or .json file",
- }),
- captionsTextColor: zColor(),
- onlyDisplayCurrentSentence: z.boolean(),
- // audio settings
- audioFileUrl: z.string(),
- audioOffsetInSeconds: z.number().min(0),
-});
-
-export type AudiogramCompositionSchemaType = z.infer<typeof audiogramSchema> & {
- captions: Caption[] | null;
-};
diff --git a/packages/template-audiogram/src/Audiogram/types.ts b/packages/template-audiogram/src/Audiogram/types.ts
new file mode 100644
index 0000000000..89384e0fbc
--- /dev/null
+++ b/packages/template-audiogram/src/Audiogram/types.ts
@@ -0,0 +1,33 @@
+import type { Caption } from "@remotion/captions";
+
+type NumberOfSamples = "32" | "64" | "128" | "256" | "512";
+
+type BaseVisualizer = {
+ readonly color: string;
+ readonly numberOfSamples: NumberOfSamples;
+};
+
+type SpectrumVisualizer = BaseVisualizer & {
+ readonly type: "spectrum";
+ readonly linesToDisplay: number;
+ readonly freqRangeStartIndex: number;
+ readonly mirrorWave: boolean;
+};
+
+type OscilloscopeVisualizer = BaseVisualizer & {
+ readonly type: "oscilloscope";
+ readonly windowInSeconds: number;
+ readonly posterization: number;
+ readonly amplitude: number;
+ readonly padding: number;
+};
+
+export type AudiogramProps = {
+ readonly visualizer: SpectrumVisualizer | OscilloscopeVisualizer;
+ readonly titleColor: string;
+ readonly captionsFileName: string;
+ readonly captionsTextColor: string;
+ readonly onlyDisplayCurrentSentence: boolean;
+ readonly audioFileUrl: string;
+ readonly captions: Caption[] | null;
+};
diff --git a/packages/template-audiogram/src/Root.tsx b/packages/template-audiogram/src/Root.tsx
index 8b4d0c82ca..07b22c398d 100644
--- a/packages/template-audiogram/src/Root.tsx
+++ b/packages/template-audiogram/src/Root.tsx
@@ -1,7 +1,6 @@
import { parseMedia } from "@remotion/media-parser";
import { Composition, staticFile } from "remotion";
import { Audiogram } from "./Audiogram/Main";
-import { audiogramSchema } from "./Audiogram/schema";
import { getSubtitles } from "./helpers/fetch-captions";
import { FPS } from "./helpers/ms-to-frame";
@@ -13,14 +12,10 @@ export const RemotionRoot: React.FC = () => {
component={Audiogram}
width={1080}
height={1080}
- schema={audiogramSchema}
defaultProps={{
// audio settings
- audioOffsetInSeconds: 0,
audioFileUrl: staticFile("dialogue.wav"),
// podcast data
- coverImageUrl: staticFile("podcast-cover.jpeg"),
- titleText: "Ep 550 - Supper Club × Remotion React",
titleColor: "rgba(186, 186, 186, 0.93)",
// captions settings
captions: null,
@@ -31,7 +26,7 @@ export const RemotionRoot: React.FC = () => {
visualizer: {
type: "oscilloscope",
color: "#F4B941",
- numberOfSamples: "64" as const,
+ numberOfSamples: "64",
windowInSeconds: 0.1,
posterization: 3,
amplitude: 4,
@@ -50,9 +45,7 @@ export const RemotionRoot: React.FC = () => {
});
return {
- durationInFrames: Math.floor(
- (slowDurationInSeconds - props.audioOffsetInSeconds) * FPS,
- ),
+ durationInFrames: Math.floor(slowDurationInSeconds * FPS),
props: {
...props,
captions,
diff --git a/packages/template-helloworld/src/HelloWorld.tsx b/packages/template-helloworld/src/HelloWorld.tsx
index 22e0ccc67b..803c33b010 100644
--- a/packages/template-helloworld/src/HelloWorld.tsx
+++ b/packages/template-helloworld/src/HelloWorld.tsx
@@ -1,4 +1,3 @@
-import { zColor } from "@remotion/zod-types";
import {
AbsoluteFill,
interpolate,
@@ -7,19 +6,18 @@ import {
useCurrentFrame,
useVideoConfig,
} from "remotion";
-import { z } from "zod";
import { Logo } from "./HelloWorld/Logo";
import { Subtitle } from "./HelloWorld/Subtitle";
import { Title } from "./HelloWorld/Title";
-export const myCompSchema = z.object({
- titleText: z.string(),
- titleColor: zColor(),
- logoColor1: zColor(),
- logoColor2: zColor(),
-});
+export type HelloWorldProps = {
+ readonly titleText: string;
+ readonly titleColor: string;
+ readonly logoColor1: string;
+ readonly logoColor2: string;
+};
-export const HelloWorld: React.FC<z.infer<typeof myCompSchema>> = ({
+export const HelloWorld: React.FC<HelloWorldProps> = ({
titleText: propOne,
titleColor: propTwo,
logoColor1,
diff --git a/packages/template-helloworld/src/HelloWorld/Logo.tsx b/packages/template-helloworld/src/HelloWorld/Logo.tsx
index 259f8c9216..4afabf2b8b 100644
--- a/packages/template-helloworld/src/HelloWorld/Logo.tsx
+++ b/packages/template-helloworld/src/HelloWorld/Logo.tsx
@@ -1,4 +1,3 @@
-import { zColor } from "@remotion/zod-types";
import {
AbsoluteFill,
interpolate,
@@ -6,16 +5,15 @@ import {
useCurrentFrame,
useVideoConfig,
} from "remotion";
-import { z } from "zod";
import { Arc } from "./Arc";
import { Atom } from "./Atom";
-export const myCompSchema2 = z.object({
- logoColor1: zColor(),
- logoColor2: zColor(),
-});
+export type LogoProps = {
+ readonly logoColor1: string;
+ readonly logoColor2: string;
+};
-export const Logo: React.FC<z.infer<typeof myCompSchema2>> = ({
+export const Logo: React.FC<LogoProps> = ({
logoColor1: color1,
logoColor2: color2,
}) => {
diff --git a/packages/template-helloworld/src/Root.tsx b/packages/template-helloworld/src/Root.tsx
index 14824c10ff..f7ac9e5082 100644
--- a/packages/template-helloworld/src/Root.tsx
+++ b/packages/template-helloworld/src/Root.tsx
@@ -1,6 +1,6 @@
import { Composition } from "remotion";
-import { HelloWorld, myCompSchema } from "./HelloWorld";
-import { Logo, myCompSchema2 } from "./HelloWorld/Logo";
+import { HelloWorld } from "./HelloWorld";
+import { Logo } from "./HelloWorld/Logo";
// Each <Composition> is an entry in the sidebar!
@@ -18,7 +18,6 @@ export const RemotionRoot: React.FC = () => {
height={1080}
// You can override these props for each render:
// https://www.remotion.dev/docs/parametrized-rendering
- schema={myCompSchema}
defaultProps={{
titleText: "Welcome to Remotion",
titleColor: "#000000",
@@ -35,10 +34,9 @@ export const RemotionRoot: React.FC = () => {
fps={30}
width={1920}
height={1080}
- schema={myCompSchema2}
defaultProps={{
- logoColor1: "#91dAE2" as const,
- logoColor2: "#86A8E7" as const,
+ logoColor1: "#91dAE2",
+ logoColor2: "#86A8E7",
}}
/>
</>