🎥 Make videos programmatically with React
stub out CLI
Jonny Burgerccbd29c1018f
diff --git a/packages/cli/src/get-cli-options.ts b/packages/cli/src/get-cli-options.tsindex 8829e3b2b3..c7133d5c83 100644--- a/packages/cli/src/get-cli-options.ts+++ b/packages/cli/src/get-cli-options.ts@@ -194,5 +194,7 @@ export const getCliOptions = async () => {pixelFormat,imageFormat,proResProfile,+ // TODO: parse flag+ frame: 0,};};diff --git a/packages/cli/src/handle-common-errors.ts b/packages/cli/src/handle-common-errors.tsnew file mode 100644index 0000000000..2e2b5d5c49--- /dev/null+++ b/packages/cli/src/handle-common-errors.ts@@ -0,0 +1,16 @@+import {Log} from './log';++export const handleCommonError = (err: Error) => {+ Log.error(err.message);+ if (err.message.includes('Could not play video with')) {+ Log.info();+ Log.info(+ '💡 Get help for this issue at https://remotion.dev/docs/media-playback-error'+ );+ }++ if (err.message.includes('A delayRender was called')) {+ Log.info();+ Log.info('💡 Get help for this issue at https://remotion.dev/docs/timeout');+ }+};diff --git a/packages/cli/src/index.tsx b/packages/cli/src/index.tsxindex 770dcdc4d9..82c13a0449 100644--- a/packages/cli/src/index.tsx+++ b/packages/cli/src/index.tsx@@ -22,6 +22,8 @@ export const cli = async () => {await previewCommand();} else if (command === 'render') {await render();+ } else if (command === 'still') {+ await render();} else if (command === 'upgrade') {await upgrade();} else {diff --git a/packages/cli/src/render.tsx b/packages/cli/src/render.tsxindex 74d4d0a8f3..4ef19aee49 100644--- a/packages/cli/src/render.tsx+++ b/packages/cli/src/render.tsx@@ -15,6 +15,7 @@ import {Internals} from 'remotion';import {getCliOptions} from './get-cli-options';import {getCompositionId} from './get-composition-id';import {loadConfig} from './get-config-file-name';+import {handleCommonError} from './handle-common-errors';import {Log} from './log';import {parseCommandLine, parsedCli} from './parse-command-line';import {@@ -37,18 +38,7 @@ const onError = async (info: OnErrorInfo) => {);}- Log.error(info.error.message);- if (info.error.message.includes('Could not play video with')) {- Log.info();- Log.info(- '💡 Get help for this issue at https://remotion.dev/docs/media-playback-error'- );- }-- if (info.error.message.includes('A delayRender was called')) {- Log.info();- Log.info('💡 Get help for this issue at https://remotion.dev/docs/timeout');- }+ handleCommonError(info.error);process.exit(1);};diff --git a/packages/cli/src/still.ts b/packages/cli/src/still.tsnew file mode 100644index 0000000000..d11a155537--- /dev/null+++ b/packages/cli/src/still.ts@@ -0,0 +1,163 @@+import {bundle, BundlerInternals} from '@remotion/bundler';+import {+ getCompositions,+ RenderInternals,+ renderStill,+} from '@remotion/renderer';+import chalk from 'chalk';+import {mkdirSync} from 'node:fs';+import path from 'path';+import {Internals} from 'remotion';+import {getCliOptions} from './get-cli-options';+import {getCompositionId} from './get-composition-id';+import {loadConfig} from './get-config-file-name';+import {handleCommonError} from './handle-common-errors';+import {Log} from './log';+import {parseCommandLine, parsedCli} from './parse-command-line';+import {+ createProgressBar,+ makeBundlingProgress,+ makeRenderingProgress,+} from './progress-bar';+import {getUserPassedOutputLocation} from './user-passed-output-location';++export const still = async () => {+ const file = parsedCli._[1];+ const fullPath = path.join(process.cwd(), file);++ const startTime = Date.now();+ parseCommandLine();+ const appliedName = loadConfig();+ if (appliedName) {+ Log.verbose(`Applied configuration from ${appliedName}.`);+ } else {+ Log.verbose('No config file loaded.');+ }++ const userOutput = path.resolve(process.cwd(), getUserPassedOutputLocation());++ const {+ inputProps,+ envVariables,+ quality,+ browser,+ imageFormat,+ frame,+ } = await getCliOptions();++ if (imageFormat === 'none') {+ Log.error(+ 'No image format was selected - this is probably an error in Remotion - please post your command on Github Issues for help.'+ );+ process.exit(1);+ }++ const browserInstance = RenderInternals.openBrowser(browser, {+ shouldDumpIo: Internals.Logging.isEqualOrBelowLogLevel('verbose'),+ });++ mkdirSync(path.join(userOutput, '..'), {+ recursive: true,+ });++ const steps = 2;++ const shouldCache = Internals.getWebpackCaching();+ const cacheExistedBefore = BundlerInternals.cacheExists('production', null);+ if (cacheExistedBefore && !shouldCache) {+ process.stdout.write('🧹 Cache disabled but found. Deleting... ');+ await BundlerInternals.clearCache('production', null);+ process.stdout.write('done. \n');+ }++ const bundleStartTime = Date.now();+ const bundlingProgress = createProgressBar();+ const bundled = await bundle(+ fullPath,+ (progress) => {+ bundlingProgress.update(+ makeBundlingProgress({progress: progress / 100, steps, doneIn: null})+ );+ },+ {+ enableCaching: shouldCache,+ }+ );+ bundlingProgress.update(+ makeBundlingProgress({+ progress: 1,+ steps,+ doneIn: Date.now() - bundleStartTime,+ }) + '\n'+ );+ Log.verbose('Bundled under', bundled);++ const cacheExistedAfter = BundlerInternals.cacheExists('production', null);+ if (cacheExistedAfter && !cacheExistedBefore) {+ Log.info('⚡️ Cached bundle. Subsequent builds will be faster.');+ }++ const openedBrowser = await browserInstance;+ const comps = await getCompositions(bundled, {+ browser,+ inputProps,+ browserInstance: openedBrowser,+ envVariables,+ });+ const compositionId = getCompositionId(comps);++ const composition = comps.find((c) => c.id === compositionId);+ if (!composition) {+ throw new Error(`Cannot find composition with ID ${compositionId}`);+ }++ const renderProgress = createProgressBar();+ const renderStart = Date.now();++ await renderStill({+ composition,+ frame,+ output: userOutput,+ webpackBundle: bundled,+ quality,+ browser,+ dumpBrowserLogs: Internals.Logging.isEqualOrBelowLogLevel('verbose'),+ envVariables,+ imageFormat,+ inputProps,+ onError: (err: Error) => {+ Log.error();+ Log.error('The following error occured when rendering the still:');++ handleCommonError(err);++ process.exit(1);+ },+ puppeteerInstance: openedBrowser,+ });++ const closeBrowserPromise = openedBrowser.close();+ renderProgress.update(+ makeRenderingProgress({+ frames: 1,+ concurrency: 1,+ doneIn: Date.now() - renderStart,+ steps,+ totalFrames: 1,+ })+ );++ Log.info(chalk.green('\nYour still frame is ready!'));++ const seconds = Math.round((Date.now() - startTime) / 1000);+ Log.info(+ [+ '- Total render time:',+ seconds,+ seconds === 1 ? 'second' : 'seconds',+ ].join(' ')+ );+ Log.info('-', 'Output can be found at:');+ Log.info(chalk.cyan(`▶️ ${userOutput}`));+ await closeBrowserPromise;+};