Skip to content

🎥 Make videos programmatically with React

richer info

Jonny Burgerd364982d9d2a
diff --git a/packages/cli/src/compositions.ts b/packages/cli/src/compositions.ts
new file mode 100644
index 0000000000..eaa4ca4465
--- /dev/null
+++ b/packages/cli/src/compositions.ts
@@ -0,0 +1,63 @@
+import path from 'path';
+import {bundle} from '@remotion/bundler';
+import {getCompositions, RenderInternals} from '@remotion/renderer';
+import {loadConfig} from './get-config-file-name';
+import {parsedCli} from './parse-command-line';
+import {Log} from './log';
+import {bundleOnCli} from './setup-cache';
+
+export const listCompositionsCommand = async () => {
+ const file = parsedCli._[1];
+
+ if (!file) {
+ Log.error(
+ 'The compositions command requires you to specify a root file. For example'
+ );
+ Log.error(' npx remotion compositions src/index.tsx');
+ Log.error(
+ 'See https://www.remotion.dev/docs/register-root for more information.'
+ );
+ process.exit(1);
+ }
+
+ const fullPath = path.join(process.cwd(), file);
+
+ loadConfig();
+
+ const bundled = await bundleOnCli(fullPath, 1);
+
+ const compositions = await getCompositions(bundled);
+ Log.info();
+ Log.info('The following compositions are available:');
+ Log.info();
+
+ const firstColumnLength =
+ RenderInternals.max(compositions.map(({id}) => id.length)) + 4;
+ const secondColumnLength = 8;
+ const thirdColumnLength = 15;
+
+ Log.info(
+ `${'Composition'.padEnd(firstColumnLength, ' ')}${'FPS'.padEnd(
+ secondColumnLength
+ )}${'Dimensions'.padEnd(thirdColumnLength, ' ')}Duration`
+ );
+ Log.info(
+ compositions
+ .map((comp) => {
+ const isStill = comp.durationInFrames === 1;
+ const dimensions = `${comp.width}x${comp.height}`;
+ const fps = isStill ? '' : comp.fps.toString();
+ const durationInSeconds = (comp.durationInFrames / comp.fps).toFixed(2);
+ const formattedDuration = isStill
+ ? 'Still'
+ : `${comp.durationInFrames} (${durationInSeconds} sec)`;
+ return [
+ comp.id.padEnd(firstColumnLength, ' '),
+ fps.padEnd(secondColumnLength, ' '),
+ dimensions.padEnd(thirdColumnLength, ' '),
+ formattedDuration,
+ ].join('');
+ })
+ .join('\n')
+ );
+};
diff --git a/packages/cli/src/index.tsx b/packages/cli/src/index.tsx
index a5d89d70f1..4c889aaee8 100644
--- a/packages/cli/src/index.tsx
+++ b/packages/cli/src/index.tsx
@@ -1,7 +1,7 @@
import {checkNodeVersion} from './check-version';
import {Log} from './log';
import {parsedCli} from './parse-command-line';
-import {listCompositionsCommand} from "./listCompositions";
+import {listCompositionsCommand} from './compositions';
import {previewCommand} from './preview';
import {printHelp} from './print-help';
import {render} from './render';
@@ -30,9 +30,9 @@ export const cli = async () => {
}
try {
- if (command === 'compositions') {
- await listCompositionsCommand();
- } else if (command === 'preview') {
+ if (command === 'compositions') {
+ await listCompositionsCommand();
+ } else if (command === 'preview') {
await previewCommand();
} else if (command === 'render') {
await render();
diff --git a/packages/cli/src/listCompositions.tsx b/packages/cli/src/listCompositions.tsx
deleted file mode 100644
index ef537d5cf6..0000000000
--- a/packages/cli/src/listCompositions.tsx
+++ /dev/null
@@ -1,19 +0,0 @@
-import path from "path";
-import {bundle} from '@remotion/bundler';
-import {getCompositions} from "@remotion/renderer";
-import {loadConfig} from "./get-config-file-name";
-import {parsedCli} from "./parse-command-line";
-import {Log} from "./log";
-
-export const listCompositionsCommand = async () => {
- const file = parsedCli._[1];
- const fullPath = path.join(process.cwd(), file);
-
- loadConfig();
-
- const bundled = await bundle(fullPath);
-
- const compositions = await getCompositions(bundled);
-
- Log.info(compositions.map(({ id }) => id).join('\n'))
-}
diff --git a/packages/cli/src/preview.ts b/packages/cli/src/preview.ts
index 295cac9090..636bef85a2 100644
--- a/packages/cli/src/preview.ts
+++ b/packages/cli/src/preview.ts
@@ -14,6 +14,18 @@ const noop = () => undefined;
export const previewCommand = async () => {
const file = parsedCli._[1];
+
+ if (!file) {
+ Log.error(
+ 'The preview command requires you to specify a root file. For example'
+ );
+ Log.error(' npx remotion preview src/index.tsx');
+ Log.error(
+ 'See https://www.remotion.dev/docs/register-root for more information.'
+ );
+ process.exit(1);
+ }
+
const {port: desiredPort} = parsedCli;
const fullPath = path.join(process.cwd(), file);
diff --git a/packages/cli/src/print-help.ts b/packages/cli/src/print-help.ts
index dc4346915d..39dfd49336 100644
--- a/packages/cli/src/print-help.ts
+++ b/packages/cli/src/print-help.ts
@@ -19,6 +19,8 @@ export const printHelp = () => {
Log.info();
Log.info('Available commands:');
Log.info('');
+ Log.info('remotion compositions <index-file.ts>');
+ Log.info(chalk.gray('Prints the available compositions.'));
Log.info('remotion preview <index-file.ts>');
Log.info(chalk.gray('Start the preview server.'));
printFlags([['--props', 'Pass input props as filename or as JSON']]);
@@ -59,11 +61,13 @@ export const printHelp = () => {
['--port', 'Custom port to use for the HTTP server'],
['--env-file', 'Specify a location for a dotenv file'],
]);
- Log.info();
- Log.info('remotion compositions <index-file.ts>');
- Log.info(
- chalk.gray('Print list of composition ids from the index file provided separated by line break')
- );
+ Log.info();
+ Log.info('remotion compositions <index-file.ts>');
+ Log.info(
+ chalk.gray(
+ 'Print list of composition ids from the index file provided separated by line break'
+ )
+ );
Log.info();
Log.info('remotion ' + VERSIONS_COMMAND);
Log.info(
diff --git a/packages/renderer/src/index.ts b/packages/renderer/src/index.ts
index 8ac9ca3bc5..ab397dadf0 100644
--- a/packages/renderer/src/index.ts
+++ b/packages/renderer/src/index.ts
@@ -6,6 +6,7 @@ import {
} from './ffmpeg-flags';
import {getActualConcurrency} from './get-concurrency';
import {ensureLocalBrowser} from './get-local-browser-executable';
+import {max, min} from './min-max';
import {openBrowser} from './open-browser';
import {validateEvenDimensionsWithCodec} from './validate-even-dimensions-with-codec';
import {binaryExists, validateFfmpeg} from './validate-ffmpeg';
@@ -35,4 +36,6 @@ export const RenderInternals = {
binaryExists,
getFfmpegBuildInfo,
validateEvenDimensionsWithCodec,
+ min,
+ max,
};