Skip to content

🎥 Make videos programmatically with React

apply main + still logic

Jonny Burgerceb6869048de
diff --git a/packages/cli/src/get-cli-options.ts b/packages/cli/src/get-cli-options.ts
index b581a0a53a..a4ef5111f9 100644
--- a/packages/cli/src/get-cli-options.ts
+++ b/packages/cli/src/get-cli-options.ts
@@ -166,8 +166,10 @@ const getAndValidateBrowser = async () => {
return browser;
};
-export const getCliOptions = async (options: {isLambda: boolean; type: 'still' | 'series'}) => {
-export const getCliOptions = async () => {
+export const getCliOptions = async (options: {
+ isLambda: boolean;
+ type: 'still' | 'series';
+}) => {
const frameRange = getAndValidateFrameRange();
const shouldOutputImageSequence = await getAndValidateShouldOutputImageSequence(
frameRange
@@ -176,10 +178,10 @@ export const getCliOptions = async () => {
const outputFile = options.isLambda
? null
: getOutputFilename({
- codec,
- imageSequence: shouldOutputImageSequence,
- type: options.type,
- });
+ codec,
+ imageSequence: shouldOutputImageSequence,
+ type: options.type,
+ });
const overwrite = Internals.getShouldOverwrite();
const crf = getAndValidateCrf(shouldOutputImageSequence, codec);
const pixelFormat = getAndValidatePixelFormat(codec);
diff --git a/packages/cli/src/index.tsx b/packages/cli/src/index.tsx
index b05a1cc2b3..97bb04fd1f 100644
--- a/packages/cli/src/index.tsx
+++ b/packages/cli/src/index.tsx
@@ -3,6 +3,7 @@ import xns from 'xns';
import {checkNodeVersion} from './check-version';
import {getCliOptions} from './get-cli-options';
import {loadConfig} from './get-config-file-name';
+import {initializeRenderCli} from './initialize-render-cli';
import {lambdaCommand} from './lambda-command';
import {loadConfigFile} from './load-config';
import {Log} from './log';
@@ -58,4 +59,5 @@ export const CliInternals = {
getCliOptions,
parseCommandLine,
loadConfig,
+ initializeRenderCli,
};
diff --git a/packages/cli/src/initialize-render-cli.ts b/packages/cli/src/initialize-render-cli.ts
index 05d0404fcc..73b1843774 100644
--- a/packages/cli/src/initialize-render-cli.ts
+++ b/packages/cli/src/initialize-render-cli.ts
@@ -2,7 +2,9 @@ import {loadConfig} from './get-config-file-name';
import {Log} from './log';
import {parseCommandLine} from './parse-command-line';
-export const initializeRenderCli = (type: 'still' | 'sequence') => {
+export const initializeRenderCli = (
+ type: 'still' | 'sequence' | 'lambda' | 'preview'
+) => {
parseCommandLine(type);
const appliedName = loadConfig();
if (appliedName) {
diff --git a/packages/cli/src/lambda-command.ts b/packages/cli/src/lambda-command.ts
index 47b333fc50..568d2e546a 100644
--- a/packages/cli/src/lambda-command.ts
+++ b/packages/cli/src/lambda-command.ts
@@ -1,6 +1,6 @@
-import {loadConfig} from './get-config-file-name';
+import {initializeRenderCli} from './initialize-render-cli';
import {Log} from './log';
-import {parseCommandLine, parsedCli} from './parse-command-line';
+import {parsedCli} from './parse-command-line';
export const lambdaCommand = async () => {
try {
@@ -8,13 +8,7 @@ export const lambdaCommand = async () => {
paths: [process.cwd()],
});
const {LambdaInternals} = require(path);
- parseCommandLine();
- const appliedName = loadConfig();
- if (appliedName) {
- Log.verbose(`Applied configuration from ${appliedName}.`);
- } else {
- Log.verbose('No config file loaded.');
- }
+ initializeRenderCli('lambda');
await LambdaInternals.executeCommand(parsedCli._.slice(1));
process.exit(0);
diff --git a/packages/cli/src/parse-command-line.ts b/packages/cli/src/parse-command-line.ts
index c24e8235e8..a27b1696dc 100644
--- a/packages/cli/src/parse-command-line.ts
+++ b/packages/cli/src/parse-command-line.ts
@@ -39,7 +39,9 @@ export const parsedCli = minimist<CommandLineOptions>(process.argv.slice(2), {
boolean: ['force', 'overwrite', 'sequence', 'help'],
});
-export const parseCommandLine = (type: 'still' | 'sequence') => {
+export const parseCommandLine = (
+ type: 'still' | 'sequence' | 'lambda' | 'preview'
+) => {
if (parsedCli['pixel-format']) {
Config.Output.setPixelFormat(parsedCli['pixel-format']);
}
diff --git a/packages/cli/src/preview.ts b/packages/cli/src/preview.ts
index 1d47130563..54c2e40de7 100644
--- a/packages/cli/src/preview.ts
+++ b/packages/cli/src/preview.ts
@@ -5,10 +5,9 @@ import betterOpn from 'better-opn';
import path from 'path';
import {Internals} from 'remotion';
import xns from 'xns';
-import {loadConfig} from './get-config-file-name';
import {getEnvironmentVariables} from './get-env';
import {getInputProps} from './get-input-props';
-import {Log} from './log';
+import {initializeRenderCli} from './initialize-render-cli';
import {parsedCli} from './parse-command-line';
const noop = () => undefined;
@@ -18,12 +17,7 @@ export const previewCommand = xns(async () => {
const {port: desiredPort} = parsedCli;
const fullPath = path.join(process.cwd(), file);
- const appliedName = loadConfig();
- if (appliedName) {
- Log.verbose(`Applied configuration from ${appliedName}.`);
- } else {
- Log.verbose('No config file loaded.');
- }
+ initializeRenderCli('preview');
const inputProps = getInputProps();
const envVariables = await getEnvironmentVariables();
diff --git a/packages/cli/src/render.tsx b/packages/cli/src/render.tsx
index e08dcc8774..15a3f9da64 100644
--- a/packages/cli/src/render.tsx
+++ b/packages/cli/src/render.tsx
@@ -49,8 +49,6 @@ export const render = async () => {
initializeRenderCli('sequence');
- parseCommandLine();
-
const {
codec,
proResProfile,
diff --git a/packages/cli/src/setup-cache.ts b/packages/cli/src/setup-cache.ts
index 31625c8019..d76b2f9f9e 100644
--- a/packages/cli/src/setup-cache.ts
+++ b/packages/cli/src/setup-cache.ts
@@ -1,7 +1,10 @@
import {bundle, BundlerInternals} from '@remotion/bundler';
import {Internals} from 'remotion';
import {Log} from './log';
-import {createProgressBar, makeBundlingProgress} from './progress-bar';
+import {
+ createOverwriteableCliOutput,
+ makeBundlingProgress,
+} from './progress-bar';
export const bundleOnCli = async (fullPath: string, steps: number) => {
const shouldCache = Internals.getWebpackCaching();
@@ -13,7 +16,7 @@ export const bundleOnCli = async (fullPath: string, steps: number) => {
}
const bundleStartTime = Date.now();
- const bundlingProgress = createProgressBar();
+ const bundlingProgress = createOverwriteableCliOutput();
const bundled = await bundle(
fullPath,
(progress) => {
diff --git a/packages/cli/src/still.ts b/packages/cli/src/still.ts
index e80f304b0d..95b7615290 100644
--- a/packages/cli/src/still.ts
+++ b/packages/cli/src/still.ts
@@ -13,7 +13,10 @@ import {handleCommonError} from './handle-common-errors';
import {initializeRenderCli} from './initialize-render-cli';
import {Log} from './log';
import {parsedCli} from './parse-command-line';
-import {createProgressBar, makeRenderingProgress} from './progress-bar';
+import {
+ createOverwriteableCliOutput,
+ makeRenderingProgress,
+} from './progress-bar';
import {bundleOnCli} from './setup-cache';
import {getUserPassedOutputLocation} from './user-passed-output-location';
@@ -40,7 +43,7 @@ export const still = async () => {
browser,
imageFormat,
stillFrame,
- } = await getCliOptions('still');
+ } = await getCliOptions({isLambda: false, type: 'still'});
if (imageFormat === 'none') {
Log.error(
@@ -91,7 +94,7 @@ export const still = async () => {
throw new Error(`Cannot find composition with ID ${compositionId}`);
}
- const renderProgress = createProgressBar();
+ const renderProgress = createOverwriteableCliOutput();
const renderStart = Date.now();
await renderStill({
diff --git a/packages/lambda/src/cli/index.ts b/packages/lambda/src/cli/index.ts
index 44ca551c96..910ed42ab9 100644
--- a/packages/lambda/src/cli/index.ts
+++ b/packages/lambda/src/cli/index.ts
@@ -72,13 +72,7 @@ export const executeCommand = async (args: string[]) => {
};
export const cli = async () => {
- const appliedName = CliInternals.loadConfig();
- if (appliedName) {
- Log.verbose(`Applied configuration from ${appliedName}.`);
- } else {
- Log.verbose('No config file loaded.');
- }
+ CliInternals.initializeRenderCli('lambda');
- CliInternals.parseCommandLine();
await executeCommand(parsedLambdaCli._);
};
diff --git a/packages/lambda/src/cli/render.ts b/packages/lambda/src/cli/render.ts
index 4e579eaa91..8f95361f23 100644
--- a/packages/lambda/src/cli/render.ts
+++ b/packages/lambda/src/cli/render.ts
@@ -76,7 +76,10 @@ export const renderCommand = async (args: string[]) => {
const {functionName} = lambdasWithMatchingVersion[0];
- const cliOptions = await CliInternals.getCliOptions({isLambda: true});
+ const cliOptions = await CliInternals.getCliOptions({
+ type: 'series',
+ isLambda: true,
+ });
const res = await renderVideoOnLambda({
functionName,
diff --git a/packages/renderer/src/render-still.ts b/packages/renderer/src/render-still.ts
index 330d6519ae..06b5e9167a 100644
--- a/packages/renderer/src/render-still.ts
+++ b/packages/renderer/src/render-still.ts
@@ -113,9 +113,10 @@ export const renderStill = async ({
};
page.on('pageerror', errorCallback);
- await setPropsAndEnv({inputProps, envVariables, page, port});
+ const serveUrl = `http://localhost:${port}`;
+ const site = `${serveUrl}/index.html?composition=${composition.id}`;
+ await setPropsAndEnv({inputProps, envVariables, page, serveUrl});
- const site = `http://localhost:${port}/index.html?composition=${composition.id}`;
await page.goto(site);
try {
await seekToFrame({frame, page});