remotion-dev/remotion · error · Error

Cannot get duration of VBR MP3 file - no sample rate

Error message

Cannot get duration of VBR MP3 file - no sample rate

What it means

Thrown by `getDurationFromMp3Xing` when computing a VBR MP3 duration and `xingData.sampleRate` is missing or falsy. The sample rate is required to convert sample counts into seconds; a Xing header without it is malformed.

Source

Thrown at packages/media-parser/src/containers/mp3/get-duration.ts:20

import {getMpegFrameLength} from './get-frame-length';
import type {XingData} from './parse-xing';
import {getSamplesPerMpegFrame} from './samples-per-mpeg-file';

export const getDurationFromMp3Xing = ({
	xingData,
	samplesPerFrame,
}: {
	xingData: XingData;
	samplesPerFrame: number;
}) => {
	const xingFrames = xingData.numberOfFrames;
	if (!xingFrames) {
		throw new Error('Cannot get duration of VBR MP3 file - no frames');
	}

	const {sampleRate} = xingData;
	if (!sampleRate) {
		throw new Error('Cannot get duration of VBR MP3 file - no sample rate');
	}

	const xingSamples = xingFrames * samplesPerFrame;
	return xingSamples / sampleRate;
};

export const getDurationFromMp3 = (state: ParserState): number | null => {
	const mp3Info = state.mp3.getMp3Info();
	const mp3BitrateInfo = state.mp3.getMp3BitrateInfo();
	if (!mp3Info || !mp3BitrateInfo) {
		return null;
	}

	const samplesPerFrame = getSamplesPerMpegFrame({
		layer: mp3Info.layer,
		mpegVersion: mp3Info.mpegVersion,
	});

View on GitHub (pinned to 78fe4bb3fd)

Solutions

  1. Re-encode the MP3 file with a well-formed encoder that writes the sample rate into the Xing header.
  2. Convert the file to CBR MP3 or a different container (e.g., M4A/MP4) to bypass the VBR Xing path.
  3. Validate the file with `ffprobe` or a similar tool to check header integrity.
  4. Use try-catch around `parseMedia` and handle the corrupt file gracefully.
Defensive patterns

Strategy: try-catch

Try / catch

try {
  await parseMedia({src, fields: {durationInSeconds: true}});
} catch (e) {
  if (e instanceof Error && e.message.includes('no sample rate')) {
    console.error('The VBR MP3 has a corrupt Xing header with no sample rate.');
  }
  throw e;
}

Prevention

When it happens

Trigger: An MP3 file whose Xing header was parsed but the `sampleRate` field came back as `0`, `null`, or `undefined`. This happens when `parseXing` could not extract or infer the sample rate from the header data.

Common situations: Corrupt or non-standard Xing headers where the sample rate bytes are absent or zero. MP3 files with damaged headers from partial downloads or faulty encoders. Files where the Xing header references a frame whose sample rate couldn't be decoded.

Related errors


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