remotion-dev/remotion · error · TypeError
The argument "bars" must be a power of two. For example: 64,
Error message
The argument "bars" must be a power of two. For example: 64, 128. Got instead: ${sampleSize} What it means
Thrown by getVisualization when sampleSize (the 'bars' parameter for the audio visualization) is not a power of two. FFT requires input lengths that are powers of two (64, 128, 256, ...); other sizes break the radix-2 algorithm. The guard checks sampleSize > 0 && (sampleSize & (sampleSize - 1)) === 0.
Source
Thrown at packages/media-utils/src/fft/get-visualization.ts:33
sampleRate,
frame,
fps,
maxInt,
optimizeFor,
dataOffsetInSeconds,
}: {
sampleSize: number;
data: Float32Array;
frame: number;
sampleRate: number;
fps: number;
maxInt: number;
optimizeFor: OptimizeFor;
dataOffsetInSeconds: number;
}): number[] => {
const isPowerOfTwo = sampleSize > 0 && (sampleSize & (sampleSize - 1)) === 0;
if (!isPowerOfTwo) {
throw new TypeError(
`The argument "bars" must be a power of two. For example: 64, 128. Got instead: ${sampleSize}`,
);
}
if (!fps) {
throw new TypeError('The argument "fps" was not provided');
}
if (data.length < sampleSize) {
throw new TypeError(
'Audio data is not big enough to provide ' + sampleSize + ' bars.',
);
}
const start = Math.floor((frame / fps - dataOffsetInSeconds) * sampleRate);
const actualStart = Math.max(0, start - sampleSize / 2);
View on GitHub (pinned to 78fe4bb3fd)
Solutions
- Use a power-of-two value: 32, 64, 128, 256, 512, 1024, 2048.
- If accepting arbitrary user input, snap it to the nearest power of two before passing it in.
- Compute the next power of two: Math.pow(2, Math.round(Math.log2(n))).
Example fix
// before
const viz = getVisualization({ sampleSize: 100, ... });
// after
const sampleSize = Math.pow(2, Math.round(Math.log2(100))); // 128
const viz = getVisualization({ sampleSize, ... }); Defensive patterns
Strategy: validation
Validate before calling
function assertPowerOfTwo(n: number) { if (!(n > 0 && (n & (n - 1)) === 0)) throw new TypeError('bars must be a power of two'); }
assertPowerOfTwo(sampleSize); Type guard
const isPowerOfTwo = (n: number): boolean => n > 0 && (n & (n - 1)) === 0;
Try / catch
try { return getVisualization({ sampleSize, ...rest }); } catch (e) { if (/power of two/.test(String((e as Error).message))) { sampleSize = Math.pow(2, Math.round(Math.log2(sampleSize))); return getVisualization({ sampleSize, ...rest }); } throw e; } Prevention
- Snap arbitrary bar counts to the nearest power of two before calling.
- Whitelist allowed sizes: [32, 64, 128, 256, 512, 1024, 2048].
- Validate UI inputs before forwarding to the FFT API.
When it happens
Trigger: Passing a numberOfBars/sampleSize value that is zero, negative, or not a power of two (e.g. 100, 50, 7) to the visualization/FFT API. The bit-trick check immediately rejects it before any FFT math runs.
Common situations: Letting user input dictate the bar count without rounding to a power of two. Copying a snippet that used a non-FFT visualization with arbitrary counts. Config-driven components where a designer set bars: 100.
Related errors
- Audio data is not big enough to provide ${sampleSize} bars.
- The argument "fps" was not provided
- No 'src' was passed to <Html5Audio>.
- No src passed
- The "freeze" prop is not supported on <Html5Audio />. Use <S
AI-assisted analysis of remotion-dev/remotion@78fe4bb3fd (2026-08-12).
Data as JSON: /api/errors/fc8ae58f7314e446.
Report an issue: GitHub.