Skip to content

🎥 Make videos programmatically with React

convert entry point to serve url

Jonny Burger96732a8ff6a9
diff --git a/packages/cli/src/benchmark.ts b/packages/cli/src/benchmark.ts
index 49bb7bff1d..88bea67ec3 100644
--- a/packages/cli/src/benchmark.ts
+++ b/packages/cli/src/benchmark.ts
@@ -5,9 +5,9 @@ import {
RenderInternals,
renderMedia,
} from '@remotion/renderer';
-import path from 'path';
import {chalk} from './chalk';
import {ConfigInternals} from './config';
+import {convertEntryPointToServeUrl} from './convert-entry-point-to-serve-url';
import {findEntryPoint} from './entry-point';
import {getCliOptions, getFinalCodec} from './get-cli-options';
import {getRenderMediaOptions} from './get-render-media-options';
@@ -150,7 +150,7 @@ export const benchmarkCommand = async (
process.exit(1);
}
- const fullPath = path.join(process.cwd(), file);
+ const fullPath = convertEntryPointToServeUrl(file);
const {
inputProps,
diff --git a/packages/cli/src/compositions.ts b/packages/cli/src/compositions.ts
index 7fdcf9b958..6dfb2a89e9 100644
--- a/packages/cli/src/compositions.ts
+++ b/packages/cli/src/compositions.ts
@@ -1,5 +1,5 @@
import {getCompositions, RenderInternals} from '@remotion/renderer';
-import path from 'path';
+import {convertEntryPointToServeUrl} from './convert-entry-point-to-serve-url';
import {findEntryPoint} from './entry-point';
import {getCliOptions} from './get-cli-options';
import {loadConfig} from './get-config-file-name';
@@ -28,7 +28,7 @@ export const listCompositionsCommand = async (
const downloadMap = RenderInternals.makeDownloadMap();
- const fullPath = path.join(process.cwd(), file);
+ const fullPath = convertEntryPointToServeUrl(file);
await loadConfig(remotionRoot);
diff --git a/packages/cli/src/convert-entry-point-to-serve-url.ts b/packages/cli/src/convert-entry-point-to-serve-url.ts
new file mode 100644
index 0000000000..191afde97b
--- /dev/null
+++ b/packages/cli/src/convert-entry-point-to-serve-url.ts
@@ -0,0 +1,10 @@
+import {RenderInternals} from '@remotion/renderer';
+import path from 'path';
+
+export const convertEntryPointToServeUrl = (entryPoint: string) => {
+ const fullPath = RenderInternals.isServeUrl(entryPoint)
+ ? entryPoint
+ : path.join(process.cwd(), entryPoint);
+
+ return fullPath;
+};
diff --git a/packages/cli/src/preview-server/render-queue/process-still.ts b/packages/cli/src/preview-server/render-queue/process-still.ts
index d6f0bd8e46..fa6831538b 100644
--- a/packages/cli/src/preview-server/render-queue/process-still.ts
+++ b/packages/cli/src/preview-server/render-queue/process-still.ts
@@ -1,12 +1,6 @@
-import {
- getCompositions,
- openBrowser,
- RenderInternals,
- renderStill,
-} from '@remotion/renderer';
-import {ConfigInternals} from '../../config';
+import {convertEntryPointToServeUrl} from '../../convert-entry-point-to-serve-url';
import {getCliOptions} from '../../get-cli-options';
-import {bundleOnCli} from '../../setup-cache';
+import {renderStillFlow} from '../../render-flows/still';
import type {RenderJob} from './job';
export const processStill = async ({
@@ -31,74 +25,41 @@ export const processStill = async ({
envVariables,
inputProps,
port,
- scale,
browser,
puppeteerTimeout,
} = await getCliOptions({
isLambda: false,
- type: 'get-compositions',
+ type: 'still',
remotionRoot,
});
- const browserInstance = openBrowser(browser, {
- browserExecutable,
- chromiumOptions,
- shouldDumpIo: RenderInternals.isEqualOrBelowLogLevel(
- ConfigInternals.Logging.getLogLevel(),
- 'verbose'
- ),
- forceDeviceScaleFactor: scale,
- });
+ const fullEntryPoint = convertEntryPointToServeUrl(entryPoint);
- const serveUrl = await bundleOnCli({
- fullPath: entryPoint,
- publicDir,
+ await renderStillFlow({
remotionRoot,
- steps: ['bundling'],
- });
-
- const compositions = await getCompositions(serveUrl, {
+ browser,
browserExecutable,
chromiumOptions,
+ entryPointReason: 'from preview',
+ entryPoint,
envVariables,
ffmpegExecutable,
ffprobeExecutable,
+ height: null,
+ fullEntryPoint,
inputProps,
+ overwrite: true,
port,
- puppeteerInstance: await browserInstance,
- timeoutInMilliseconds: puppeteerTimeout,
- });
-
- const composition = compositions.find((c) => {
- return c.id === job.compositionId;
- });
-
- if (!composition) {
- throw new TypeError(`Composition ${job.compositionId} not found`);
- }
-
- await renderStill({
- composition,
- output: job.outputLocation,
- serveUrl,
- browserExecutable,
- chromiumOptions,
- envVariables,
- ffmpegExecutable,
- ffprobeExecutable,
- scale: job.scale,
- timeoutInMilliseconds: puppeteerTimeout,
- // TODO: Write download progress to CLI
- overwrite: false,
- // TODO: Allow user to overwrite file
- port,
- inputProps,
- puppeteerInstance: await browserInstance,
+ publicDir,
+ puppeteerTimeout,
quality: job.quality ?? undefined,
- imageFormat: job.imageFormat,
- frame: job.frame,
-
- // TODO: Allow cancel signal
- // TODO: Accept CLI options
+ remainingArgs: [],
+ scale: job.scale,
+ stillFrame: job.frame,
+ width: null,
});
+ // TODO: Allow user to overwrite file
+ // TODO: Write download progress to CLI
+ // TODO: Allow cancel signal
+ // TODO: Accept CLI options
};
diff --git a/packages/cli/src/preview.ts b/packages/cli/src/preview.ts
index e0ca7cb125..4ce1005f87 100644
--- a/packages/cli/src/preview.ts
+++ b/packages/cli/src/preview.ts
@@ -2,6 +2,7 @@ import betterOpn from 'better-opn';
import path from 'path';
import {chalk} from './chalk';
import {ConfigInternals} from './config';
+import {convertEntryPointToServeUrl} from './convert-entry-point-to-serve-url';
import {findEntryPoint} from './entry-point';
import {getEnvironmentVariables} from './get-env';
import {getInputProps} from './get-input-props';
@@ -33,7 +34,8 @@ export const previewCommand = async (remotionRoot: string, args: string[]) => {
}
const {port: desiredPort} = parsedCli;
- const fullPath = path.join(process.cwd(), file);
+
+ const fullPath = convertEntryPointToServeUrl(file);
let inputProps = getInputProps((newProps) => {
waitForLiveEventsListener().then((listener) => {
diff --git a/packages/cli/src/render-flows/still.ts b/packages/cli/src/render-flows/still.ts
index 5155c880b6..275dc78325 100644
--- a/packages/cli/src/render-flows/still.ts
+++ b/packages/cli/src/render-flows/still.ts
@@ -1,6 +1,12 @@
// Prints to CLI and also reports back to browser
-import type {RenderMediaOnDownload} from '@remotion/renderer';
+import type {
+ Browser,
+ BrowserExecutable,
+ ChromiumOptions,
+ FfmpegExecutable,
+ RenderMediaOnDownload,
+} from '@remotion/renderer';
import {
getCompositions,
openBrowser,
@@ -12,10 +18,7 @@ import path from 'path';
import {chalk} from '../chalk';
import {ConfigInternals} from '../config';
import {determineFinalImageFormat} from '../determine-image-format';
-import {
- getAndValidateAbsoluteOutputFile,
- getCliOptions,
-} from '../get-cli-options';
+import {getAndValidateAbsoluteOutputFile} from '../get-cli-options';
import {getCompositionWithDimensionOverride} from '../get-composition-with-dimension-override';
import {Log} from '../log';
import {parsedCli, quietFlagProvided} from '../parse-command-line';
@@ -34,42 +37,50 @@ import {
export const renderStillFlow = async ({
remotionRoot,
- fullPath,
+ fullEntryPoint,
entryPointReason,
- file,
remainingArgs,
+ browser,
+ browserExecutable,
+ chromiumOptions,
+ envVariables,
+ ffmpegExecutable,
+ ffprobeExecutable,
+ height,
+ inputProps,
+ overwrite,
+ port,
+ publicDir,
+ puppeteerTimeout,
+ quality,
+ scale,
+ stillFrame,
+ width,
}: {
remotionRoot: string;
- fullPath: string;
- file: string | null;
+ fullEntryPoint: string;
+ entryPoint: string | null;
entryPointReason: string;
remainingArgs: string[];
+ inputProps: object;
+ envVariables: Record<string, string>;
+ quality: number | undefined;
+ browser: Browser;
+ stillFrame: number;
+ browserExecutable: BrowserExecutable;
+ chromiumOptions: ChromiumOptions;
+ scale: number;
+ ffmpegExecutable: FfmpegExecutable;
+ ffprobeExecutable: FfmpegExecutable;
+ overwrite: boolean;
+ puppeteerTimeout: number;
+ port: number | null;
+ publicDir: string | null;
+ height: number | null;
+ width: number | null;
}) => {
const startTime = Date.now();
- const {
- inputProps,
- envVariables,
- quality,
- browser,
- stillFrame,
- browserExecutable,
- chromiumOptions,
- scale,
- ffmpegExecutable,
- ffprobeExecutable,
- overwrite,
- puppeteerTimeout,
- port,
- publicDir,
- height,
- width,
- } = await getCliOptions({
- isLambda: false,
- type: 'still',
- remotionRoot,
- });
-
Log.verbose('Browser executable: ', browserExecutable);
const browserInstance = openBrowser(browser, {
@@ -83,12 +94,12 @@ export const renderStillFlow = async ({
});
const steps: RenderStep[] = [
- RenderInternals.isServeUrl(fullPath) ? null : ('bundling' as const),
+ RenderInternals.isServeUrl(fullEntryPoint) ? null : ('bundling' as const),
'rendering' as const,
].filter(truthy);
const {cleanup: cleanupBundle, urlOrBundle} = await bundleOnCliOrTakeServeUrl(
- {fullPath, remotionRoot, steps, publicDir}
+ {fullPath: fullEntryPoint, remotionRoot, steps, publicDir}
);
const puppeteerInstance = await browserInstance;
@@ -141,7 +152,7 @@ export const renderStillFlow = async ({
Log.info(
chalk.gray(
- `Entry point = ${file} (${entryPointReason}), Output = ${relativeOutputLocation}, Format = ${imageFormat} (${source}), Composition = ${compositionId} (${reason})`
+ `Entry point = ${fullEntryPoint} (${entryPointReason}), Output = ${relativeOutputLocation}, Format = ${imageFormat} (${source}), Composition = ${compositionId} (${reason})`
)
);
diff --git a/packages/cli/src/render.tsx b/packages/cli/src/render.tsx
index 6e0a2522db..0752812fd0 100644
--- a/packages/cli/src/render.tsx
+++ b/packages/cli/src/render.tsx
@@ -13,6 +13,7 @@ import path from 'path';
import {Internals} from 'remotion';
import {chalk} from './chalk';
import {ConfigInternals} from './config';
+import {convertEntryPointToServeUrl} from './convert-entry-point-to-serve-url';
import {findEntryPoint} from './entry-point';
import {
getAndValidateAbsoluteOutputFile,
@@ -52,9 +53,7 @@ export const render = async (remotionRoot: string, args: string[]) => {
process.exit(1);
}
- const fullPath = RenderInternals.isServeUrl(file)
- ? file
- : path.join(process.cwd(), file);
+ const fullPath = convertEntryPointToServeUrl(file);
const downloadMap = RenderInternals.makeDownloadMap();
diff --git a/packages/cli/src/still.ts b/packages/cli/src/still.ts
index df4ebe597d..4b809336f9 100644
--- a/packages/cli/src/still.ts
+++ b/packages/cli/src/still.ts
@@ -1,6 +1,6 @@
-import {RenderInternals} from '@remotion/renderer';
-import path from 'path';
+import {convertEntryPointToServeUrl} from './convert-entry-point-to-serve-url';
import {findEntryPoint} from './entry-point';
+import {getCliOptions} from './get-cli-options';
import {Log} from './log';
import {parsedCli} from './parse-command-line';
import {renderStillFlow} from './render-flows/still';
@@ -21,9 +21,7 @@ export const still = async (remotionRoot: string, args: string[]) => {
process.exit(1);
}
- const fullPath = RenderInternals.isServeUrl(file)
- ? file
- : path.join(process.cwd(), file);
+ const fullPath = convertEntryPointToServeUrl(file);
if (parsedCli.frames) {
Log.error(
@@ -32,11 +30,50 @@ export const still = async (remotionRoot: string, args: string[]) => {
process.exit(1);
}
+ const {
+ browser,
+ browserExecutable,
+ chromiumOptions,
+ envVariables,
+ ffmpegExecutable,
+ ffprobeExecutable,
+ height,
+ inputProps,
+ overwrite,
+ port,
+ publicDir,
+ puppeteerTimeout,
+ quality,
+ scale,
+ stillFrame,
+ width,
+ } = await getCliOptions({
+ isLambda: false,
+ type: 'still',
+ remotionRoot,
+ });
+
await renderStillFlow({
remotionRoot,
entryPointReason,
- fullPath,
- file,
+ fullEntryPoint: fullPath,
+ entryPoint: file,
remainingArgs,
+ browser,
+ browserExecutable,
+ chromiumOptions,
+ envVariables,
+ ffmpegExecutable,
+ ffprobeExecutable,
+ height,
+ inputProps,
+ overwrite,
+ port,
+ publicDir,
+ puppeteerTimeout,
+ quality,
+ scale,
+ stillFrame,
+ width,
});
};