Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Oct 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 2 additions & 6 deletions packages/cli/src/get-cli-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down Expand Up @@ -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();
Expand Down
6 changes: 6 additions & 0 deletions packages/cli/src/get-final-output-codec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
21 changes: 12 additions & 9 deletions packages/renderer/src/prores-profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(', ')}`
);
Expand Down
6 changes: 6 additions & 0 deletions packages/renderer/src/render-media.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -170,6 +171,11 @@ export const renderMedia = ({
validateSelectedCrfAndCodecCombination(crf, codec);
}

validateSelectedCodecAndProResCombination({
codec,
proResProfile,
});

if (outputLocation) {
validateOutputFilename(codec, getExtensionOfFilename(outputLocation));
}
Expand Down
6 changes: 6 additions & 0 deletions packages/renderer/src/stitch-frames-to-video.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
Expand Down
23 changes: 16 additions & 7 deletions packages/renderer/src/test/prores-profile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,31 @@ import {validateSelectedCodecAndProResCombination} from '../prores-profile';
describe('Pro Res Profile', () => {
test("Just a ProRes profile is not enough, because codec doesn't default to ProRes", () => {
expect(() => {
validateSelectedCodecAndProResCombination('aac', '4444-xq');
validateSelectedCodecAndProResCombination({
codec: 'aac',
proResProfile: '4444-xq',
});
}).toThrow(
/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 "aac". Set the codec to "prores" or remove the ProRes profile./
);
});

test('Should accept a valid codec and ProRes combination', () => {
expect(validateSelectedCodecAndProResCombination('prores', '4444')).toBe(
undefined
);
expect(
validateSelectedCodecAndProResCombination({
codec: 'prores',
proResProfile: '4444',
})
).toBe(undefined);
});

test('Should throw on invalid ProRes name', () => {
expect(() =>
// @ts-expect-error
validateSelectedCodecAndProResCombination('prores', 'typoed')
validateSelectedCodecAndProResCombination({
codec: 'prores',
// @ts-expect-error
proResProfile: 'typoed',
})
).toThrow(
/The ProRes profile "typoed" is not valid. Valid options are "4444-xq", "4444", "hq", "standard", "light", "proxy"/
);
Expand Down