🎥 Make videos programmatically with React
static demo
Jonny Burgerf33a7751cd3b
diff --git a/packages/bundler/src/bundler.ts b/packages/bundler/src/bundler.tsindex 0a141681ce..ac85dd1262 100644--- a/packages/bundler/src/bundler.ts+++ b/packages/bundler/src/bundler.ts@@ -55,9 +55,19 @@ export const bundle = async (}// TODO: Make this better in Lambda- // TODO: Copy /public folder- const html = indexHtml(`/`);+ const html = indexHtml(`/public`);fs.writeFileSync(path.join(outDir, 'index.html'), html);+ if (process.platform === 'win32') {+ await execa('xcopy', [+ path.join(process.cwd(), 'public'),+ outDir,+ '/s',+ '/e',+ '/y',+ ]);+ } else {+ await execa('cp', ['-a', path.join(process.cwd(), 'public'), outDir]);+ }return outDir;};diff --git a/packages/bundler/src/start-server.ts b/packages/bundler/src/start-server.tsindex c0c5998c4f..eabf90b767 100644--- a/packages/bundler/src/start-server.ts+++ b/packages/bundler/src/start-server.ts@@ -44,12 +44,9 @@ export const startServer = async (});const compiler = webpack(config);- const hash = crypto.randomBytes(6).toString('hex');+ const hash = `static-${crypto.randomBytes(6).toString('hex')}`;- app.use(- `/static-${hash}`,- express.static(path.join(process.cwd(), 'public'))- );+ app.use(hash, express.static(path.join(process.cwd(), 'public')));app.use(webpackDevMiddleware(compiler));app.use(webpackHotMiddleware(compiler, {diff --git a/packages/core/src/static-file.ts b/packages/core/src/static-file.tsindex 7eba8cd30f..d8a8b8ca5a 100644--- a/packages/core/src/static-file.ts+++ b/packages/core/src/static-file.ts@@ -8,7 +8,7 @@ const trimLeadingSlash = (path: string) => {const inner = (path: string): string => {if (window.remotion_staticBase) {- return `/static-${window.remotion_staticBase}/${trimLeadingSlash(path)}`;+ return `${window.remotion_staticBase}/${trimLeadingSlash(path)}`;}return `/${trimLeadingSlash(path)}`;diff --git a/packages/example/public/nested/mp4.png b/packages/example/public/nested/mp4.pngnew file mode 100644index 0000000000..2d36a37e67Binary files /dev/null and b/packages/example/public/nested/mp4.png differdiff --git a/packages/example/src/StaticServer/index.tsx b/packages/example/src/StaticServer/index.tsxindex 39fa752a7f..718823d704 100644--- a/packages/example/src/StaticServer/index.tsx+++ b/packages/example/src/StaticServer/index.tsx@@ -1,11 +1,19 @@-import React from 'react';-import {Img, staticFile} from 'remotion';+import React, {useState} from 'react';+import {continueRender, delayRender, Img, staticFile} from 'remotion';export const StaticDemo: React.FC = () => {+ const [handle1] = useState(() => delayRender());+ const [handle2] = useState(() => delayRender());return (<>- <Img src={staticFile('logo.png')} />- <Img src="/logo.png" />+ <Img+ src={staticFile('logo.png')}+ onLoad={() => continueRender(handle1)}+ />+ <Img+ src={staticFile('/nested/mp4.png')}+ onLoad={() => continueRender(handle2)}+ /></>);};diff --git a/packages/example/src/Video.tsx b/packages/example/src/Video.tsxindex 08ac70c4b8..b59fa52dbe 100644--- a/packages/example/src/Video.tsx+++ b/packages/example/src/Video.tsx@@ -285,7 +285,7 @@ export const Index: React.FC = () => {/><Still id="Orb" component={OrbScene} width={2000} height={2000} /><Still- id="static-file"+ id="static-demo"component={StaticDemo}width={2000}height={2000}diff --git a/tests/rendering.test.ts b/tests/rendering.test.tsindex 5ba72d1a71..26f7d65b77 100644--- a/tests/rendering.test.ts+++ b/tests/rendering.test.ts@@ -280,6 +280,19 @@ test("Should fail to render an audio file that doesn't have any audio inputs", afs.unlinkSync(out);});+test.only("Should render a still that uses the staticFile() API", async () => {+ const out = outputPath.replace(".mp4", ".png");+ const task = await execa(+ "npx",+ ["remotion", "still", "src/index.tsx", "static-demo", out, "--log=verbose"],+ {+ cwd: "packages/example",+ reject: false,+ }+ );+ expect(task.exitCode).toBe(0);+});+test("Dynamic duration should work", async () => {const randomDuration = Math.round(Math.random() * 18 + 2);const task = await execa(