🎥 Make videos programmatically with React
default is the compositionName.mp4
Jonny Burger92372544bb4c
diff --git a/packages/cli/src/compositions.ts b/packages/cli/src/compositions.tsindex 6a2798238f..49101202a9 100644--- a/packages/cli/src/compositions.ts+++ b/packages/cli/src/compositions.ts@@ -49,7 +49,12 @@ export const listCompositionsCommand = async () => {inputProps,puppeteerTimeout,port,- } = await getCliOptions({isLambda: false, type: 'get-compositions'});+ // TODO: Refactor compositionName out+ } = await getCliOptions({+ isLambda: false,+ type: 'get-compositions',+ compositionName: 'abc',+ });const bundled = await bundleOnCli({fullPath, steps: ['bundling']});diff --git a/packages/cli/src/get-cli-options.ts b/packages/cli/src/get-cli-options.tsindex 54b8f64605..93e11719d1 100644--- a/packages/cli/src/get-cli-options.ts+++ b/packages/cli/src/get-cli-options.ts@@ -24,14 +24,25 @@ const getAndValidateFrameRange = () => {return frameRange;};-const getFinalCodec = async (options: {isLambda: boolean}) => {+const getFinalCodec = async (options: {+ isLambda: boolean;+ compositionName: string;+}) => {const userCodec = Internals.getOutputCodecOrUndefined();const codec = Internals.getFinalOutputCodec({codec: userCodec,fileExtension: options.isLambda? null- : RenderInternals.getExtensionOfFilename(getUserPassedOutputLocation()),+ : RenderInternals.getExtensionOfFilename(+ getUserPassedOutputLocation(+ RenderInternals.getFileExtensionFromCodec(+ userCodec ?? 'h264',+ 'final'+ ),+ options.compositionName+ )+ ),emitWarning: true,});const ffmpegExecutable = Internals.getCustomFfmpegExecutable();@@ -184,13 +195,17 @@ const getAndValidateBrowser = async (browserExecutable: BrowserExecutable) => {export const getCliOptions = async (options: {isLambda: boolean;type: 'still' | 'series' | 'get-compositions';+ compositionName: string;}) => {const frameRange = getAndValidateFrameRange();const codec: Codec =options.type === 'get-compositions'? 'h264'- : await getFinalCodec({isLambda: options.isLambda});+ : await getFinalCodec({+ isLambda: options.isLambda,+ compositionName: options.compositionName,+ });const shouldOutputImageSequence =options.type === 'still'? true@@ -205,6 +220,7 @@ export const getCliOptions = async (options: {codec,imageSequence: shouldOutputImageSequence,type: options.type,+ compositionName: options.compositionName,});const overwrite = Internals.getShouldOverwrite();diff --git a/packages/cli/src/get-filename.ts b/packages/cli/src/get-filename.tsindex 0ab4ef7bdd..8a56a8f874 100644--- a/packages/cli/src/get-filename.ts+++ b/packages/cli/src/get-filename.ts@@ -7,12 +7,17 @@ export const getOutputFilename = ({codec,imageSequence,type,+ compositionName,}: {codec: Codec;imageSequence: boolean;type: 'still' | 'series';+ compositionName: string;}): string => {- let filename = getUserPassedOutputLocation();+ let filename = getUserPassedOutputLocation(+ RenderInternals.getFileExtensionFromCodec(codec, 'final'),+ compositionName+ );if (type === 'still') {return filename;}diff --git a/packages/cli/src/render.tsx b/packages/cli/src/render.tsxindex 56a6a42a1f..5f22fdf6d3 100644--- a/packages/cli/src/render.tsx+++ b/packages/cli/src/render.tsx@@ -67,7 +67,11 @@ export const render = async () => {numberOfGifLoops,everyNthFrame,puppeteerTimeout,- } = await getCliOptions({isLambda: false, type: 'series'});+ } = await getCliOptions({+ isLambda: false,+ type: 'series',+ compositionName: getCompositionId([]),+ });if (!absoluteOutputFile) {throw new Error(diff --git a/packages/cli/src/still.ts b/packages/cli/src/still.tsindex 9d60f65c3d..43e489b6a1 100644--- a/packages/cli/src/still.ts+++ b/packages/cli/src/still.ts@@ -32,22 +32,6 @@ export const still = async () => {await initializeRenderCli('still');- const userOutput = path.resolve(process.cwd(), getUserPassedOutputLocation());-- if (userOutput.endsWith('.jpeg') || userOutput.endsWith('.jpg')) {- Log.verbose(- 'Output file has a JPEG extension, therefore setting the image format to JPEG.'- );- Config.Rendering.setImageFormat('jpeg');- }-- if (userOutput.endsWith('.png')) {- Log.verbose(- 'Output file has a PNG extension, therefore setting the image format to PNG.'- );- Config.Rendering.setImageFormat('png');- }-const {inputProps,envVariables,@@ -63,7 +47,30 @@ export const still = async () => {overwrite,puppeteerTimeout,port,- } = await getCliOptions({isLambda: false, type: 'still'});+ } = await getCliOptions({+ isLambda: false,+ type: 'still',+ compositionName: getCompositionId([]),+ });++ const userOutput = path.resolve(+ process.cwd(),+ getUserPassedOutputLocation(imageFormat, getCompositionId([]))+ );++ if (userOutput.endsWith('.jpeg') || userOutput.endsWith('.jpg')) {+ Log.verbose(+ 'Output file has a JPEG extension, therefore setting the image format to JPEG.'+ );+ Config.Rendering.setImageFormat('jpeg');+ }++ if (userOutput.endsWith('.png')) {+ Log.verbose(+ 'Output file has a PNG extension, therefore setting the image format to PNG.'+ );+ Config.Rendering.setImageFormat('png');+ }Log.verbose('Browser executable: ', browserExecutable);diff --git a/packages/cli/src/user-passed-output-location.ts b/packages/cli/src/user-passed-output-location.tsindex 58ac667878..b997176fe5 100644--- a/packages/cli/src/user-passed-output-location.ts+++ b/packages/cli/src/user-passed-output-location.ts@@ -1,9 +1,15 @@import {Internals} from 'remotion';import {parsedCli} from './parse-command-line';-export const getUserPassedOutputLocation = () => {+export const getUserPassedOutputLocation = (+ defaultExtension: string,+ compositionName: string+) => {const filename = parsedCli._[3]? parsedCli._[3]: Internals.getOutputLocation();- return filename;++ const defaultName = `${compositionName}.${defaultExtension}`;++ return filename ?? defaultName;};diff --git a/packages/core/src/config/output-location.ts b/packages/core/src/config/output-location.tsindex 8d413906a1..7716dd581a 100644--- a/packages/core/src/config/output-location.ts+++ b/packages/core/src/config/output-location.ts@@ -1,6 +1,4 @@-export const DEFAULT_OUTPUT_LOCATION = 'out/video.mp4';--let currentOutputLocation: string = DEFAULT_OUTPUT_LOCATION;+let currentOutputLocation: string | null = null;export const setOutputLocation = (newOutputLocation: string) => {if (typeof newOutputLocation !== 'string') {@@ -11,7 +9,7 @@ export const setOutputLocation = (newOutputLocation: string) => {);}- if (newOutputLocation === '') {+ if (newOutputLocation.trim() === '') {throw new Error(`outputLocation must not be an empty string`);}diff --git a/packages/example/remotion.config.ts b/packages/example/remotion.config.tsindex 5b3e5a272b..4b94295e33 100644--- a/packages/example/remotion.config.ts+++ b/packages/example/remotion.config.ts@@ -1,6 +1,5 @@import {Config} from 'remotion';import {webpackOverride} from './src/webpack-override';-Config.Output.setOutputLocation('out/video.mp4');Config.Output.setOverwriteOutput(true);Config.Bundling.overrideWebpackConfig(webpackOverride);diff --git a/packages/lambda/src/cli/commands/render/render.ts b/packages/lambda/src/cli/commands/render/render.tsindex a7396c3738..73a0c6675b 100644--- a/packages/lambda/src/cli/commands/render/render.ts+++ b/packages/lambda/src/cli/commands/render/render.ts@@ -70,6 +70,7 @@ export const renderCommand = async (args: string[]) => {} = await CliInternals.getCliOptions({type: 'series',isLambda: true,+ compositionName: composition,});const functionName = await findFunctionName();diff --git a/packages/lambda/src/cli/commands/still.ts b/packages/lambda/src/cli/commands/still.tsindex 84405ac5c7..6b87a30c03 100644--- a/packages/lambda/src/cli/commands/still.ts+++ b/packages/lambda/src/cli/commands/still.ts@@ -61,6 +61,7 @@ export const stillCommand = async (args: string[]) => {} = await CliInternals.getCliOptions({type: 'still',isLambda: true,+ compositionName: composition,});const functionName = await findFunctionName();