remotion-dev/remotion · warning · Error
Invalid traf number size
Error message
Invalid traf number size
What it means
Thrown in readTrafNumber() while parsing a tfra (track fragment random access) box inside mfra. The 2-bit lengthSizeOfTrafNum field yields a uint width other than {8,16,32,64} bits — i.e. it maps to the unsupported 24-bit or 48-bit widths ((lengthSizeOfTrafNum+1)*8 must be one of those four). The traf number size is therefore invalid and the parser aborts.
Source
Thrown at packages/media-parser/src/containers/iso-base-media/mfra/tfra.ts:39
): number => {
const uintTypeTrafNum = (lengthSizeOfTrafNum + 1) * 8;
if (uintTypeTrafNum === 8) {
return iterator.getUint8();
}
if (uintTypeTrafNum === 16) {
return iterator.getUint16();
}
if (uintTypeTrafNum === 32) {
return iterator.getUint32();
}
if (uintTypeTrafNum === 64) {
return Number(iterator.getUint64());
}
throw new Error('Invalid traf number size');
};
const readTrunNumber = (
iterator: BufferIterator,
lengthSizeOfTrunNum: number,
): number => {
const uintTypeTrunNum = (lengthSizeOfTrunNum + 1) * 8;
if (uintTypeTrunNum === 8) {
return iterator.getUint8();
}
if (uintTypeTrunNum === 16) {
return iterator.getUint16();
}
if (uintTypeTrunNum === 32) {
return iterator.getUint32();
}View on GitHub (pinned to 78fe4bb3fd)
Solutions
- Re-mux the fragmented stream without an mfra index, or regenerate it: ffmpeg -i in.mp4 -c copy -movflags +faststart out.mp4.
- Obtain a fresh copy of the segment if you suspect transfer corruption.
- If you do not need seeking, request fields/on* callbacks that let the parser skip video data (maySkipVideoData path) so the mfra is not required.
- Migrate to @remotion/mediabunny (parseMedia is deprecated).
Example fix
// before
const {slowKeyframes} = await parseMedia({src: fragmentedMp4, reader: nodeReader});
// after
try {
const r = await parseMedia({src: fragmentedMp4, reader: nodeReader});
} catch (err) {
if (err instanceof Error && /Invalid traf number size/.test(err.message)) {
// mfra/tfra index corrupt; re-mux to regenerate or drop the index
} else throw err;
} Defensive patterns
Strategy: try-catch
Validate before calling
// Only fragmented MP4 with an mfra box hits this. Validate the segment with:
// ffprobe -v warning -show_entries format=tags in.mp4
import {execFileSync} from 'node:child_process';
function fragmentLooksIntact(file: string): boolean {
try {
execFileSync('ffprobe', ['-v','warning','-hide_banner', file], {encoding:'utf8', stdio:'pipe'});
return true;
} catch { return false; }
} Type guard
// tfra size-encoding bits are deep binary fields in the mfra index; not caller-type-guardable. // => typeGuard: null
Try / catch
try {
await parseMedia({src: fragmentedMp4, reader: nodeReader});
} catch (err) {
if (err instanceof Error && /Invalid traf number size/.test(err.message)) {
// mfra/tfra index corrupt; re-mux to regenerate or drop the index
} else {
throw err;
}
} Prevention
- Re-mux fragmented MP4 with ffmpeg to regenerate a valid mfra index.
- Request only fields that don't force sample iteration to avoid the mfra path.
- Re-fetch segments suspected of corruption.
- Migrate to @remotion/mediabunny (parseMedia is deprecated).
When it happens
Trigger: parseMedia({src}) on a fragmented MP4 whose mfra/tfra box has a malformed size-encoding byte, or whose tmpByte bit-fields are corrupted. Only relevant for fragmented MP4 files that contain an mfra box (used for optimised seeking).
Common situations: Corrupted fragmented MP4 (DASH/CMAF segments with an mfra index); non-compliant packagers writing invalid tfra size fields; bit-level corruption in the tfra header.
Related errors
- Invalid trun number size
- Invalid sample number size
- No video section defined
- Expected stsz box in trak box
- Expected stco box in trak box
AI-assisted analysis of remotion-dev/remotion@78fe4bb3fd (2026-08-12).
Data as JSON: /api/errors/2e5543a704257452.
Report an issue: GitHub.