remotion-dev/remotion · error
Invalid ADTS header
Error message
Invalid ADTS header
What it means
Thrown by readAdtsHeader() when the first 12 bits of an AAC ADTS frame are not the 0xFFF sync word. ADTS frames always begin with the 12-bit sync word; a mismatch means the buffer does not start on an ADTS frame boundary or the data is corrupt/not AAC.
Source
Thrown at packages/media-parser/src/containers/transport-stream/adts-header.ts:21
getSampleRateFromSampleFrequencyIndex,
} from '../../aac-codecprivate';
import {getArrayBufferIterator} from '../../iterator/buffer-iterator';
export const readAdtsHeader = (buffer: Uint8Array) => {
if (buffer.byteLength < 9) {
return null;
}
const iterator = getArrayBufferIterator({
initialData: buffer,
maxBytes: buffer.byteLength,
logLevel: 'error',
});
iterator.startReadingBits();
const bits = iterator.getBits(12);
if (bits !== 0xfff) {
throw new Error('Invalid ADTS header ');
}
// MPEG Version, set to 0 for MPEG-4 and 1 for MPEG-2.
const id = iterator.getBits(1);
if (id !== 0) {
throw new Error('Only supporting MPEG-4 for .ts');
}
const layer = iterator.getBits(2);
if (layer !== 0) {
throw new Error('Only supporting layer 0 for .ts');
}
const protectionAbsent = iterator.getBits(1); // protection absent
const audioObjectType = iterator.getBits(2); // 1 = 'AAC-LC'
const samplingFrequencyIndex = iterator.getBits(4);
const sampleRate = getSampleRateFromSampleFrequencyIndex(View on GitHub (pinned to 78fe4bb3fd)
Solutions
- Verify the stream is MPEG-TS with AAC audio (ffprobe -show_streams).
- If the TS is corrupt, re-mux/re-encode it: ffmpeg -i in.ts -c copy -muxpreload 0 -muxdelay 0 out.ts (or re-encode AAC).
- Resync before parsing by scanning for the 0xFFF sync word at expected ADTS frame boundaries.
Example fix
// before const hdr = readAdtsHeader(maybeMisalignedBuffer); // after: align to the ADTS sync word first let i = 0; while (i < buffer.length - 1 && !(buffer[i] === 0xff && (buffer[i + 1] & 0xf0) === 0xf0)) i++; const hdr = readAdtsHeader(buffer.subarray(i));
Defensive patterns
Strategy: validation
Validate before calling
// Check the ADTS 12-bit sync word (0xFFF) before fully parsing the header.
function hasAdtsSync(buf: Uint8Array): boolean {
return buf.length >= 2 && buf[0] === 0xff && (buf[1] & 0xf0) === 0xf0;
}
if (!hasAdtsSync(buffer)) {
// resync or reject before calling readAdtsHeader
} Type guard
function isAdtsSync(buf: Uint8Array): boolean {
return buf.length >= 2 && buf[0] === 0xff && (buf[1] & 0xf0) === 0xf0;
} Try / catch
try {
const hdr = readAdtsHeader(buffer);
} catch (err) {
if (err instanceof Error && err.message === 'Invalid ADTS header ') {
// scan to next 0xFFF sync and retry
} else throw err;
} Prevention
- Resync to 0xFFF before parsing ADTS.
- Verify the stream is TS/AAC with ffprobe.
- Re-mux corrupt TS files before parsing.
When it happens
Trigger: Feeding a buffer to readAdtsHeader() that is misaligned (not starting at an ADTS sync point), truncated, or not AAC audio at all. Common when a TS packet's payload pointer is wrong or when concatenating partial PES payloads incorrectly.
Common situations: Corrupt MPEG-TS streams; buggy TS demuxing that loses ADTS alignment; non-AAC audio misrouted through the ADTS reader; bit-flips in transport.
Related errors
- Only supporting MPEG-4 for .ts
- Only supporting layer 0 for .ts
- Invalid ADTS header - too short
- Expected length is null
- Expected length is greater than stream buffer length
AI-assisted analysis of remotion-dev/remotion@78fe4bb3fd (2026-08-12).
Data as JSON: /api/errors/3548899354b47043.
Report an issue: GitHub.