Skip to content

🎥 Make videos programmatically with React

added file extension support

Shankhadeep Dey71964badb7c3
diff --git a/packages/cli/src/get-filename.ts b/packages/cli/src/get-filename.ts
index ab2526000b..0b8eba0f8c 100644
--- a/packages/cli/src/get-filename.ts
+++ b/packages/cli/src/get-filename.ts
@@ -1,10 +1,64 @@
import minimist from 'minimist';
+import {Config, OutputFormat} from 'remotion';
-export const getOutputFilename = () => {
+export const getOutputFilename = (renderMode: OutputFormat): string => {
const args = minimist(process.argv.slice(2));
if (!args._[3]) {
console.log('Pass an extra argument <output-filename>.');
process.exit(1);
}
- return args._[3].split('.')[0];
+ let filename = args._[3];
+ const filenameArr = filename.split('.');
+ const filenameArrLength = filenameArr.length;
+ if (filenameArrLength === 1 && renderMode !== 'png') {
+ console.info(
+ 'User has given a file without extension , adding the extension automatically.'
+ );
+ if (renderMode === 'mp4') {
+ filename += '.mp4';
+ }
+ if (renderMode === 'webm-v8' || renderMode === 'webm-v9') {
+ filename += '.webm';
+ }
+ }
+ if (filenameArrLength >= 2 && filenameArr[filenameArrLength - 1] === 'webm') {
+ if (renderMode === 'mp4') {
+ console.info(
+ 'User has given WebM extension, encoding it using the default VP8 codec. To use VP9 codec use --format=webm-v9 flag.'
+ );
+ Config.Output.setOutputFormat('webm-v8');
+ renderMode = 'webm-v8';
+ }
+ }
+ if (renderMode === 'mp4') {
+ if (
+ filenameArrLength >= 2 &&
+ filenameArr[filenameArrLength - 1] !== 'mp4'
+ ) {
+ console.error(
+ 'User has selected MP4 format , the output extension must be .mp4'
+ );
+ process.exit(1);
+ }
+ }
+ if (renderMode === 'webm-v8' || renderMode === 'webm-v9') {
+ if (
+ filenameArrLength >= 2 &&
+ filenameArr[filenameArrLength - 1] !== 'webm'
+ ) {
+ console.error(
+ 'User has selected WebM format , the output extension must be .webm'
+ );
+ process.exit(1);
+ }
+ }
+ if (renderMode === 'png') {
+ if (filenameArrLength >= 2) {
+ console.error(
+ 'User has selected PNG format , there can not be an extension'
+ );
+ process.exit(1);
+ }
+ }
+ return filename;
};
diff --git a/packages/cli/src/parse-command-line.ts b/packages/cli/src/parse-command-line.ts
index a4b1b392df..2116dfeec6 100644
--- a/packages/cli/src/parse-command-line.ts
+++ b/packages/cli/src/parse-command-line.ts
@@ -24,7 +24,7 @@ export const parseCommandLine = () => {
}
if (parsedCli.png) {
Config.Output.setOutputFormat('png');
- console.log('--png has been deprecated, use --format=png from now on');
+ console.warn('--png has been deprecated, use --format=png from now on');
}
if (parsedCli.format) {
Config.Output.setOutputFormat(parsedCli.format);
diff --git a/packages/cli/src/render.tsx b/packages/cli/src/render.tsx
index 14443dba95..05f6c2ae91 100644
--- a/packages/cli/src/render.tsx
+++ b/packages/cli/src/render.tsx
@@ -29,21 +29,12 @@ export const render = async () => {
parseCommandLine();
const parallelism = Internals.getConcurrency();
const renderMode = Internals.getOutputFormat();
- const outputFile = getOutputFilename();
+ const outputFile = getOutputFilename(renderMode);
const overwrite = Internals.getShouldOverwrite();
const userProps = getUserProps();
const quality = Internals.getQuality();
const absoluteOutputFile = path.resolve(process.cwd(), outputFile);
- const absoluteOutputFileWithExtension = (): string => {
- if (renderMode === 'mp4') {
- return absoluteOutputFile + '.mp4';
- }
- if (renderMode === 'webm-v8' || renderMode === 'webm-v9') {
- return absoluteOutputFile + '.webm';
- }
- return absoluteOutputFile;
- };
if (fs.existsSync(absoluteOutputFile) && !overwrite) {
console.log(
`File at ${absoluteOutputFile} already exists. Use --overwrite to overwrite.`
@@ -138,7 +129,7 @@ export const render = async () => {
width: config.width,
height: config.height,
fps: config.fps,
- outputLocation: absoluteOutputFileWithExtension(),
+ outputLocation: absoluteOutputFile,
force: overwrite,
imageFormat: getFrameFormat(renderMode),
pixelFormat: Internals.getPixelFormat(),
@@ -152,5 +143,5 @@ export const render = async () => {
} else {
console.log('\n▶️ Your PNG sequence is ready!');
}
- console.log(absoluteOutputFileWithExtension());
+ console.log(absoluteOutputFile);
};