π₯ Make videos programmatically with React
cleanup and remove emojis over bugs
Jonny Burger2abe8434649a
diff --git a/packages/cli/src/progress-bar.ts b/packages/cli/src/progress-bar.tsindex 018f84ab9c..ce24607cbb 100644--- a/packages/cli/src/progress-bar.ts+++ b/packages/cli/src/progress-bar.ts@@ -36,7 +36,6 @@ export const makeBundlingProgress = ({doneIn: number | null;}) =>[- 'π¦',`(1/${steps})`,makeProgressBar(progress),`${doneIn ? 'Bundled' : 'Bundling'} code`,@@ -45,47 +44,53 @@ export const makeBundlingProgress = ({: chalk.gray(`${doneIn}ms`),].join(' ');+type RenderingProgressInput = {+ frames: number;+ totalFrames: number;+ steps: number;+ concurrency: number;+ doneIn: number | null;+};+export const makeRenderingProgress = ({frames,totalFrames,steps,concurrency,doneIn,-}: {- frames: number;- totalFrames: number;- steps: number;- concurrency: number;- doneIn: number | null;-}) => {+}: RenderingProgressInput) => {const progress = frames / totalFrames;return [- 'πΌ ',`(2/${steps})`,makeProgressBar(progress),[doneIn ? 'Rendered' : 'Rendering', `frames (${concurrency}x)`].filter(Internals.truthy).join(' '),- doneIn === null ? `${frames}/${totalFrames}` : chalk.gray(`${doneIn}ms`),+ doneIn === null+ ? `${frames+ .toString()+ .padStart(String(totalFrames).length, '0')}/${totalFrames}`+ : chalk.gray(`${doneIn}ms`),].join(' ');};+type StitchingProgressInput = {+ frames: number;+ totalFrames: number;+ steps: number;+ doneIn: number | null;+ parallelEncoding: boolean;+};+export const makeStitchingProgress = ({frames,totalFrames,steps,doneIn,parallelEncoding,-}: {- frames: number;- totalFrames: number;- steps: number;- doneIn: number | null;- parallelEncoding?: boolean;-}) => {+}: StitchingProgressInput) => {const progress = frames / totalFrames;return [- 'π ',`(3/${steps})`,makeProgressBar(progress),parallelEncoding@@ -94,3 +99,16 @@ export const makeStitchingProgress = ({doneIn === null ? `${frames}/${totalFrames}` : chalk.gray(`${doneIn}ms`),].join(' ');};++export const makeRenderingAndStitchingProgress = ({+ rendering,+ stitching,+}: {+ rendering: RenderingProgressInput;+ stitching: StitchingProgressInput | null;+}) => {+ return [+ makeRenderingProgress(rendering),+ stitching === null ? null : makeStitchingProgress(stitching),+ ].join('\n');+};diff --git a/packages/cli/src/render.tsx b/packages/cli/src/render.tsxindex b0c3b83684..01153d1bec 100644--- a/packages/cli/src/render.tsx+++ b/packages/cli/src/render.tsx@@ -19,8 +19,7 @@ import {Log} from './log';import {parsedCli} from './parse-command-line';import {createOverwriteableCliOutput,- makeRenderingProgress,- makeStitchingProgress,+ makeRenderingAndStitchingProgress,} from './progress-bar';import {bundleOnCli} from './setup-cache';import {getUserPassedFileExtension} from './user-passed-output-location';@@ -74,7 +73,9 @@ export const render = async () => {});}- const steps = shouldOutputImageSequence ? 2 : 3;+ const hasStitching = !shouldOutputImageSequence;++ const steps = hasStitching ? 3 : 2;const bundled = await bundleOnCli(fullPath, steps);@@ -120,17 +121,25 @@ export const render = async () => {let stitcherFfmpeg: ExecaChildProcess<string> | undefined;let preStitcher;let encodedFrames: number | null = null;- let renderedFrames: number;+ let renderedFrames = 0;let preEncodedFileLocation: string | undefined;const updateRenderProgress = () =>renderProgress.update(- makeRenderingProgress({- frames: renderedFrames || 0,- encodedFrames,- totalFrames,- concurrency: RenderInternals.getActualConcurrency(parallelism),- doneIn: null,- steps,+ makeRenderingAndStitchingProgress({+ rendering: {+ frames: renderedFrames,+ totalFrames,+ concurrency: RenderInternals.getActualConcurrency(parallelism),+ doneIn: null,+ steps,+ },+ stitching: {+ doneIn: null,+ frames: encodedFrames ?? 0,+ parallelEncoding,+ steps,+ totalFrames,+ },}));if (parallelEncoding) {@@ -204,13 +213,23 @@ export const render = async () => {}const closeBrowserPromise = openedBrowser.close();+ const finalizedRenderProgress = {+ frames: totalFrames,+ totalFrames,+ steps,+ concurrency: RenderInternals.getActualConcurrency(parallelism),+ doneIn: Date.now() - renderStart,+ };renderProgress.update(- makeRenderingProgress({- frames: totalFrames,- totalFrames,- steps,- concurrency: RenderInternals.getActualConcurrency(parallelism),- doneIn: Date.now() - renderStart,+ makeRenderingAndStitchingProgress({+ rendering: finalizedRenderProgress,+ stitching: {+ doneIn: null,+ frames: encodedFrames ?? 0,+ steps: 0,+ parallelEncoding,+ totalFrames,+ },}) + '\n');if (process.env.DEBUG) {@@ -224,7 +243,6 @@ export const render = async () => {throw new TypeError('CRF is unexpectedly not a number');}- const stitchingProgress = createOverwriteableCliOutput();const dirName = path.dirname(absoluteOutputFile);if (!fs.existsSync(dirName)) {@@ -233,15 +251,6 @@ export const render = async () => {});}- stitchingProgress.update(- makeStitchingProgress({- doneIn: null,- frames: 0,- steps,- totalFrames,- parallelEncoding,- })- );const stitchStart = Date.now();await stitchFramesToVideo({dir: outputDir,@@ -260,15 +269,16 @@ export const render = async () => {parallelism,ffmpegExecutable,onProgress: (frame: number) => {- stitchingProgress.update(- makeStitchingProgress({+ makeRenderingAndStitchingProgress({+ rendering: finalizedRenderProgress,+ stitching: {doneIn: null,frames: frame,steps,totalFrames,parallelEncoding,- })- );+ },+ });},onDownload: (src: string) => {Log.info('Downloading asset... ', src);@@ -276,13 +286,17 @@ export const render = async () => {webpackBundle: bundled,verbose: Internals.Logging.isEqualOrBelowLogLevel('verbose'),});- stitchingProgress.update(- makeStitchingProgress({- doneIn: Date.now() - stitchStart,- frames: totalFrames,- steps,- totalFrames,- parallelEncoding,+ renderProgress.update(+ makeRenderingAndStitchingProgress({+ rendering: finalizedRenderProgress,++ stitching: {+ doneIn: Date.now() - stitchStart,+ frames: totalFrames,+ steps,+ totalFrames,+ parallelEncoding,+ },}) + '\n');diff --git a/packages/core/src/config/index.ts b/packages/core/src/config/index.tsindex e72a40bcd9..95f6788dea 100644--- a/packages/core/src/config/index.ts+++ b/packages/core/src/config/index.ts@@ -98,10 +98,6 @@ export const Config = {*/setFrameRange,- /**- * Enabling parallel encoding means render frames and encode video at the same time.- * The image will be passed directly into ffmpeg.- *//*** Specify local ffmpeg executable.* Default: null, which will use ffmpeg available in PATH.diff --git a/packages/example/out.mp4 b/packages/example/out.mp4new file mode 100644index 0000000000..98f35745c0Binary files /dev/null and b/packages/example/out.mp4 differdiff --git a/packages/example/server.ts b/packages/example/server.tsindex 78fb95f45b..c2c5cf7fc2 100644--- a/packages/example/server.ts+++ b/packages/example/server.ts@@ -15,7 +15,7 @@ import express from 'express';import fs from 'fs';import os from 'os';import path from 'path';-import {webpackOverride} from './remotion.config';+import {webpackOverride} from './webpack-override';const app = express();const port = process.env.PORT || 8000;@@ -72,11 +72,10 @@ app.get('/', async (req, res) => {inputProps: {duration: 100,},- compositionId,imageFormat: 'jpeg',// TODO: Update or remove serverserveUrl: 'fsdf',- puppeteerInstance: null,+ puppeteerInstance: undefined,});const finalOutput = path.join(tmpDir, 'out.mp4');diff --git a/packages/example/src/HelloWorld/HelloWorld.tsx b/packages/example/src/HelloWorld/HelloWorld.tsxdeleted file mode 100644index 5617c4250e..0000000000--- a/packages/example/src/HelloWorld/HelloWorld.tsx+++ /dev/null@@ -1,14 +0,0 @@-import {useCurrentFrame} from 'remotion';-import './index.css';--export const HelloWorld = () => {- const frame = useCurrentFrame();-- return (- <div id='scene' style={{flex: 1, backgroundColor: 'gray'}}>- <div id='hello' style={{transform:`translate(${frame%300-150}px,${frame/300}px)`}}>- Hello World!- </div>- </div>- );-};diff --git a/packages/example/src/HelloWorld/index.css b/packages/example/src/HelloWorld/index.cssdeleted file mode 100644index eb295c2a99..0000000000--- a/packages/example/src/HelloWorld/index.css+++ /dev/null@@ -1,13 +0,0 @@--#hello {- color: #def;- /* This text shadow will make the browser lag, but when we render into a video file, it will be 60fps smooth!!! */- text-shadow: 0 16px 64px black;- font: bold 120px Arimo, sans-serif;-}-#scene{-- display: flex;- align-items: center;- justify-content: center;-}\ No newline at end of filediff --git a/packages/example/src/Video.tsx b/packages/example/src/Video.tsxindex c1321f5406..b57d7e4df8 100644--- a/packages/example/src/Video.tsx+++ b/packages/example/src/Video.tsx@@ -12,7 +12,6 @@ import {TenFrameTester} from './TenFrameTester';import ThreeBasic from './ThreeBasic';import {VideoSpeed} from './VideoSpeed';import {VideoTesting} from './VideoTesting';-import {HelloWorld} from './HelloWorld/HelloWorld';// Use it to test that UI does not regress on weird CSS//import './weird-css.css';@@ -21,14 +20,6 @@ export const Index: React.FC = () => {const inputProps = getInputProps();return (<>- <Composition- id="HelloWorld"- component={HelloWorld}- width={1920}- height={1080}- fps={60}- durationInFrames={60 * 30}- /><Compositionid="dynamic-duration"component={VideoTesting}diff --git a/packages/lambda/remotionlambda.zip b/packages/lambda/remotionlambda.zipindex a498276752..d713ec17c0 100644Binary files a/packages/lambda/remotionlambda.zip and b/packages/lambda/remotionlambda.zip differdiff --git a/packages/renderer/src/screenshot-dom-element.ts b/packages/renderer/src/screenshot-dom-element.tsindex bec107930d..eee4434493 100644--- a/packages/renderer/src/screenshot-dom-element.ts+++ b/packages/renderer/src/screenshot-dom-element.ts@@ -20,7 +20,6 @@ export const screenshotDOMElement = async ({const {selector} = opts;if (!selector) throw Error('Please provide a selector.');- // if (!path) throw Error('Please provide a path.');if (imageFormat === 'png') {await page.evaluate(() => {diff --git a/packages/renderer/src/stitcher.ts b/packages/renderer/src/stitcher.tsindex f082abb52e..4d30f26fd4 100644--- a/packages/renderer/src/stitcher.ts+++ b/packages/renderer/src/stitcher.ts@@ -62,7 +62,6 @@ const getAssetsData = async (options: StitcherOptions) => {const codec = options.codec ?? Internals.DEFAULT_CODEC;const encoderName = getCodecName(codec);const isAudioOnly = encoderName === null;- // eslint-disable-next-line @typescript-eslint/no-shadowconst [frameInfo, fileUrlAssets] = await Promise.all([options.preEncodedFileLocation? undefined@@ -81,7 +80,6 @@ const getAssetsData = async (options: StitcherOptions) => {markAllAssetsAsDownloaded();const assetPositions = calculateAssetPositions(fileUrlAssets);- // eslint-disable-next-line @typescript-eslint/no-shadowconst assetPaths = assetPositions.map((asset) => resolveAssetSrc(asset.src));const assetAudioDetails = await getAssetAudioDetails({@@ -103,7 +101,6 @@ const getAssetsData = async (options: StitcherOptions) => {console.log('filters', filters);}- // eslint-disable-next-line @typescript-eslint/no-shadowconst {complexFilterFlag, cleanup} = await createFfmpegComplexFilter(filters);return {@@ -114,7 +111,6 @@ const getAssetsData = async (options: StitcherOptions) => {};};-// eslint-disable-next-line complexityexport const spawnFfmpeg = async (options: StitcherOptions) => {Internals.validateDimension(options.height,@@ -243,7 +239,6 @@ export const spawnFfmpeg = async (options: StitcherOptions) => {cwd: options.dir,});task.stderr?.on('data', (data: Buffer) => {- // console.log(data.toString());if (options.onProgress) {const parsed = parseFfmpegProgress(data.toString());if (parsed !== undefined) {@@ -254,7 +249,6 @@ export const spawnFfmpeg = async (options: StitcherOptions) => {return {task, cleanup};};-// eslint-disable-next-line complexityexport const stitchFramesToVideo = async (options: StitcherOptions): Promise<void> => {