🎥 Make videos programmatically with React
Keep default Element captions inline
Igor Samokhovets8aeab060fcec
diff --git a/packages/docs/elements/captions/moving-pill-captions/moving-pill-captions.tsx b/packages/docs/elements/captions/moving-pill-captions/moving-pill-captions.tsxindex 05c6495762..fdc3f69981 100644--- a/packages/docs/elements/captions/moving-pill-captions/moving-pill-captions.tsx+++ b/packages/docs/elements/captions/moving-pill-captions/moving-pill-captions.tsx@@ -51,64 +51,10 @@ const pillVerticalPadding = 12;const pillBorderRadius = 10;const pillMoveDurationInFrames = 5;const defaultCombineTokensWithinMilliseconds = 800;-const defaultCaptions: Caption[] = [- {- text: 'Captions',- startMs: 0,- endMs: 800,- timestampMs: 400,- confidence: null,- },- {- text: ' can',- startMs: 800,- endMs: 1500,- timestampMs: 1150,- confidence: null,- },- {- text: ' move',- startMs: 1500,- endMs: 2300,- timestampMs: 1900,- confidence: null,- },- {- text: ' with',- startMs: 2300,- endMs: 3100,- timestampMs: 2700,- confidence: null,- },- {- text: ' every',- startMs: 3100,- endMs: 4000,- timestampMs: 3550,- confidence: null,- },- {- text: ' spoken',- startMs: 4000,- endMs: 5100,- timestampMs: 4550,- confidence: null,- },- {- text: ' word.',- startMs: 5100,- endMs: 6500,- timestampMs: 5800,- confidence: null,- },-];const movingPillCaptionsSchema = {...Interactive.baseSchema,- captions: {- ...Interactive.captionsSchema.captions,- default: defaultCaptions,- },+ ...Interactive.captionsSchema,width: {type: 'number',min: 1,@@ -530,16 +476,25 @@ const MovingPillCaptionsInner = forwardRef<},);-const MovingPillCaptionsWithControls: React.FC<- MovingPillCaptionsProps & {readonly controls: SequenceControls | undefined}-> = ({captions, controls, style, ...props}) => {+const MovingPillCaptionsLayer = Interactive.withSchema({+ Component: MovingPillCaptionsInner,+ componentName: '<MovingPillCaptions>',+ componentIdentity: null,+ schema: movingPillCaptionsSchema,+ supportsEffects: false,+}) as React.FC<MovingPillCaptionsLayerProps>;++export const MovingPillCaptions: React.FC<MovingPillCaptionsProps> = ({+ captions,+ style,+ ...props+}) => {if (captions) {return (- <MovingPillCaptionsInner+ <MovingPillCaptionsLayer{...props}callerStyle={style ?? null}captions={captions}- controls={controls}style={{translate: '0px 0px'}}/>);@@ -555,11 +510,60 @@ const MovingPillCaptionsWithControls: React.FC<width: 900,}}>- <MovingPillCaptionsInner+ <MovingPillCaptionsLayer{...props}callerStyle={style ?? null}- captions={defaultCaptions}- controls={controls}+ captions={[+ {+ text: 'Captions',+ startMs: 0,+ endMs: 800,+ timestampMs: 400,+ confidence: null,+ },+ {+ text: ' can',+ startMs: 800,+ endMs: 1500,+ timestampMs: 1150,+ confidence: null,+ },+ {+ text: ' move',+ startMs: 1500,+ endMs: 2300,+ timestampMs: 1900,+ confidence: null,+ },+ {+ text: ' with',+ startMs: 2300,+ endMs: 3100,+ timestampMs: 2700,+ confidence: null,+ },+ {+ text: ' every',+ startMs: 3100,+ endMs: 4000,+ timestampMs: 3550,+ confidence: null,+ },+ {+ text: ' spoken',+ startMs: 4000,+ endMs: 5100,+ timestampMs: 4550,+ confidence: null,+ },+ {+ text: ' word.',+ startMs: 5100,+ endMs: 6500,+ timestampMs: 5800,+ confidence: null,+ },+ ]}width={props.width ?? 681}height={props.height ?? 252}style={{translate: '0px 0px'}}@@ -567,11 +571,3 @@ const MovingPillCaptionsWithControls: React.FC<</div>);};--export const MovingPillCaptions = Interactive.withSchema({- Component: MovingPillCaptionsWithControls,- componentName: '<MovingPillCaptions>',- componentIdentity: null,- schema: movingPillCaptionsSchema,- supportsEffects: false,-}) as React.FC<MovingPillCaptionsProps>;diff --git a/packages/docs/elements/captions/popping-word-captions/popping-word-captions.tsx b/packages/docs/elements/captions/popping-word-captions/popping-word-captions.tsxindex e27aca4ed8..2e1670b6b9 100644--- a/packages/docs/elements/captions/popping-word-captions/popping-word-captions.tsx+++ b/packages/docs/elements/captions/popping-word-captions/popping-word-captions.tsx@@ -47,64 +47,10 @@ const textColor = '#ffffff';const highlightColor = '#4da3ff';const activeWordScale = 1.03;const defaultCombineTokensWithinMilliseconds = 800;-const defaultCaptions: Caption[] = [- {- text: 'Captions',- startMs: 0,- endMs: 800,- timestampMs: 400,- confidence: null,- },- {- text: ' can',- startMs: 800,- endMs: 1500,- timestampMs: 1150,- confidence: null,- },- {- text: ' move',- startMs: 1500,- endMs: 2300,- timestampMs: 1900,- confidence: null,- },- {- text: ' with',- startMs: 2300,- endMs: 3100,- timestampMs: 2700,- confidence: null,- },- {- text: ' every',- startMs: 3100,- endMs: 4000,- timestampMs: 3550,- confidence: null,- },- {- text: ' spoken',- startMs: 4000,- endMs: 5100,- timestampMs: 4550,- confidence: null,- },- {- text: ' word.',- startMs: 5100,- endMs: 6500,- timestampMs: 5800,- confidence: null,- },-];const poppingWordCaptionsSchema = {...Interactive.baseSchema,- captions: {- ...Interactive.captionsSchema.captions,- default: defaultCaptions,- },+ ...Interactive.captionsSchema,width: {type: 'number',min: 1,@@ -440,16 +386,25 @@ const PoppingWordCaptionsInner = forwardRef<},);-const PoppingWordCaptionsWithControls: React.FC<- PoppingWordCaptionsProps & {readonly controls: SequenceControls | undefined}-> = ({captions, controls, style, ...props}) => {+const PoppingWordCaptionsLayer = Interactive.withSchema({+ Component: PoppingWordCaptionsInner,+ componentName: '<PoppingWordCaptions>',+ componentIdentity: null,+ schema: poppingWordCaptionsSchema,+ supportsEffects: false,+}) as React.FC<PoppingWordCaptionsLayerProps>;++export const PoppingWordCaptions: React.FC<PoppingWordCaptionsProps> = ({+ captions,+ style,+ ...props+}) => {if (captions) {return (- <PoppingWordCaptionsInner+ <PoppingWordCaptionsLayer{...props}callerStyle={style ?? null}captions={captions}- controls={controls}style={{translate: '0px 0px'}}/>);@@ -465,11 +420,60 @@ const PoppingWordCaptionsWithControls: React.FC<width: 900,}}>- <PoppingWordCaptionsInner+ <PoppingWordCaptionsLayer{...props}callerStyle={style ?? null}- captions={defaultCaptions}- controls={controls}+ captions={[+ {+ text: 'Captions',+ startMs: 0,+ endMs: 800,+ timestampMs: 400,+ confidence: null,+ },+ {+ text: ' can',+ startMs: 800,+ endMs: 1500,+ timestampMs: 1150,+ confidence: null,+ },+ {+ text: ' move',+ startMs: 1500,+ endMs: 2300,+ timestampMs: 1900,+ confidence: null,+ },+ {+ text: ' with',+ startMs: 2300,+ endMs: 3100,+ timestampMs: 2700,+ confidence: null,+ },+ {+ text: ' every',+ startMs: 3100,+ endMs: 4000,+ timestampMs: 3550,+ confidence: null,+ },+ {+ text: ' spoken',+ startMs: 4000,+ endMs: 5100,+ timestampMs: 4550,+ confidence: null,+ },+ {+ text: ' word.',+ startMs: 5100,+ endMs: 6500,+ timestampMs: 5800,+ confidence: null,+ },+ ]}width={props.width ?? 681}height={props.height ?? 252}style={{translate: '0px 0px'}}@@ -477,11 +481,3 @@ const PoppingWordCaptionsWithControls: React.FC<</div>);};--export const PoppingWordCaptions = Interactive.withSchema({- Component: PoppingWordCaptionsWithControls,- componentName: '<PoppingWordCaptions>',- componentIdentity: null,- schema: poppingWordCaptionsSchema,- supportsEffects: false,-}) as React.FC<PoppingWordCaptionsProps>;diff --git a/packages/docs/elements/captions/word-highlight-captions/word-highlight-captions.tsx b/packages/docs/elements/captions/word-highlight-captions/word-highlight-captions.tsxindex 3749f2e39d..afec7c408e 100644--- a/packages/docs/elements/captions/word-highlight-captions/word-highlight-captions.tsx+++ b/packages/docs/elements/captions/word-highlight-captions/word-highlight-captions.tsx@@ -44,64 +44,10 @@ const fontWeight = '700';const textColor = '#ffffff';const highlightColor = '#4da3ff';const defaultCombineTokensWithinMilliseconds = 800;-const defaultCaptions: Caption[] = [- {- text: 'Captions',- startMs: 0,- endMs: 800,- timestampMs: 400,- confidence: null,- },- {- text: ' can',- startMs: 800,- endMs: 1500,- timestampMs: 1150,- confidence: null,- },- {- text: ' move',- startMs: 1500,- endMs: 2300,- timestampMs: 1900,- confidence: null,- },- {- text: ' with',- startMs: 2300,- endMs: 3100,- timestampMs: 2700,- confidence: null,- },- {- text: ' every',- startMs: 3100,- endMs: 4000,- timestampMs: 3550,- confidence: null,- },- {- text: ' spoken',- startMs: 4000,- endMs: 5100,- timestampMs: 4550,- confidence: null,- },- {- text: ' word.',- startMs: 5100,- endMs: 6500,- timestampMs: 5800,- confidence: null,- },-];const wordHighlightCaptionsSchema = {...Interactive.baseSchema,- captions: {- ...Interactive.captionsSchema.captions,- default: defaultCaptions,- },+ ...Interactive.captionsSchema,width: {type: 'number',min: 1,@@ -398,16 +344,25 @@ const WordHighlightCaptionsInner = forwardRef<},);-const WordHighlightCaptionsWithControls: React.FC<- WordHighlightCaptionsProps & {readonly controls: SequenceControls | undefined}-> = ({captions, controls, style, ...props}) => {+const WordHighlightCaptionsLayer = Interactive.withSchema({+ Component: WordHighlightCaptionsInner,+ componentName: '<WordHighlightCaptions>',+ componentIdentity: null,+ schema: wordHighlightCaptionsSchema,+ supportsEffects: false,+}) as React.FC<WordHighlightCaptionsLayerProps>;++export const WordHighlightCaptions: React.FC<WordHighlightCaptionsProps> = ({+ captions,+ style,+ ...props+}) => {if (captions) {return (- <WordHighlightCaptionsInner+ <WordHighlightCaptionsLayer{...props}callerStyle={style ?? null}captions={captions}- controls={controls}style={{translate: '0px 0px'}}/>);@@ -423,11 +378,60 @@ const WordHighlightCaptionsWithControls: React.FC<width: 900,}}>- <WordHighlightCaptionsInner+ <WordHighlightCaptionsLayer{...props}callerStyle={style ?? null}- captions={defaultCaptions}- controls={controls}+ captions={[+ {+ text: 'Captions',+ startMs: 0,+ endMs: 800,+ timestampMs: 400,+ confidence: null,+ },+ {+ text: ' can',+ startMs: 800,+ endMs: 1500,+ timestampMs: 1150,+ confidence: null,+ },+ {+ text: ' move',+ startMs: 1500,+ endMs: 2300,+ timestampMs: 1900,+ confidence: null,+ },+ {+ text: ' with',+ startMs: 2300,+ endMs: 3100,+ timestampMs: 2700,+ confidence: null,+ },+ {+ text: ' every',+ startMs: 3100,+ endMs: 4000,+ timestampMs: 3550,+ confidence: null,+ },+ {+ text: ' spoken',+ startMs: 4000,+ endMs: 5100,+ timestampMs: 4550,+ confidence: null,+ },+ {+ text: ' word.',+ startMs: 5100,+ endMs: 6500,+ timestampMs: 5800,+ confidence: null,+ },+ ]}width={props.width ?? 681}height={props.height ?? 252}style={{translate: '0px 0px'}}@@ -435,11 +439,3 @@ const WordHighlightCaptionsWithControls: React.FC<</div>);};--export const WordHighlightCaptions = Interactive.withSchema({- Component: WordHighlightCaptionsWithControls,- componentName: '<WordHighlightCaptions>',- componentIdentity: null,- schema: wordHighlightCaptionsSchema,- supportsEffects: false,-}) as React.FC<WordHighlightCaptionsProps>;diff --git a/packages/example/e2e/captions-inspector.test.mts b/packages/example/e2e/captions-inspector.test.mtsindex e8c7d39d44..1aae3ad836 100644--- a/packages/example/e2e/captions-inspector.test.mts+++ b/packages/example/e2e/captions-inspector.test.mts@@ -12,7 +12,12 @@ const inlineCaptionsFile = path.join('CaptionsTester','InlineAnimatedCaptions.tsx',);-const defaultCaptionsFile = path.join(+const elementCaptionsFile = path.join(+ exampleDir,+ 'src',+ 'moving-pill-captions.element.tsx',+);+const elementCallSiteFile = path.join(exampleDir,'src','MovingPillCaptionsComposition.tsx',@@ -20,21 +25,24 @@ const defaultCaptionsFile = path.join(test.describe('captions inspector', () => {let inlineSourceBefore: string;- let defaultSourceBefore: string;+ let elementSourceBefore: string;+ let elementCallSiteSourceBefore: string;test.beforeEach(async () => {inlineSourceBefore = fs.readFileSync(inlineCaptionsFile, 'utf-8');- defaultSourceBefore = fs.readFileSync(defaultCaptionsFile, 'utf-8');+ elementSourceBefore = fs.readFileSync(elementCaptionsFile, 'utf-8');+ elementCallSiteSourceBefore = fs.readFileSync(elementCallSiteFile, 'utf-8');await startStudio();});test.afterEach(async () => {await stopStudio();fs.writeFileSync(inlineCaptionsFile, inlineSourceBefore);- fs.writeFileSync(defaultCaptionsFile, defaultSourceBefore);+ fs.writeFileSync(elementCaptionsFile, elementSourceBefore);+ fs.writeFileSync(elementCallSiteFile, elementCallSiteSourceBefore);});- test('persists inline and default caption edits', async ({page}) => {+ test('persists caption edits at their inline definitions', async ({page}) => {await page.goto(`${STUDIO_URL}/captions-inspector-e2e`);await expect(page).toHaveURL(/captions-inspector-e2e/, {timeout: 15_000});await page.waitForFunction(@@ -97,9 +105,12 @@ test.describe('captions inspector', () => {await expect.poll(() => {return /text:\s*['"]Editable captions['"]/.test(- fs.readFileSync(defaultCaptionsFile, 'utf-8'),+ fs.readFileSync(elementCaptionsFile, 'utf-8'),);}).toBe(true);+ expect(fs.readFileSync(elementCallSiteFile, 'utf-8')).toBe(+ elementCallSiteSourceBefore,+ );});});diff --git a/packages/example/src/moving-pill-captions.element.tsx b/packages/example/src/moving-pill-captions.element.tsxindex 05c6495762..fdc3f69981 100644--- a/packages/example/src/moving-pill-captions.element.tsx+++ b/packages/example/src/moving-pill-captions.element.tsx@@ -51,64 +51,10 @@ const pillVerticalPadding = 12;const pillBorderRadius = 10;const pillMoveDurationInFrames = 5;const defaultCombineTokensWithinMilliseconds = 800;-const defaultCaptions: Caption[] = [- {- text: 'Captions',- startMs: 0,- endMs: 800,- timestampMs: 400,- confidence: null,- },- {- text: ' can',- startMs: 800,- endMs: 1500,- timestampMs: 1150,- confidence: null,- },- {- text: ' move',- startMs: 1500,- endMs: 2300,- timestampMs: 1900,- confidence: null,- },- {- text: ' with',- startMs: 2300,- endMs: 3100,- timestampMs: 2700,- confidence: null,- },- {- text: ' every',- startMs: 3100,- endMs: 4000,- timestampMs: 3550,- confidence: null,- },- {- text: ' spoken',- startMs: 4000,- endMs: 5100,- timestampMs: 4550,- confidence: null,- },- {- text: ' word.',- startMs: 5100,- endMs: 6500,- timestampMs: 5800,- confidence: null,- },-];const movingPillCaptionsSchema = {...Interactive.baseSchema,- captions: {- ...Interactive.captionsSchema.captions,- default: defaultCaptions,- },+ ...Interactive.captionsSchema,width: {type: 'number',min: 1,@@ -530,16 +476,25 @@ const MovingPillCaptionsInner = forwardRef<},);-const MovingPillCaptionsWithControls: React.FC<- MovingPillCaptionsProps & {readonly controls: SequenceControls | undefined}-> = ({captions, controls, style, ...props}) => {+const MovingPillCaptionsLayer = Interactive.withSchema({+ Component: MovingPillCaptionsInner,+ componentName: '<MovingPillCaptions>',+ componentIdentity: null,+ schema: movingPillCaptionsSchema,+ supportsEffects: false,+}) as React.FC<MovingPillCaptionsLayerProps>;++export const MovingPillCaptions: React.FC<MovingPillCaptionsProps> = ({+ captions,+ style,+ ...props+}) => {if (captions) {return (- <MovingPillCaptionsInner+ <MovingPillCaptionsLayer{...props}callerStyle={style ?? null}captions={captions}- controls={controls}style={{translate: '0px 0px'}}/>);@@ -555,11 +510,60 @@ const MovingPillCaptionsWithControls: React.FC<width: 900,}}>- <MovingPillCaptionsInner+ <MovingPillCaptionsLayer{...props}callerStyle={style ?? null}- captions={defaultCaptions}- controls={controls}+ captions={[+ {+ text: 'Captions',+ startMs: 0,+ endMs: 800,+ timestampMs: 400,+ confidence: null,+ },+ {+ text: ' can',+ startMs: 800,+ endMs: 1500,+ timestampMs: 1150,+ confidence: null,+ },+ {+ text: ' move',+ startMs: 1500,+ endMs: 2300,+ timestampMs: 1900,+ confidence: null,+ },+ {+ text: ' with',+ startMs: 2300,+ endMs: 3100,+ timestampMs: 2700,+ confidence: null,+ },+ {+ text: ' every',+ startMs: 3100,+ endMs: 4000,+ timestampMs: 3550,+ confidence: null,+ },+ {+ text: ' spoken',+ startMs: 4000,+ endMs: 5100,+ timestampMs: 4550,+ confidence: null,+ },+ {+ text: ' word.',+ startMs: 5100,+ endMs: 6500,+ timestampMs: 5800,+ confidence: null,+ },+ ]}width={props.width ?? 681}height={props.height ?? 252}style={{translate: '0px 0px'}}@@ -567,11 +571,3 @@ const MovingPillCaptionsWithControls: React.FC<</div>);};--export const MovingPillCaptions = Interactive.withSchema({- Component: MovingPillCaptionsWithControls,- componentName: '<MovingPillCaptions>',- componentIdentity: null,- schema: movingPillCaptionsSchema,- supportsEffects: false,-}) as React.FC<MovingPillCaptionsProps>;diff --git a/packages/studio/src/components/InlineCaptionInspector.tsx b/packages/studio/src/components/InlineCaptionInspector.tsxindex 35cd528fb5..2591d1fc1e 100644--- a/packages/studio/src/components/InlineCaptionInspector.tsx+++ b/packages/studio/src/components/InlineCaptionInspector.tsx@@ -15,10 +15,7 @@ import {Internals} from 'remotion';import type {CodePosition} from '../error-overlay/react-overlay/utils/get-source-map';import {StudioServerConnectionCtx} from '../helpers/client-id';import {CaptionInspector} from './CaptionInspector';-import {- saveInlineCaptionPatches,- saveSequenceProps,-} from './Timeline/save-sequence-prop';+import {saveInlineCaptionPatches} from './Timeline/save-sequence-prop';const serializeCaptions = (captions: Caption[]): string => {return JSON.stringify(captions);@@ -98,8 +95,6 @@ export const InlineCaptionInspector: React.FC<{: null;const canSave =!readOnlyStudio && clientId !== null && captionStatus?.status === 'static';- const captionsAreOmitted =- captionStatus?.status === 'static' && captionStatus.codeValue === undefined;const [draftCaptions, setDraftCaptions] = useState(captions);const savedCaptions = useRef(captions);const runtimeSignature = serializeCaptions(captions);@@ -152,51 +147,21 @@ export const InlineCaptionInspector: React.FC<{}savedCaptions.current = nextCaptions;- if (captionsAreOmitted) {- const defaultCaptions =- controls.schema.captions?.type === 'remotion-captions'- ? controls.schema.captions.default- : undefined;- saveSequenceProps({- changes: [- {- fileName: validatedLocation.source,- nodePath,- fieldKey: 'captions',- value: nextCaptions,- defaultValue:- defaultCaptions === undefined- ? null- : JSON.stringify(defaultCaptions),- schema: controls.schema,- },- ],- addedKeyframes: null,- movedKeyframes: null,- setPropStatuses,- clientId,- undoLabel: 'Update captions',- redoLabel: 'Update captions again',- });- } else {- saveInlineCaptionPatches({- fileName: validatedLocation.source,- nodePath,- schema: controls.schema,- patches,- nextCaptions,- setPropStatuses,- clientId,- undoLabel: 'Update captions',- redoLabel: 'Update captions again',- });- }-+ saveInlineCaptionPatches({+ fileName: validatedLocation.source,+ nodePath,+ schema: controls.schema,+ patches,+ nextCaptions,+ setPropStatuses,+ clientId,+ undoLabel: 'Update captions',+ redoLabel: 'Update captions again',+ });clearDragOverrides(nodePath);},[canSave,- captionsAreOmitted,clearDragOverrides,clientId,controls.schema,diff --git a/packages/studio/src/components/InspectorSequenceSection.tsx b/packages/studio/src/components/InspectorSequenceSection.tsxindex 3afb086e77..2c821bb69b 100644--- a/packages/studio/src/components/InspectorSequenceSection.tsx+++ b/packages/studio/src/components/InspectorSequenceSection.tsx@@ -636,7 +636,7 @@ export const InspectorSequenceSection: React.FC<{);const inlineCaptionValue =schema.captions?.type === 'remotion-captions'- ? (runtimeValues.captions ?? schema.captions.default)+ ? runtimeValues.captions: null;const inlineCaptions = Array.isArray(inlineCaptionValue)? (inlineCaptionValue as Caption[])