🎥 Make videos programmatically with React
validate H264 odd dimensions
Jonny Burgerda5d3abaf7ce
diff --git a/packages/cli/src/render.tsx b/packages/cli/src/render.tsxindex c1faef4b68..c1d8f35d91 100644--- a/packages/cli/src/render.tsx+++ b/packages/cli/src/render.tsx@@ -111,6 +111,7 @@ export const render = async () => {width: config.width,height: config.height,codec,+ scale: config.scale ?? 1,});const outputDir = shouldOutputImageSequence@@ -205,8 +206,8 @@ export const render = async () => {const stitchStart = Date.now();await stitchFramesToVideo({dir: outputDir,- width: config.width,- height: config.height,+ width: config.width * (config.scale ?? 1),+ height: config.height * (config.scale ?? 1),fps: config.fps,outputLocation: absoluteOutputFile,force: overwrite,@@ -283,6 +284,6 @@ export const render = async () => {].join(' '));Log.info('-', 'Output can be found at:');- Log.info(chalk.cyan(`▶️ ${absoluteOutputFile}`));+ Log.info(chalk.cyan(`▶ ${absoluteOutputFile}`));await closeBrowserPromise;};diff --git a/packages/renderer/src/stitcher.ts b/packages/renderer/src/stitcher.tsindex 5934a1bfa0..f9f928a8b0 100644--- a/packages/renderer/src/stitcher.ts+++ b/packages/renderer/src/stitcher.ts@@ -61,6 +61,7 @@ export const stitchFramesToVideo = async (options: {width: options.width,height: options.height,codec,+ scale: 1,});const crf = options.crf ?? Internals.getDefaultCrfForCodec(codec);const imageFormat = options.imageFormat ?? DEFAULT_IMAGE_FORMAT;diff --git a/packages/renderer/src/validate-even-dimensions-with-codec.ts b/packages/renderer/src/validate-even-dimensions-with-codec.tsindex cf0da350f4..36194f22d0 100644--- a/packages/renderer/src/validate-even-dimensions-with-codec.ts+++ b/packages/renderer/src/validate-even-dimensions-with-codec.ts@@ -1,33 +1,46 @@-import {Codec} from 'remotion';+import {Codec, Internals} from 'remotion';export const validateEvenDimensionsWithCodec = ({width,height,codec,+ scale,}: {width: number;height: number;+ scale: number;codec: Codec;}) => {if (codec !== 'h264-mkv' && codec !== 'h264' && codec !== 'h265') {return;}+ const actualWidth = width * scale;+ const actualHeight = height * scale;+const displayName = codec === 'h265' ? 'H265' : 'H264';- if (width % 2 !== 0) {- throw new Error(- `Codec error: You are trying to render a video with a ${displayName} codec that has a width of ${width}px, which is an odd number. The ${displayName} codec does only support dimensions with even numbers. Change the width to ${Math.floor(- width - 1- )}px to fix this issue.`- );+ if (actualWidth % 2 !== 0) {+ const message = [+ `Codec error: You are trying to render a video with a ${displayName} codec that has a width of ${actualWidth}px, which is an uneven number.`,+ `The ${displayName} codec does only support dimensions that are evenly divisible by two.`,+ scale === 1+ ? `Change the width to ${Math.floor(width - 1)}px to fix this issue.`+ : `You have used the "scale" option which might be the reason for the problem: The original width is ${width} and the scale is ${scale}x, which was multiplied to get the actual width.`,+ ]+ .filter(Internals.truthy)+ .join(' ');+ throw new Error(message);}if (height % 2 !== 0) {- throw new Error(- `Codec error: You are trying to render a video with a ${displayName} codec that has a height of ${height}px, which is an odd number. The ${displayName} codec does only support dimensions with even numbers. Change the height to ${Math.floor(- height - 1- )}px to fix this issue.`- );+ const message = [+ `Codec error: You are trying to render a video with a ${displayName} codec that has a height of ${actualHeight}px, which is an uneven number.`,+ `The ${displayName} codec does only support dimensions that are evenly divisible by two. `,+ scale === 1+ ? `Change the height to ${Math.floor(height - 1)}px to fix this issue.`+ : `You have used the "scale" option which might be the reason for the problem: The original height is ${height} and the scale is ${scale}x, which was multiplied to get the actual height.`,+ ].join(' ');+ throw new Error(message);}};