{"record":{"id":"b643f65183ef1c71","repo":"remotion-dev/remotion","slug":"only-supporting-layer-0-for-ts","errorCode":null,"errorMessage":"Only supporting layer 0 for .ts","messagePattern":"Only supporting layer 0 for \\.ts","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/media-parser/src/containers/transport-stream/adts-header.ts","lineNumber":32,"sourceCode":"\t\tmaxBytes: buffer.byteLength,\n\t\tlogLevel: 'error',\n\t});\n\n\titerator.startReadingBits();\n\tconst bits = iterator.getBits(12);\n\tif (bits !== 0xfff) {\n\t\tthrow new Error('Invalid ADTS header ');\n\t}\n\n\t// MPEG Version, set to 0 for MPEG-4 and 1 for MPEG-2.\n\tconst id = iterator.getBits(1);\n\tif (id !== 0) {\n\t\tthrow new Error('Only supporting MPEG-4 for .ts');\n\t}\n\n\tconst layer = iterator.getBits(2);\n\tif (layer !== 0) {\n\t\tthrow new Error('Only supporting layer 0 for .ts');\n\t}\n\n\tconst protectionAbsent = iterator.getBits(1); // protection absent\n\tconst audioObjectType = iterator.getBits(2); // 1 = 'AAC-LC'\n\n\tconst samplingFrequencyIndex = iterator.getBits(4);\n\tconst sampleRate = getSampleRateFromSampleFrequencyIndex(\n\t\tsamplingFrequencyIndex,\n\t);\n\titerator.getBits(1); // private bit\n\tconst channelConfiguration = iterator.getBits(3);\n\tconst codecPrivate = createAacCodecPrivate({\n\t\taudioObjectType,\n\t\tsampleRate,\n\t\tchannelConfiguration,\n\t\tcodecPrivate: null,\n\t});\n\titerator.getBits(1); // originality","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/remotion-dev/remotion/blob/78fe4bb3fdb5a2cd68724393d63cb223db333fa7/packages/media-parser/src/containers/transport-stream/adts-header.ts#L14-L50","documentation":"Thrown by readAdtsHeader() when the 2-bit ADTS 'layer' field is not 0. Per the MPEG-4 ADTS spec the layer field is always 00 (reserved/unused); any other value indicates a corrupt header or non-ADTS data.","triggerScenarios":"A corrupt ADTS header where the layer bits are non-zero, almost always caused by bit-flips or misaligned reading rather than a legitimately different stream — valid ADTS always has layer == 0.","commonSituations":"Corrupt TS payload, misaligned ADTS read, bit errors in transport, or random data being parsed as ADTS.","solutions":["Re-acquire or re-encode the TS stream: ffmpeg -i in.ts -c copy out.ts (re-mux) or ffmpeg -i in.ts -c:a aac out.ts (re-encode AAC).","Resync the ADTS reader to the next 0xFFF sync word before retrying.","Validate the stream with ffprobe before parsing."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// The ADTS layer field must be 00 (bits 2..3 of byte 1).\nfunction isAdtsLayerZero(buf: Uint8Array): boolean {\n  return buf.length >= 2 && (buf[1] & 0x06) === 0;\n}\nif (!isAdtsLayerZero(buffer)) {\n  // corrupt header — resync or re-encode\n}","typeGuard":"function isAdtsLayerZero(buf: Uint8Array): boolean {\n  return buf.length >= 2 && (buf[1] & 0x06) === 0;\n}","tryCatchPattern":"try {\n  const hdr = readAdtsHeader(buffer);\n} catch (err) {\n  if (err instanceof Error && err.message === 'Only supporting layer 0 for .ts') {\n    // corrupt header: resync to next 0xFFF and retry\n  } else throw err;\n}","preventionTips":["Treat a non-zero ADTS layer as corruption and resync.","Re-encode suspect TS files with ffmpeg to regenerate clean ADTS.","Validate streams with ffprobe before parsing."],"tags":["transport-stream","adts","aac","corrupt-header","media-parser"],"backgroundTag":null,"analyzedSha":"78fe4bb3fdb5a2cd68724393d63cb223db333fa7","analyzedAt":"2026-08-12T17:18:50.444Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}