Skip to content

🎥 Make videos programmatically with React

validate file extension

Jonny Burgera09f8adec2a4
diff --git a/packages/cli/src/still.ts b/packages/cli/src/still.ts
index 629e6b894c..e80f304b0d 100644
--- a/packages/cli/src/still.ts
+++ b/packages/cli/src/still.ts
@@ -6,7 +6,7 @@ import {
import chalk from 'chalk';
import {mkdirSync} from 'fs';
import path from 'path';
-import {Internals} from 'remotion';
+import {Config, Internals} from 'remotion';
import {getCliOptions} from './get-cli-options';
import {getCompositionId} from './get-composition-id';
import {handleCommonError} from './handle-common-errors';
@@ -26,6 +26,13 @@ export const still = async () => {
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 PNG.'
+ );
+ Config.Rendering.setImageFormat('jpeg');
+ }
+
const {
inputProps,
envVariables,
@@ -42,6 +49,22 @@ export const still = async () => {
process.exit(1);
}
+ if (imageFormat === 'png' && !userOutput.endsWith('.png')) {
+ Log.warn(
+ `Rendering a PNG, expected a .png extension but got ${userOutput}`
+ );
+ }
+
+ if (
+ imageFormat === 'jpeg' &&
+ !userOutput.endsWith('.jpg') &&
+ !userOutput.endsWith('.jpeg')
+ ) {
+ Log.warn(
+ `Rendering a JPEG, expected a .jpg or .jpeg extension but got ${userOutput}`
+ );
+ }
+
const browserInstance = RenderInternals.openBrowser(browser, {
shouldDumpIo: Internals.Logging.isEqualOrBelowLogLevel('verbose'),
});