remotion-dev/remotion · error · Error

Scale must be greater than 0

Error message

Scale must be greater than 0

What it means

Thrown by calculateNewSizeAfterResizing when resizeOperation.mode === 'scale' and the supplied scale is <= 0. The function multiplies width/height by scale, so a zero or negative scale would produce invalid (zero or negative) dimensions.

Source

Thrown at packages/convert/app/lib/calculate-new-dimensions-from-dimensions.ts:65

			},
			needsToBeMultipleOfTwo,
		});
	}

	if (resizeOperation.mode === 'max-width') {
		const width = Math.min(dimensions.width, resizeOperation.maxWidth);
		return ensureMultipleOfTwo({
			dimensions: {
				width,
				height: Math.round((width / dimensions.width) * dimensions.height),
			},
			needsToBeMultipleOfTwo,
		});
	}

	if (resizeOperation.mode === 'scale') {
		if (resizeOperation.scale <= 0) {
			throw new Error('Scale must be greater than 0');
		}

		const width = Math.round(dimensions.width * resizeOperation.scale);
		const height = Math.round(dimensions.height * resizeOperation.scale);
		return ensureMultipleOfTwo({
			dimensions: {
				width,
				height,
			},
			needsToBeMultipleOfTwo,
		});
	}

	throw new Error('Invalid resizing mode ' + (resizeOperation satisfies never));
};

export const normalizeVideoRotation = (rotation: number) => {
	return ((rotation % 360) + 360) % 360;

View on GitHub (pinned to 78fe4bb3fd)

Solutions

  1. Clamp the scale input to a small positive minimum (e.g. 0.01) before constructing the resize operation.
  2. Validate the resize config at the form/UI boundary so scale must be a positive finite number.
  3. Default scale to 1 when the field is missing or invalid.

Example fix

// before
const scale = Number(userInput); // 0 or negative allowed
resizeOperation = {mode: 'scale', scale};

// after
const scale = Math.max(0.01, Number(userInput) || 1);
if (!Number.isFinite(scale) || scale <= 0) {
  throw new Error('Scale must be a positive number');
}
resizeOperation = {mode: 'scale', scale};
Defensive patterns

Strategy: validation

Validate before calling

function isValidScale(scale: number): boolean {
  return Number.isFinite(scale) && scale > 0;
}
if (!isValidScale(resizeOperation.scale)) throw new Error('Scale must be a positive finite number');

Type guard

function isValidResize(op: MediabunnyResize | null): boolean {
  if (!op) return true;
  if (op.mode === 'scale') return Number.isFinite(op.scale) && op.scale > 0;
  return true;
}

Try / catch

try {
  return calculateNewSizeAfterResizing({...});
} catch (e) {
  if (e.message === 'Scale must be greater than 0') return dimensions; // ignore resize
  throw e;
}

Prevention

When it happens

Trigger: Passing a MediabunnyResize of mode 'scale' with scale = 0, a negative number, or NaN (NaN <= 0 is false but yields NaN dims elsewhere). Direct misuse of the resize API or a UI control that allows zero/negative scale values.

Common situations: A slider bound to scale that can reach zero; deserialized config with a missing/zeroed scale field; division or parsing that yields a negative scale.

Related errors


AI-assisted analysis of remotion-dev/remotion@78fe4bb3fd (2026-08-12). Data as JSON: /api/errors/c1edf0e2b3a879ef. Report an issue: GitHub.