{"record":{"id":"171af76424de1a1a","repo":"remotion-dev/remotion","slug":"only-supporting-layer-0-for-aac","errorCode":null,"errorMessage":"Only supporting layer 0 for .aac","messagePattern":"Only supporting layer 0 for \\.aac","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/media-parser/src/containers/aac/parse-aac.ts","lineNumber":29,"sourceCode":"\nexport const parseAac = async (state: ParserState): Promise<ParseResult> => {\n\tconst {iterator} = state;\n\tconst startOffset = iterator.counter.getOffset();\n\n\titerator.startReadingBits();\n\tconst syncWord = iterator.getBits(12);\n\tif (syncWord !== 0xfff) {\n\t\tthrow new Error('Invalid syncword: ' + syncWord);\n\t}\n\n\tconst id = iterator.getBits(1);\n\tif (id !== 0) {\n\t\tthrow new Error('Only supporting MPEG-4 for .aac');\n\t}\n\n\tconst layer = iterator.getBits(2);\n\tif (layer !== 0) {\n\t\tthrow new Error('Only supporting layer 0 for .aac');\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":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/remotion-dev/remotion/blob/78fe4bb3fdb5a2cd68724393d63cb223db333fa7/packages/media-parser/src/containers/aac/parse-aac.ts#L11-L47","documentation":"Thrown by parseAac when the 2-bit 'layer' field in an ADTS header is non-zero. Per the ADTS specification, valid AAC streams must have layer=0 (indicating MPEG-4 Audio). A non-zero layer means the bitstream is either not AAC or the header is corrupted, so the parser refuses to continue.","triggerScenarios":"Parsing a .aac file where the ADTS header's layer field (bits 13-14 after sync) is 1, 2, or 3 instead of 0. This can result from bit corruption, a file that is actually MP3 with an AAC extension, or a misaligned read position.","commonSituations":"Files mislabeled with a .aac extension that are actually MP3 or another MPEG audio layer. Corrupted downloads where header bits are flipped. Byte streams with a prepended ID3 tag or other metadata that offsets the read position.","solutions":["Check the actual format with `ffprobe input.aac` — if it reports MP3 or another codec, rename/re-handle accordingly.","If ID3 tags are prepended, strip them: `ffmpeg -i input.aac -c:a copy -map_metadata -1 output.aac`.","Re-encode from a known-good source to produce valid ADTS: `ffmpeg -i input.wav -c:a aac -f adts output.aac`.","Switch to Mediabunny (https://www.remotion.dev/docs/mediabunny/metadata) for broader format handling."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Pre-check: verify ADTS layer bits are 0 (bits 13-14 of ADTS header)\nasync function isAdtsLayerZero(filePath: string): Promise<boolean> {\n  const buf = await readFile(filePath);\n  if (buf.length < 2) return false;\n  // Byte 1, bits 1-2 = layer field; should be 00\n  return (buf[1] & 0x06) === 0x00;\n}","typeGuard":null,"tryCatchPattern":"try {\n  const result = await parseMedia({src, fields: {/* ... */}});\n} catch (e) {\n  if (e instanceof Error && e.message === 'Only supporting layer 0 for .aac') {\n    console.error('ADTS layer is non-zero. File may be corrupt or mislabeled. Run: ffprobe <file>');\n  } else {\n    throw e;\n  }\n}","preventionTips":["Verify the actual audio format with ffprobe before parsing.","Strip ID3 tags and other prepended metadata that could misalign the parser.","Re-encode from a known-good source if the file is corrupt.","Migrate to Mediabunny for more robust format handling."],"tags":["aac","adts","media-parser","layer","corrupt-file","container-detection"],"backgroundTag":null,"analyzedSha":"78fe4bb3fdb5a2cd68724393d63cb223db333fa7","analyzedAt":"2026-08-12T17:18:50.444Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}