{"record":{"id":"63e8ee673721a2c1","repo":"remotion-dev/remotion","slug":"expected-length-is-greater-than-stream-buffer-leng","errorCode":null,"errorMessage":"Expected length is greater than stream buffer length","messagePattern":"Expected length is greater than stream buffer length","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/media-parser/src/containers/transport-stream/process-audio.ts","lineNumber":74,"sourceCode":"\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,\n\t\ttransportStream,\n\t\tmakeSamplesStartAtZero,\n\t\tavcState,\n\t});","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/remotion-dev/remotion/blob/78fe4bb3fdb5a2cd68724393d63cb223db333fa7/packages/media-parser/src/containers/transport-stream/process-audio.ts#L56-L92","documentation":"Thrown by processAudio at process-audio.ts:74 when the ADTS header reports a frame length greater than the number of bytes currently buffered for the PID. This means the full AAC frame has not yet arrived (or will never arrive), so it cannot be sliced and processed.","triggerScenarios":"processAudio compares expectedLength from readAdtsHeader against streamBuffer.getBuffer().length; if the header advertises a larger frame, it throws. Triggered by truncated audio packets, packet loss, partial files, or bit-flips that inflate frameLength.","commonSituations":"Partially downloaded .ts files; network captures with dropped packets; corrupt ADTS headers that overstate frame length; live streams where the parser is invoked before enough data has accumulated.","solutions":["Ensure the input is fully downloaded/complete before parsing.","Re-mux to drop incomplete frames: ffmpeg -i in.ts -c copy out.ts.","Validate ADTS framing with faad or aacdec.","If the file is a damaged capture, re-acquire the source."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Ensure the file is fully downloaded before parsing\nimport {statSync} from 'node:fs';\nfunction isCompleteDownload(path: string, expectedSize?: number): boolean {\n  return expectedSize === undefined || statSync(path).size === expectedSize;\n}","typeGuard":null,"tryCatchPattern":"try { await parseMedia({src}); }\ncatch (e) {\n  if (e instanceof Error && e.message === 'Expected length is greater than stream buffer length') {\n    // partial file - re-fetch or re-mux\n    await runFfmpeg(['-i', src, '-c', 'copy', src + '.remux.ts']);\n    await parseMedia({src: src + '.remux.ts'});\n  } else throw e;\n}","preventionTips":["Ensure inputs are fully downloaded before parsing.","Re-mux partial files with ffmpeg to drop incomplete frames.","Validate ADTS framing with faad/aacdec."],"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-12T23:17:12.415Z"}