Skip to content

🎥 Make videos programmatically with React

validate prores + throw if config file does not match file extension

Jonny Burgerbf06fab143b6
diff --git a/packages/cli/src/get-cli-options.ts b/packages/cli/src/get-cli-options.ts
index 1f7df439ab..8edd34a2ff 100644
--- a/packages/cli/src/get-cli-options.ts
+++ b/packages/cli/src/get-cli-options.ts
@@ -155,12 +155,8 @@ const getAndValidatePixelFormat = (codec: Codec) => {
return pixelFormat;
};
-const getAndValidateProResProfile = (actualCodec: Codec) => {
+const getProResProfile = () => {
const proResProfile = ConfigInternals.getProResProfile();
- RenderInternals.validateSelectedCodecAndProResCombination(
- actualCodec,
- proResProfile
- );
return proResProfile;
};
@@ -222,7 +218,7 @@ export const getCliOptions = async (options: {
codec: options.codec,
pixelFormat,
});
- const proResProfile = getAndValidateProResProfile(options.codec);
+ const proResProfile = getProResProfile();
const browserExecutable = ConfigInternals.getBrowserExecutable();
const ffmpegExecutable = ConfigInternals.getCustomFfmpegExecutable();
const ffprobeExecutable = ConfigInternals.getCustomFfprobeExecutable();
diff --git a/packages/cli/src/get-final-output-codec.ts b/packages/cli/src/get-final-output-codec.ts
index 06a715d702..27f1d13f99 100644
--- a/packages/cli/src/get-final-output-codec.ts
+++ b/packages/cli/src/get-final-output-codec.ts
@@ -72,6 +72,12 @@ export const getFinalOutputCodec = ({
);
}
+ if (configFile && derivedOutNameCodec !== configFile) {
+ throw new TypeError(
+ `The out name is ${outName} but ${configFile} was set as the codec in the config file. The out name implies a codec of ${derivedOutNameCodec} which does not align with the codec set in the config file.`
+ );
+ }
+
return {
codec: derivedOutNameCodec,
reason: 'derived from out name',
diff --git a/packages/renderer/src/prores-profile.ts b/packages/renderer/src/prores-profile.ts
index 5aca6d90df..1e67da77c4 100644
--- a/packages/renderer/src/prores-profile.ts
+++ b/packages/renderer/src/prores-profile.ts
@@ -11,22 +11,25 @@ const proResProfileOptions = [
export type ProResProfile = typeof proResProfileOptions[number];
-export const validateSelectedCodecAndProResCombination = (
- actualCodec: Codec,
- actualProResProfile: ProResProfile | undefined
-) => {
- if (typeof actualProResProfile !== 'undefined' && actualCodec !== 'prores') {
+export const validateSelectedCodecAndProResCombination = ({
+ codec,
+ proResProfile,
+}: {
+ codec: Codec;
+ proResProfile: ProResProfile | undefined;
+}) => {
+ if (typeof proResProfile !== 'undefined' && codec !== 'prores') {
throw new TypeError(
- 'You have set a ProRes profile but the codec is not "prores". Set the codec to "prores" or remove the ProRes profile.'
+ `You have set a ProRes profile but the codec is "${codec}". Set the codec to "prores" or remove the ProRes profile.`
);
}
if (
- actualProResProfile !== undefined &&
- !proResProfileOptions.includes(actualProResProfile as ProResProfile)
+ proResProfile !== undefined &&
+ !proResProfileOptions.includes(proResProfile as ProResProfile)
) {
throw new TypeError(
- `The ProRes profile "${actualProResProfile}" is not valid. Valid options are ${proResProfileOptions
+ `The ProRes profile "${proResProfile}" is not valid. Valid options are ${proResProfileOptions
.map((p) => `"${p}"`)
.join(', ')}`
);
diff --git a/packages/renderer/src/render-media.ts b/packages/renderer/src/render-media.ts
index e3bf528276..f7f2247862 100644
--- a/packages/renderer/src/render-media.ts
+++ b/packages/renderer/src/render-media.ts
@@ -37,6 +37,7 @@ import type {PixelFormat} from './pixel-format';
import {prespawnFfmpeg} from './prespawn-ffmpeg';
import {shouldUseParallelEncoding} from './prestitcher-memory-usage';
import type {ProResProfile} from './prores-profile';
+import {validateSelectedCodecAndProResCombination} from './prores-profile';
import {validateQuality} from './quality';
import {renderFrames} from './render-frames';
import {stitchFramesToVideo} from './stitch-frames-to-video';
@@ -170,6 +171,11 @@ export const renderMedia = ({
validateSelectedCrfAndCodecCombination(crf, codec);
}
+ validateSelectedCodecAndProResCombination({
+ codec,
+ proResProfile,
+ });
+
if (outputLocation) {
validateOutputFilename(codec, getExtensionOfFilename(outputLocation));
}
diff --git a/packages/renderer/src/stitch-frames-to-video.ts b/packages/renderer/src/stitch-frames-to-video.ts
index d7192aff1b..7047c28375 100644
--- a/packages/renderer/src/stitch-frames-to-video.ts
+++ b/packages/renderer/src/stitch-frames-to-video.ts
@@ -36,6 +36,7 @@ import {
} from './pixel-format';
import {preprocessAudioTrack} from './preprocess-audio-track';
import type {ProResProfile} from './prores-profile';
+import {validateSelectedCodecAndProResCombination} from './prores-profile';
import {truthy} from './truthy';
import {validateEvenDimensionsWithCodec} from './validate-even-dimensions-with-codec';
import {validateFfmpeg} from './validate-ffmpeg';
@@ -182,6 +183,11 @@ export const spawnFfmpeg = async (
codec,
scale: 1,
});
+ validateSelectedCodecAndProResCombination({
+ codec,
+ proResProfile: options.proResProfile,
+ });
+
Internals.validateFps(options.fps, 'in `stitchFramesToVideo()`', false);
const crf = options.crf ?? getDefaultCrfForCodec(codec);
const pixelFormat = options.pixelFormat ?? DEFAULT_PIXEL_FORMAT;