Skip to content

🎥 Make videos programmatically with React

refactor some stuff

Jonny Burgercb2229482056
diff --git a/packages/cli/src/benchmark.ts b/packages/cli/src/benchmark.ts
index c2962741c4..ef91ea8138 100644
--- a/packages/cli/src/benchmark.ts
+++ b/packages/cli/src/benchmark.ts
@@ -11,7 +11,7 @@ import {convertEntryPointToServeUrl} from './convert-entry-point-to-serve-url';
import {findEntryPoint} from './entry-point';
import {getCliOptions} from './get-cli-options';
import {getFinalOutputCodec} from './get-final-output-codec';
-import {getRenderMediaOptions} from './get-render-media-options';
+import {getImageFormat} from './image-formats';
import {Log} from './log';
import {makeProgressBar} from './make-progress-bar';
import {parsedCli, quietFlagProvided} from './parse-command-line';
@@ -22,16 +22,11 @@ import {truthy} from './truthy';
const DEFAULT_RUNS = 3;
-const getValidConcurrency = (renderMediaOptions: RenderMediaOptions) => {
- const concurrency =
- 'concurrency' in renderMediaOptions
- ? renderMediaOptions.concurrency ?? null
- : null;
-
+const getValidConcurrency = (cliConcurrency: number | string | null) => {
const {concurrencies} = parsedCli;
if (!concurrencies) {
- return [RenderInternals.getActualConcurrency(concurrency)];
+ return [RenderInternals.getActualConcurrency(cliConcurrency)];
}
return (concurrencies as string)
@@ -245,21 +240,32 @@ export const benchmarkCommand = async (
});
for (const composition of compositions) {
- const renderMediaOptions = await getRenderMediaOptions({
- config: composition,
- outputLocation: undefined,
- serveUrl: bundleLocation,
- codec,
+ const {
+ proResProfile,
+ frameRange: defaultFrameRange,
+ overwrite,
+ quality,
+ crf: configFileCrf,
+ pixelFormat,
+ scale: configFileScale,
+ numberOfGifLoops,
+ everyNthFrame,
+ muted,
+ enforceAudioTrack,
+ ffmpegOverride,
+ audioBitrate,
+ videoBitrate,
+ height,
+ width,
+ configFileImageFormat,
+ concurrency: unparsedConcurrency,
+ } = await getCliOptions({
+ isLambda: false,
+ type: 'series',
remotionRoot,
- uiCrf: null,
- uiImageFormat: null,
- uiFrameRange: null,
- uiMuted: null,
- uiQuality: null,
- uiScale: null,
- uiConcurrency: null,
});
- const concurrency = getValidConcurrency(renderMediaOptions);
+
+ const concurrency = getValidConcurrency(unparsedConcurrency);
benchmark[composition.id] = {};
for (const con of concurrency) {
@@ -277,7 +283,49 @@ export const benchmarkCommand = async (
const timeTaken = await runBenchmark(
runs,
{
- ...renderMediaOptions,
+ outputLocation: undefined,
+ composition: {
+ ...composition,
+ width: width ?? composition.width,
+ height: height ?? composition.height,
+ },
+ crf: configFileCrf,
+ envVariables,
+ ffmpegExecutable,
+ ffprobeExecutable,
+ frameRange: defaultFrameRange,
+ imageFormat: getImageFormat({
+ codec,
+ configFileImageFormat,
+ uiImageFormat: null,
+ }),
+ inputProps,
+ overwrite,
+ pixelFormat,
+ proResProfile,
+ quality,
+ dumpBrowserLogs: RenderInternals.isEqualOrBelowLogLevel(
+ ConfigInternals.Logging.getLogLevel(),
+ 'verbose'
+ ),
+ chromiumOptions,
+ timeoutInMilliseconds: ConfigInternals.getCurrentPuppeteerTimeout(),
+ scale: configFileScale,
+ port,
+ numberOfGifLoops,
+ everyNthFrame,
+ verbose: RenderInternals.isEqualOrBelowLogLevel(
+ ConfigInternals.Logging.getLogLevel(),
+ 'verbose'
+ ),
+ muted,
+ enforceAudioTrack,
+ browserExecutable,
+ ffmpegOverride,
+ serveUrl: bundleLocation,
+ codec,
+ audioBitrate,
+ videoBitrate,
puppeteerInstance,
concurrency: con,
},
diff --git a/packages/cli/src/get-render-media-options.ts b/packages/cli/src/get-render-media-options.ts
deleted file mode 100644
index 347dc91c04..0000000000
--- a/packages/cli/src/get-render-media-options.ts
+++ /dev/null
@@ -1,119 +0,0 @@
-import type {Codec, FrameRange, RenderMediaOptions} from '@remotion/renderer';
-import {RenderInternals} from '@remotion/renderer';
-import {ConfigInternals} from './config';
-import {getCliOptions} from './get-cli-options';
-import {getImageFormat} from './image-formats';
-
-export const getRenderMediaOptions = async ({
- outputLocation,
- config,
- serveUrl,
- codec,
- remotionRoot,
- uiImageFormat,
- uiCrf,
- uiFrameRange,
- uiScale,
- uiMuted,
- uiQuality,
- uiConcurrency,
-}: {
- outputLocation: RenderMediaOptions['outputLocation'];
- config: RenderMediaOptions['composition'];
- serveUrl: string;
- codec: Codec;
- remotionRoot: string;
- uiImageFormat: 'png' | 'jpeg' | 'none' | null;
- uiCrf: number | null;
- uiFrameRange: FrameRange | null;
- uiScale: number | null;
- uiMuted: boolean | null;
- uiQuality: number | null;
- uiConcurrency: number | string | null;
-}): Promise<RenderMediaOptions> => {
- // TODO: Lots of these options can have difference defaults
- // TODO: Scale option for example is not being applied
- const {
- proResProfile,
- concurrency,
- frameRange: defaultFrameRange,
- overwrite,
- inputProps,
- envVariables,
- quality,
- crf: configFileCrf,
- pixelFormat,
- browserExecutable,
- ffmpegExecutable,
- ffprobeExecutable,
- scale: configFileScale,
- chromiumOptions,
- port,
- numberOfGifLoops,
- everyNthFrame,
- muted,
- enforceAudioTrack,
- ffmpegOverride,
- audioBitrate,
- videoBitrate,
- height,
- width,
- configFileImageFormat,
- } = await getCliOptions({
- isLambda: false,
- type: 'series',
- remotionRoot,
- });
-
- return {
- outputLocation,
- composition: {
- ...config,
- width: width ?? config.width,
- height: height ?? config.height,
- },
- crf: uiCrf ?? configFileCrf,
- envVariables,
- ffmpegExecutable,
- ffprobeExecutable,
- frameRange: uiFrameRange ?? defaultFrameRange,
- imageFormat: getImageFormat({
- codec,
- configFileImageFormat,
- uiImageFormat,
- }),
- // TODO: Take from UI
- inputProps,
- overwrite,
- // TODO: Take from UI
- pixelFormat,
- // TODO: Take from UI
- proResProfile,
- quality: uiQuality ?? quality,
- dumpBrowserLogs: RenderInternals.isEqualOrBelowLogLevel(
- ConfigInternals.Logging.getLogLevel(),
- 'verbose'
- ),
- chromiumOptions,
- timeoutInMilliseconds: ConfigInternals.getCurrentPuppeteerTimeout(),
- scale: uiScale ?? configFileScale,
- port,
- numberOfGifLoops,
- everyNthFrame,
- verbose: RenderInternals.isEqualOrBelowLogLevel(
- ConfigInternals.Logging.getLogLevel(),
- 'verbose'
- ),
- muted: uiMuted ?? muted,
- // TODO: Take from UI
- enforceAudioTrack,
- browserExecutable,
- ffmpegOverride,
- concurrency: uiConcurrency ?? concurrency,
- serveUrl,
- // TODO: Take from UI
- codec,
- audioBitrate,
- videoBitrate,
- };
-};
diff --git a/packages/cli/src/render-flows/render.ts b/packages/cli/src/render-flows/render.ts
index 5940b93dd1..6d8ca53718 100644
--- a/packages/cli/src/render-flows/render.ts
+++ b/packages/cli/src/render-flows/render.ts
@@ -25,12 +25,12 @@ import {chalk} from '../chalk';
import {ConfigInternals} from '../config';
import {
getAndValidateAbsoluteOutputFile,
+ getCliOptions,
validateFfmpegCanUseCodec,
} from '../get-cli-options';
import {getCompositionWithDimensionOverride} from '../get-composition-with-dimension-override';
import {getOutputFilename} from '../get-filename';
import {getFinalOutputCodec} from '../get-final-output-codec';
-import {getRenderMediaOptions} from '../get-render-media-options';
import {getImageFormat} from '../image-formats';
import {INDENT_TOKEN, Log} from '../log';
import {parsedCli} from '../parse-command-line';
@@ -139,6 +139,23 @@ export const renderCompFlow = async ({
browserExecutable
);
+ // TODO: Don't parse CLI here
+ const {
+ proResProfile,
+ crf: configFileCrf,
+ pixelFormat,
+ numberOfGifLoops,
+ muted,
+ enforceAudioTrack,
+ ffmpegOverride,
+ audioBitrate,
+ videoBitrate,
+ } = await getCliOptions({
+ isLambda: false,
+ type: 'series',
+ remotionRoot,
+ });
+
Log.verboseAdvanced({indent, logLevel}, 'Asset dirs', downloadMap.assetDir);
const browserInstance = openBrowser(browser, {
@@ -276,24 +293,7 @@ export const renderCompFlow = async ({
let renderedDoneIn: number | null = null;
let stitchStage: StitchingState = 'encoding';
- const options = await getRenderMediaOptions({
- config,
- outputLocation: absoluteOutputFile,
- serveUrl: urlOrBundle,
- codec,
- remotionRoot,
- uiImageFormat,
- uiCrf,
- uiFrameRange: frameRange,
- uiMuted,
- uiQuality: quality ?? null,
- uiScale: scale,
- uiConcurrency: concurrency,
- });
-
- const actualConcurrency = RenderInternals.getActualConcurrency(
- 'concurrency' in options ? concurrency : null
- );
+ const actualConcurrency = RenderInternals.getActualConcurrency(concurrency);
const updateRenderProgress = () => {
if (totalFrames.length === 0) {
@@ -404,7 +404,48 @@ export const renderCompFlow = async ({
}
await renderMedia({
- ...options,
+ outputLocation: absoluteOutputFile,
+ composition: {
+ ...config,
+ width: width ?? config.width,
+ height: height ?? config.height,
+ },
+ crf: uiCrf ?? configFileCrf,
+ envVariables,
+ ffmpegExecutable,
+ ffprobeExecutable,
+ frameRange,
+ inputProps,
+ overwrite,
+ pixelFormat,
+ proResProfile,
+ quality,
+ // TODO: Take from UI
+ dumpBrowserLogs: RenderInternals.isEqualOrBelowLogLevel(
+ ConfigInternals.Logging.getLogLevel(),
+ 'verbose'
+ ),
+ chromiumOptions,
+ timeoutInMilliseconds: ConfigInternals.getCurrentPuppeteerTimeout(),
+ scale,
+ port,
+ numberOfGifLoops,
+ everyNthFrame,
+ verbose: RenderInternals.isEqualOrBelowLogLevel(
+ ConfigInternals.Logging.getLogLevel(),
+ 'verbose'
+ ),
+ muted: uiMuted ?? muted,
+ // TODO: Take from UI
+ enforceAudioTrack,
+ browserExecutable,
+ ffmpegOverride,
+ concurrency,
+ serveUrl: urlOrBundle,
+ // TODO: Take from UI
+ codec,
+ audioBitrate,
+ videoBitrate,
onProgress: (update) => {
encodedDoneIn = update.encodedDoneIn;
encodedFrames = update.encodedFrames;