{"record":{"id":"e217d5a3651f2145","repo":"remotion-dev/remotion","slug":"cannot-process-avc-stream","errorCode":null,"errorMessage":"cannot process avc stream","messagePattern":"cannot process avc stream","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/media-parser/src/containers/transport-stream/process-video.ts","lineNumber":56,"sourceCode":"\ttransportStream,\n\tmakeSamplesStartAtZero,\n\tavcState,\n}: {\n\tprogramId: number;\n\tstructure: TransportStreamStructure;\n\tstreamBuffer: TransportStreamPacketBuffer;\n\tsampleCallbacks: CallbacksState;\n\tlogLevel: MediaParserLogLevel;\n\tonAudioTrack: MediaParserOnAudioTrack | null;\n\tonVideoTrack: MediaParserOnVideoTrack | null;\n\ttransportStream: TransportStreamState;\n\tmakeSamplesStartAtZero: boolean;\n\tavcState: AvcState;\n}): Promise<Uint8Array> => {\n\tconst indexOfSeparator = streamBuffer.get2ndSubArrayIndex();\n\n\tif (indexOfSeparator === -1 || indexOfSeparator === 0) {\n\t\tthrow new Error('cannot process avc stream');\n\t}\n\n\tconst buf = streamBuffer.getBuffer();\n\tconst packet = buf.slice(0, indexOfSeparator);\n\tconst rest = buf.slice(indexOfSeparator);\n\n\tawait processStreamBuffer({\n\t\tstreamBuffer: makeTransportStreamPacketBuffer({\n\t\t\toffset: streamBuffer.offset,\n\t\t\tpesHeader: streamBuffer.pesHeader,\n\t\t\t// Replace the regular 0x00000001 with 0x00000002 to avoid confusion with other 0x00000001 (?)\n\t\t\tbuffers: packet,\n\t\t}),\n\t\tprogramId,\n\t\tstructure,\n\t\tsampleCallbacks,\n\t\tlogLevel,\n\t\tonAudioTrack,","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/remotion-dev/remotion/blob/78fe4bb3fdb5a2cd68724393d63cb223db333fa7/packages/media-parser/src/containers/transport-stream/process-video.ts#L38-L74","documentation":"Thrown by the AVC (H.264) packet processing path at process-video.ts:56 when get2ndSubArrayIndex() returns -1 or 0. get2ndSubArrayIndex searches for the second occurrence of the NAL-unit start code [0,0,1,9] (AUD - Access Unit Delimiter); a -1 means only one (or zero) AUD has been buffered, and 0 means the buffer starts exactly on the second AUD with no payload in between. Both indicate the AVC stream cannot be cleanly split into access units.","triggerScenarios":"processVideo computes indexOfSeparator via get2ndSubArrayIndex and throws when it equals -1 or 0. Triggered when the buffered AVC bytes contain fewer than two AUD start codes (incomplete frame), when start codes are corrupted/misaligned, or when an encoder omits AUDs entirely.","commonSituations":"Partial captures; H.264 encoders that do not emit Access Unit Delimiter NAL units (common with some hardware encoders); bit corruption that destroys the 0x00000109 sequence; live streams parsed before enough data has accumulated.","solutions":["Re-encode with AUD insertion: ffmpeg -i in.ts -c:v libx264 -flags +aud -c:a copy out.ts.","Re-mux to MP4 which does not rely on AUD framing: ffmpeg -i in.ts -c copy out.mp4.","Ensure the input is complete before parsing.","Verify with h264_parse or ffmpeg -loglevel debug that AUD NAL units are present."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Re-encode to insert AUD NAL units and/or remux to MP4\nimport {execSync} from 'node:child_process';\nfunction ensureAudNalUnits(src: string): string {\n  const out = src + '.aud.ts';\n  execSync(`ffmpeg -y -i \"${src}\" -c:v libx264 -flags +aud -c:a copy \"${out}\"`);\n  return out;\n}","typeGuard":null,"tryCatchPattern":"try { await parseMedia({src}); }\ncatch (e) {\n  if (e instanceof Error && e.message === 'cannot process avc stream') {\n    // either incomplete or no AUD - re-encode with AUDs or remux to MP4\n    await runFfmpeg(['-i', src, '-c:v', 'libx264', '-flags', '+aud', '-c:a', 'copy', out]);\n    await parseMedia({src: out});\n  } else throw e;\n}","preventionTips":["Re-encode H.264 streams with AUD insertion (ffmpeg -flags +aud).","Remux to MP4 to avoid reliance on AUD framing when source must be preserved.","Ensure inputs are complete before parsing."],"tags":["media-parser","transport-stream","mpegts","video","h264","avc","nal-unit"],"backgroundTag":null,"analyzedSha":"78fe4bb3fdb5a2cd68724393d63cb223db333fa7","analyzedAt":"2026-08-12T17:18:50.444Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}