{"record":{"id":"ba37b0d9b0d7ad28","repo":"remotion-dev/remotion","slug":"expected-length-is-null","errorCode":null,"errorMessage":"Expected length is null","messagePattern":"Expected length is null","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/media-parser/src/containers/transport-stream/process-audio.ts","lineNumber":70,"sourceCode":"\tlogLevel: MediaParserLogLevel;\n\tonAudioTrack: MediaParserOnAudioTrack | null;\n\tonVideoTrack: MediaParserOnVideoTrack | null;\n\ttransportStream: TransportStreamState;\n\toffset: number;\n\tmakeSamplesStartAtZero: boolean;\n\tavcState: AvcState;\n}): Promise<void> => {\n\tconst {streamBuffers, nextPesHeaderStore: nextPesHeader} = transportStream;\n\tconst streamBuffer = streamBuffers.get(transportStreamEntry.pid);\n\tif (!streamBuffer) {\n\t\tthrow new Error('Stream buffer not found');\n\t}\n\n\tconst expectedLength =\n\t\treadAdtsHeader(streamBuffer.getBuffer())?.frameLength ?? null;\n\n\tif (expectedLength === null) {\n\t\tthrow new Error('Expected length is null');\n\t}\n\n\tif (expectedLength > streamBuffer.getBuffer().length) {\n\t\tthrow new Error('Expected length is greater than stream buffer length');\n\t}\n\n\tawait processStreamBuffer({\n\t\tstreamBuffer: makeTransportStreamPacketBuffer({\n\t\t\tbuffers: streamBuffer.getBuffer().slice(0, expectedLength),\n\t\t\toffset,\n\t\t\tpesHeader: streamBuffer.pesHeader,\n\t\t}),\n\t\tprogramId: transportStreamEntry.pid,\n\t\tstructure,\n\t\tsampleCallbacks,\n\t\tlogLevel,\n\t\tonAudioTrack,\n\t\tonVideoTrack,","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/remotion-dev/remotion/blob/78fe4bb3fdb5a2cd68724393d63cb223db333fa7/packages/media-parser/src/containers/transport-stream/process-audio.ts#L52-L88","documentation":"Thrown by processAudio at process-audio.ts:70 when readAdtsHeader returns null (no parseable ADTS header) for the buffered audio bytes. The library expects AAC streams to carry an ADTS framing; without it, the frame length cannot be determined.","triggerScenarios":"processAudio calls readAdtsHeader(streamBuffer.getBuffer()) and checks for a null result. Triggered when the audio PID is not actually AAC/ADTS (e.g. MP2/MP3, AC-3, or raw AAC LATM), when the buffer is too short to contain a full ADTS header (7 bytes), or when the bytes are corrupted.","commonSituations":"Stream declared as stream_type=15 (AAC) but actually carrying another codec; partial packets where ADTS framing is split; LATM/LOAS wrapped AAC; private-stream audio routed through the AAC path.","solutions":["Re-encode audio as plain ADTS-AAC: ffmpeg -i in.ts -c:a aac -f adts out.aac, then re-mux.","Verify the audio codec with ffprobe before parsing.","Filter the stream to only supported codecs before passing to @remotion/media-parser.","File a feature request if you need MP2/AC-3/LATM support."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Verify audio codec is AAC/ADTS before parsing\nimport {execSync} from 'node:child_process';\nfunction isAdtsAac(src: string): boolean {\n  try {\n    const out = execSync(`ffprobe -v error -select_streams a -show_entries stream=codec_name -of csv=p=0 \"${src}\"`).toString().trim();\n    return out === 'aac';\n  } catch { return false; }\n}","typeGuard":null,"tryCatchPattern":"try { await parseMedia({src}); }\ncatch (e) {\n  if (e instanceof Error && e.message === 'Expected length is null') {\n    // re-encode audio as ADTS-AAC\n    await runFfmpeg(['-i', src, '-c:v', 'copy', '-c:a', 'aac', '-f', 'mpegts', out]);\n    await parseMedia({src: out});\n  } else throw e;\n}","preventionTips":["Verify audio codec with ffprobe before parsing transport streams.","Re-encode non-AAC audio to AAC/ADTS for transport-stream compatibility.","Filter streams to supported codecs before parsing."],"tags":["media-parser","transport-stream","mpegts","audio","aac","adts"],"backgroundTag":null,"analyzedSha":"78fe4bb3fdb5a2cd68724393d63cb223db333fa7","analyzedAt":"2026-08-12T17:18:50.444Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}