remotion-dev/remotion · error · Error

Offset ${offsetNow - startOffset} is larger than the length

Error message

Offset ${offsetNow - startOffset} is larger than the length of the hex ${size}

What it means

While parsing the children of a container EBML element, the iterator's offset advanced past the parent's declared size (offsetNow - startOffset > size). This is a structural inconsistency: the sum of child element sizes does not fit inside the parent, so the EBML tree is corrupt.

Source

Thrown at packages/media-parser/src/containers/webm/parse-ebml.ts:142

			const offset = iterator.counter.getOffset();
			const value = await parseEbml(iterator, statesForProcessing, logLevel);

			if (value) {
				const remapped = statesForProcessing
					? // eslint-disable-next-line @typescript-eslint/no-use-before-define
						await postprocessEbml({
							offset,
							ebml: value,
							statesForProcessing,
						})
					: value;
				children.push(remapped);
			}

			const offsetNow = iterator.counter.getOffset();

			if (offsetNow - startOffset > size) {
				throw new Error(
					`Offset ${offsetNow - startOffset} is larger than the length of the hex ${size}`,
				);
			}

			if (offsetNow - startOffset === size) {
				break;
			}
		}

		return {type: hasInMap.name, value: children, minVintWidth};
	}

	// @ts-expect-error
	throw new Error(`Unknown segment type ${hasInMap.type}`);
};

export const postprocessEbml = async ({
	offset,

View on GitHub (pinned to 78fe4bb3fd)

Solutions

  1. Re-mux with ffmpeg ('ffmpeg -i in.mkv -c copy out.mkv') to rebuild correct EBML sizes.
  2. Open the file with ffprobe/MediaInfo; if they also report errors, the file is structurally damaged.
  3. Obtain a fresh copy of the source.
  4. Switch to Mediabunny for an alternative parse path.

Example fix

// before
await parseMedia({src: 'corrupt.mkv'}); // throws with 'Offset N is larger than the length of the hex M'

// after
// shell: ffmpeg -i corrupt.mkv -c copy remuxed.mkv
await parseMedia({src: 'remuxed.mkv'});
Defensive patterns

Strategy: try-catch

Validate before calling

// Structural integrity pre-check via ffprobe (returns non-zero on corrupt EBML).
import {execFileSync} from 'node:child_process';
function isStructurallyValid(file: string): boolean {
  try {
    execFileSync('ffprobe', ['-v', 'error', '-count_packets', file], {stdio: 'ignore'});
    return true;
  } catch { return false; }
}
if (!isStructurallyValid('in.mkv')) throw new Error('corrupt EBML structure');

Try / catch

try {
  await parseMedia({src: 'in.mkv'});
} catch (err) {
  if (err instanceof Error && /Offset .* is larger than the length of the hex/.test(err.message)) {
    throw new Error('Corrupt EBML container sizes; re-mux with ffmpeg.', {cause: err});
  }
  throw err;
}

Prevention

When it happens

Trigger: A corrupted or hand-edited Matroska file where a container's declared size is smaller than its actual children; a bit-flip in a size VInt; or a parser bug where a child consumed too many bytes. The message interpolates the overrun and the declared size for diagnosis.

Common situations: Files damaged in transfer/storage, files written by buggy muxers that mis-size containers, or partial overwrites.

Related errors


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