Skip to content

🎥 Make videos programmatically with React

aha

Jonny Burger7a1e9fe905ab
diff --git a/packages/studio-server/src/test/discriminated-union-update.test.ts b/packages/studio-server/src/test/discriminated-union-update.test.ts
index c36005cf35..2d5bd24cf5 100644
--- a/packages/studio-server/src/test/discriminated-union-update.test.ts
+++ b/packages/studio-server/src/test/discriminated-union-update.test.ts
@@ -3,19 +3,20 @@ import assert from 'node:assert';
import {readFileSync} from 'node:fs';
import path from 'node:path';
import type {SchemaFieldInfo} from '@remotion/studio-shared';
+import {Internals} from 'remotion';
import {parseAst} from '../codemods/parse-ast';
import {updateSequenceProps} from '../codemods/update-sequence-props';
import {lineColumnToNodePath} from '../preview-server/routes/can-update-sequence-props';
test('Should be able to update a discriminated union', async () => {
const file = readFileSync(
- path.join(__dirname, 'snapshots', 'discriminated-union.txt'),
+ path.join(__dirname, 'snapshots', 'discriminated-union.tsx'),
'utf-8',
);
const ast = parseAst(file);
- const nodePath = lineColumnToNodePath(ast, 177);
+ const nodePath = lineColumnToNodePath(ast, 3);
assert(nodePath, 'No node path found');
const field: SchemaFieldInfo = {
@@ -29,39 +30,7 @@ test('Should be able to update a discriminated union', async () => {
type: 'enum',
default: 'absolute-fill',
description: 'Layout',
- variants: {
- 'absolute-fill': {
- 'style.translate': {
- type: 'translate',
- step: 1,
- default: '0px 0px',
- description: 'Position',
- },
- 'style.scale': {
- type: 'number',
- min: 0.05,
- max: 100,
- step: 0.01,
- default: 1,
- description: 'Scale',
- },
- 'style.rotate': {
- type: 'rotation',
- step: 1,
- default: '0deg',
- description: 'Rotation',
- },
- 'style.opacity': {
- type: 'number',
- min: 0,
- max: 1,
- step: 0.01,
- default: 1,
- description: 'Opacity',
- },
- },
- none: {},
- },
+ variants: Internals.sequenceSchema.layout.variants,
},
};
@@ -70,11 +39,11 @@ test('Should be able to update a discriminated union', async () => {
nodePath,
key: 'layout',
value: 'none',
- defaultValue: 'absolute-fill',
+ defaultValue: field.fieldSchema.default,
});
const expected = readFileSync(
- path.join(__dirname, 'snapshots', 'discriminated-union-expected.txt'),
+ path.join(__dirname, 'snapshots', 'discriminated-union-expected.tsx'),
'utf-8',
);
const actualLines = update.output.split('\n');
diff --git a/packages/studio-server/src/test/snapshots/discriminated-union-expected.tsx b/packages/studio-server/src/test/snapshots/discriminated-union-expected.tsx
new file mode 100644
index 0000000000..14b3b23492
--- /dev/null
+++ b/packages/studio-server/src/test/snapshots/discriminated-union-expected.tsx
@@ -0,0 +1,12 @@
+export const ExperimentalControlsShowcase: React.FC = () => {
+ return (
+ <Sequence
+ style={{
+ scale: 1.74,
+ }}
+ layout={'none'}
+ >
+ hi
+ </Sequence>
+ );
+};
diff --git a/packages/studio-server/src/test/snapshots/discriminated-union-expected.txt b/packages/studio-server/src/test/snapshots/discriminated-union-expected.txt
deleted file mode 100644
index 26e2ac89a4..0000000000
--- a/packages/studio-server/src/test/snapshots/discriminated-union-expected.txt
+++ /dev/null
@@ -1,190 +0,0 @@
-import {Gif} from '@remotion/gif';
-import {LightLeak} from '@remotion/light-leaks';
-import {Audio, Video} from '@remotion/media';
-import {Starburst} from '@remotion/starburst';
-import React from 'react';
-import {AbsoluteFill, HtmlInCanvas, Img, Sequence, staticFile} from 'remotion';
-
-const Tile: React.FC<{
- readonly title: string;
- readonly children: React.ReactNode;
-}> = ({title, children}) => {
- return (
- <div
- style={{
- flex: 1,
- display: 'flex',
- flexDirection: 'column',
- border: '2px solid #333',
- borderRadius: 8,
- overflow: 'hidden',
- backgroundColor: '#111',
- minWidth: 0,
- minHeight: 0,
- }}
- >
- <div
- style={{
- padding: '8px 12px',
- fontFamily: 'monospace',
- fontSize: 16,
- color: '#fff',
- backgroundColor: '#222',
- }}
- >
- {title}
- </div>
- <div
- style={{
- flex: 1,
- position: 'relative',
- display: 'flex',
- alignItems: 'center',
- justifyContent: 'center',
- overflow: 'hidden',
- }}
- >
- {children}
- </div>
- </div>
- );
-};
-
-export const ExperimentalControlsShowcase: React.FC = () => {
- return (
- <AbsoluteFill style={{backgroundColor: 'black', padding: 16, gap: 16}}>
- <div style={{flex: 1, display: 'flex', flexDirection: 'row', gap: 16}}>
- <Tile title="Img">
- <Img
- src={staticFile('1.jpg')}
- style={{
- maxWidth: '100%',
- maxHeight: '100%',
- translate: '0px 93px',
- scale: 1.98,
- }}
- />
- </Tile>
- <Tile title="Sequence">
- <Sequence
- durationInFrames={120}
- name="inner-sequence"
- style={{
- translate: '0px 66px',
- scale: 2.05,
- }}
- >
- <AbsoluteFill
- style={{
- backgroundColor: '#3344ff',
- color: 'white',
- fontFamily: 'sans-serif',
- fontSize: 40,
- alignItems: 'center',
- justifyContent: 'center',
- }}
- >
- Sequence
- </AbsoluteFill>
- </Sequence>
- </Tile>
- <Tile title="HtmlInCanvas">
- <HtmlInCanvas
- width={400}
- height={300}
- style={{
- translate: '0px -124px',
- scale: 2.06,
- rotate: '48deg',
- }}
- >
- <div
- style={{
- width: 400,
- height: 300,
- backgroundColor: '#101728',
- color: 'white',
- fontFamily: 'sans-serif',
- fontSize: 32,
- alignItems: 'center',
- justifyContent: 'center',
- }}
- >
- HtmlInCanvas
- </div>
- </HtmlInCanvas>
- </Tile>
- <Tile title="LightLeak">
- <AbsoluteFill style={{backgroundColor: 'black'}}>
- <LightLeak
- durationInFrames={120}
- seed={3}
- hueShift={30}
- style={{
- translate: '0px 81px',
- scale: 1.1,
- }}
- />
- </AbsoluteFill>
- </Tile>
- </div>
- <div style={{flex: 1, display: 'flex', flexDirection: 'row', gap: 16}}>
- <Tile title="Starburst">
- <AbsoluteFill style={{backgroundColor: 'black'}}>
- <Starburst
- rays={16}
- colors={['#ffdd00', '#ff8800']}
- vignette={0.5}
- />
- </AbsoluteFill>
- </Tile>
- <Tile title="Gif">
- <Gif
- src={staticFile('giphy.gif')}
- fit="contain"
- width={400}
- height={300}
- style={{
- translate: '0px 59px',
- }}
- />
- </Tile>
- <Tile title="Video">
- <Video
- src={staticFile('bigbuckbunny.mp4')}
- style={{
- width: '100%',
- height: '100%',
- translate: '0px -27px',
- }}
- objectFit="contain"
- />
- </Tile>
- <Tile title="Audio">
- <div
- style={{
- color: 'white',
- fontFamily: 'sans-serif',
- fontSize: 24,
- textAlign: 'center',
- }}
- >
- Audio (no visual)
- <Audio src={staticFile('music.mp3')} volume={1.29} />
- </div>
- </Tile>
- <Tile title="Sequence layout='none'">
- <Sequence
- name="layout='none'"
- style={{
- scale: 1.74,
- }}
- layout={'none'}
- >
- hi
- </Sequence>
- </Tile>
- </div>
- </AbsoluteFill>
- );
-};
diff --git a/packages/studio-server/src/test/snapshots/discriminated-union.tsx b/packages/studio-server/src/test/snapshots/discriminated-union.tsx
new file mode 100644
index 0000000000..dfecd7908c
--- /dev/null
+++ b/packages/studio-server/src/test/snapshots/discriminated-union.tsx
@@ -0,0 +1,11 @@
+export const ExperimentalControlsShowcase: React.FC = () => {
+ return (
+ <Sequence
+ style={{
+ scale: 1.74,
+ }}
+ >
+ hi
+ </Sequence>
+ );
+};
diff --git a/packages/studio-server/src/test/snapshots/discriminated-union.txt b/packages/studio-server/src/test/snapshots/discriminated-union.txt
deleted file mode 100644
index b62743b84a..0000000000
--- a/packages/studio-server/src/test/snapshots/discriminated-union.txt
+++ /dev/null
@@ -1,189 +0,0 @@
-import {Gif} from '@remotion/gif';
-import {LightLeak} from '@remotion/light-leaks';
-import {Audio, Video} from '@remotion/media';
-import {Starburst} from '@remotion/starburst';
-import React from 'react';
-import {AbsoluteFill, HtmlInCanvas, Img, Sequence, staticFile} from 'remotion';
-
-const Tile: React.FC<{
- readonly title: string;
- readonly children: React.ReactNode;
-}> = ({title, children}) => {
- return (
- <div
- style={{
- flex: 1,
- display: 'flex',
- flexDirection: 'column',
- border: '2px solid #333',
- borderRadius: 8,
- overflow: 'hidden',
- backgroundColor: '#111',
- minWidth: 0,
- minHeight: 0,
- }}
- >
- <div
- style={{
- padding: '8px 12px',
- fontFamily: 'monospace',
- fontSize: 16,
- color: '#fff',
- backgroundColor: '#222',
- }}
- >
- {title}
- </div>
- <div
- style={{
- flex: 1,
- position: 'relative',
- display: 'flex',
- alignItems: 'center',
- justifyContent: 'center',
- overflow: 'hidden',
- }}
- >
- {children}
- </div>
- </div>
- );
-};
-
-export const ExperimentalControlsShowcase: React.FC = () => {
- return (
- <AbsoluteFill style={{backgroundColor: 'black', padding: 16, gap: 16}}>
- <div style={{flex: 1, display: 'flex', flexDirection: 'row', gap: 16}}>
- <Tile title="Img">
- <Img
- src={staticFile('1.jpg')}
- style={{
- maxWidth: '100%',
- maxHeight: '100%',
- translate: '0px 93px',
- scale: 1.98,
- }}
- />
- </Tile>
- <Tile title="Sequence">
- <Sequence
- durationInFrames={120}
- name="inner-sequence"
- style={{
- translate: '0px 66px',
- scale: 2.05,
- }}
- >
- <AbsoluteFill
- style={{
- backgroundColor: '#3344ff',
- color: 'white',
- fontFamily: 'sans-serif',
- fontSize: 40,
- alignItems: 'center',
- justifyContent: 'center',
- }}
- >
- Sequence
- </AbsoluteFill>
- </Sequence>
- </Tile>
- <Tile title="HtmlInCanvas">
- <HtmlInCanvas
- width={400}
- height={300}
- style={{
- translate: '0px -124px',
- scale: 2.06,
- rotate: '48deg',
- }}
- >
- <div
- style={{
- width: 400,
- height: 300,
- backgroundColor: '#101728',
- color: 'white',
- fontFamily: 'sans-serif',
- fontSize: 32,
- alignItems: 'center',
- justifyContent: 'center',
- }}
- >
- HtmlInCanvas
- </div>
- </HtmlInCanvas>
- </Tile>
- <Tile title="LightLeak">
- <AbsoluteFill style={{backgroundColor: 'black'}}>
- <LightLeak
- durationInFrames={120}
- seed={3}
- hueShift={30}
- style={{
- translate: '0px 81px',
- scale: 1.1,
- }}
- />
- </AbsoluteFill>
- </Tile>
- </div>
- <div style={{flex: 1, display: 'flex', flexDirection: 'row', gap: 16}}>
- <Tile title="Starburst">
- <AbsoluteFill style={{backgroundColor: 'black'}}>
- <Starburst
- rays={16}
- colors={['#ffdd00', '#ff8800']}
- vignette={0.5}
- />
- </AbsoluteFill>
- </Tile>
- <Tile title="Gif">
- <Gif
- src={staticFile('giphy.gif')}
- fit="contain"
- width={400}
- height={300}
- style={{
- translate: '0px 59px',
- }}
- />
- </Tile>
- <Tile title="Video">
- <Video
- src={staticFile('bigbuckbunny.mp4')}
- style={{
- width: '100%',
- height: '100%',
- translate: '0px -27px',
- }}
- objectFit="contain"
- />
- </Tile>
- <Tile title="Audio">
- <div
- style={{
- color: 'white',
- fontFamily: 'sans-serif',
- fontSize: 24,
- textAlign: 'center',
- }}
- >
- Audio (no visual)
- <Audio src={staticFile('music.mp3')} volume={1.29} />
- </div>
- </Tile>
- <Tile title="Sequence layout='none'">
- <Sequence
- name="layout='none'"
- style={{
- scale: 1.74,
- }}
- >
- hi
- </Sequence>
- </Tile>
- </div>
- </AbsoluteFill>
- );
-};