Skip to content

🎥 Make videos programmatically with React

shuffle things around

Jonny Burger85735ddd58d8
diff --git a/packages/cli/src/preview-server/render-queue/process-still.ts b/packages/cli/src/preview-server/render-queue/process-still.ts
new file mode 100644
index 0000000000..d6f0bd8e46
--- /dev/null
+++ b/packages/cli/src/preview-server/render-queue/process-still.ts
@@ -0,0 +1,104 @@
+import {
+ getCompositions,
+ openBrowser,
+ RenderInternals,
+ renderStill,
+} from '@remotion/renderer';
+import {ConfigInternals} from '../../config';
+import {getCliOptions} from '../../get-cli-options';
+import {bundleOnCli} from '../../setup-cache';
+import type {RenderJob} from './job';
+
+export const processStill = async ({
+ job,
+ remotionRoot,
+ entryPoint,
+}: {
+ job: RenderJob;
+ remotionRoot: string;
+ entryPoint: string;
+}) => {
+ if (job.type !== 'still') {
+ throw new Error('Expected still job');
+ }
+
+ const {
+ publicDir,
+ browserExecutable,
+ ffmpegExecutable,
+ ffprobeExecutable,
+ chromiumOptions,
+ envVariables,
+ inputProps,
+ port,
+ scale,
+ browser,
+ puppeteerTimeout,
+ } = await getCliOptions({
+ isLambda: false,
+ type: 'get-compositions',
+ remotionRoot,
+ });
+
+ const browserInstance = openBrowser(browser, {
+ browserExecutable,
+ chromiumOptions,
+ shouldDumpIo: RenderInternals.isEqualOrBelowLogLevel(
+ ConfigInternals.Logging.getLogLevel(),
+ 'verbose'
+ ),
+ forceDeviceScaleFactor: scale,
+ });
+
+ const serveUrl = await bundleOnCli({
+ fullPath: entryPoint,
+ publicDir,
+ remotionRoot,
+ steps: ['bundling'],
+ });
+
+ const compositions = await getCompositions(serveUrl, {
+ browserExecutable,
+ chromiumOptions,
+ envVariables,
+ ffmpegExecutable,
+ ffprobeExecutable,
+ inputProps,
+ 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,
+ quality: job.quality ?? undefined,
+ imageFormat: job.imageFormat,
+ frame: job.frame,
+
+ // TODO: Allow cancel signal
+ // TODO: Accept CLI options
+ });
+};
diff --git a/packages/cli/src/preview-server/render-queue/queue.ts b/packages/cli/src/preview-server/render-queue/queue.ts
index f10c0fe5da..ecf5b141c6 100644
--- a/packages/cli/src/preview-server/render-queue/queue.ts
+++ b/packages/cli/src/preview-server/render-queue/queue.ts
@@ -1,16 +1,8 @@
-import {
- getCompositions,
- openBrowser,
- RenderInternals,
- renderStill,
-} from '@remotion/renderer';
-import {ConfigInternals} from '../../config';
import {installFileWatcher} from '../../file-watcher';
-import {getCliOptions} from '../../get-cli-options';
import {Log} from '../../log';
-import {bundleOnCli} from '../../setup-cache';
import {waitForLiveEventsListener} from '../live-events';
import type {RenderJob, RenderJobWithCleanup} from './job';
+import {processStill} from './process-still';
let jobQueue: RenderJobWithCleanup[] = [];
@@ -54,85 +46,7 @@ export const processJob = async ({
entryPoint: string;
}) => {
if (job.type === 'still') {
- const {
- publicDir,
- browserExecutable,
- ffmpegExecutable,
- ffprobeExecutable,
- chromiumOptions,
- envVariables,
- inputProps,
- port,
- scale,
- browser,
- puppeteerTimeout,
- } = await getCliOptions({
- isLambda: false,
- type: 'get-compositions',
- remotionRoot,
- });
-
- const browserInstance = openBrowser(browser, {
- browserExecutable,
- chromiumOptions,
- shouldDumpIo: RenderInternals.isEqualOrBelowLogLevel(
- ConfigInternals.Logging.getLogLevel(),
- 'verbose'
- ),
- forceDeviceScaleFactor: scale,
- });
-
- const serveUrl = await bundleOnCli({
- fullPath: entryPoint,
- publicDir,
- remotionRoot,
- steps: ['bundling'],
- });
-
- const compositions = await getCompositions(serveUrl, {
- browserExecutable,
- chromiumOptions,
- envVariables,
- ffmpegExecutable,
- ffprobeExecutable,
- inputProps,
- 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,
- quality: job.quality ?? undefined,
- imageFormat: job.imageFormat,
- frame: job.frame,
-
- // TODO: Allow cancel signal
- // TODO: Accept CLI options
- });
+ await processStill({job, remotionRoot, entryPoint});
}
};