remotion-dev/remotion · warning · Error
Invalid trun number size
Error message
Invalid trun number size
What it means
Thrown in readTrunNumber() while parsing a tfra box. Same mechanism as the traf-number check: the 2-bit lengthSizeOfTrunNum field maps to a uint width other than {8,16,32,64} (i.e. 24- or 48-bit), which is not supported, so the trun number size is invalid and parsing aborts.
Source
Thrown at packages/media-parser/src/containers/iso-base-media/mfra/tfra.ts:63
): number => {
const uintTypeTrunNum = (lengthSizeOfTrunNum + 1) * 8;
if (uintTypeTrunNum === 8) {
return iterator.getUint8();
}
if (uintTypeTrunNum === 16) {
return iterator.getUint16();
}
if (uintTypeTrunNum === 32) {
return iterator.getUint32();
}
if (uintTypeTrunNum === 64) {
return Number(iterator.getUint64());
}
throw new Error('Invalid trun number size');
};
const readSampleNumber = (
iterator: BufferIterator,
lengthSizeOfSampleNum: number,
): number => {
const uintTypeSampleNum = (lengthSizeOfSampleNum + 1) * 8;
if (uintTypeSampleNum === 8) {
return iterator.getUint8();
}
if (uintTypeSampleNum === 16) {
return iterator.getUint16();
}
if (uintTypeSampleNum === 32) {
return iterator.getUint32();
}View on GitHub (pinned to 78fe4bb3fd)
Solutions
- Re-mux the fragmented file: ffmpeg -i in.mp4 -c copy -movflags +faststart out.mp4.
- Re-fetch a clean copy of the segment.
- Avoid the mfra path by requesting only metadata/fields that do not force full sample iteration.
- Migrate to @remotion/mediabunny (parseMedia is deprecated).
Example fix
// before
await parseMedia({src: fragmentedMp4, reader: nodeReader});
// after
try {
await parseMedia({src: fragmentedMp4, reader: nodeReader});
} catch (err) {
if (err instanceof Error && /Invalid trun number size/.test(err.message)) {
// tfra trun-number size corrupt; re-mux the fragmented file
} else throw err;
} Defensive patterns
Strategy: try-catch
Validate before calling
// Validate the fragmented segment before parsing:
// ffprobe -v warning 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 trun-number size bits are deep binary fields; not caller-type-guardable. // => typeGuard: null
Try / catch
try {
await parseMedia({src: fragmentedMp4, reader: nodeReader});
} catch (err) {
if (err instanceof Error && /Invalid trun number size/.test(err.message)) {
// tfra trun-number size corrupt; re-mux the fragmented file
} else {
throw err;
}
} Prevention
- Re-mux fragmented MP4 with ffmpeg to rebuild a valid mfra index.
- Avoid forcing the mfra/seeking path by limiting requested fields.
- Re-fetch clean copies of corrupted segments.
- Migrate to @remotion/mediabunny (parseMedia is deprecated).
When it happens
Trigger: parseMedia({src}) on a fragmented MP4 whose tfra box has a corrupt trun-number size field in its size-encoding byte. Only encountered when an mfra box is present (fragmented MP4 seeking index).
Common situations: Corrupted CMAF/DASH fragmented MP4 segments with an mfra index; malformed packager output; bit corruption in the tfra size byte.
Related errors
- Invalid traf 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/44958c46b4ee62d1.
Report an issue: GitHub.