{"record":{"id":"8e114e1b9ad0ccff","repo":"remotion-dev/remotion","slug":"unexpected-pes-packet-start-code-ident-tostring","errorCode":null,"errorMessage":"Unexpected PES packet start code: ${ident.toString(16)}","messagePattern":"Unexpected PES packet start code: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/media-parser/src/containers/transport-stream/parse-pes.ts","lineNumber":20,"sourceCode":"\nexport type PacketPes = {\n\tstreamId: number;\n\tdts: number | null;\n\tpts: number;\n\tpriority: number;\n\toffset: number;\n};\n\nexport const parsePes = ({\n\titerator,\n\toffset,\n}: {\n\titerator: BufferIterator;\n\toffset: number;\n}) => {\n\tconst ident = iterator.getUint24();\n\tif (ident !== 0x000001) {\n\t\tthrow new Error(`Unexpected PES packet start code: ${ident.toString(16)}`);\n\t}\n\n\tconst streamId = iterator.getUint8();\n\titerator.getUint16(); // PES packet length, is most of the time 0, so useless\n\titerator.startReadingBits();\n\tconst markerBits = iterator.getBits(2);\n\tif (markerBits !== 0b10) {\n\t\tthrow new Error(`Invalid marker bits: ${markerBits}`);\n\t}\n\n\tconst scrambled = iterator.getBits(2);\n\tif (scrambled !== 0b00) {\n\t\tthrow new Error(`Only supporting non-scrambled streams`);\n\t}\n\n\tconst priority = iterator.getBits(1);\n\titerator.getBits(1); // data alignment indicator\n\titerator.getBits(1); // copy right","sourceCodeStart":2,"sourceCodeEnd":38,"githubUrl":"https://github.com/remotion-dev/remotion/blob/78fe4bb3fdb5a2cd68724393d63cb223db333fa7/packages/media-parser/src/containers/transport-stream/parse-pes.ts#L2-L38","documentation":"Thrown by parsePes at parse-pes.ts:20 when the first three bytes of a PES packet (the 'packet_start_code_prefix') are not 0x000001. ISO/IEC 13818-1 mandates every PES packet begin with this 24-bit prefix; any other value means the iterator is not aligned on a PES boundary.","triggerScenarios":"parsePes calls iterator.getUint24() and compares to 0x000001; mismatch throws. Triggered when the wrong PID is routed to PES parsing, when a PES payload is fed instead of the header, or when transport-stream buffering has desynchronized the byte cursor.","commonSituations":"Truncated or partially written .ts files; bit-for-bit corruption of the start code; an internal library bug where discardRestOfPacket left the iterator at the wrong offset; switching audio/video PIDs in a multi-program transport stream.","solutions":["Re-mux with ffmpeg -i in.ts -c copy out.ts to rebuild PES framing.","If you control the source, ensure the muxer emits the standard 0x000001 start code prefix.","Validate the file with ffprobe before parsing; if ffprobe also fails, the file is damaged.","Report a bug to @remotion/media-parser if ffprobe parses the file cleanly but Remotion does not."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { await parseMedia({src: tsUrl}); }\ncatch (e) {\n  if (e instanceof Error && e.message.startsWith('Unexpected PES packet start code')) {\n    // PES framing is broken - re-mux and retry\n    await runFfmpeg(['-i', tsUrl, '-c', 'copy', tsUrl + '.remux.ts']);\n    await parseMedia({src: tsUrl + '.remux.ts'});\n  } else throw e;\n}","preventionTips":["Re-mux transport streams with ffmpeg before parsing to normalize PES framing.","Validate with ffprobe -show_packets that PES start codes are present.","File a bug if a ffprobe-clean file fails here."],"tags":["media-parser","transport-stream","mpegts","pes","validation"],"backgroundTag":null,"analyzedSha":"78fe4bb3fdb5a2cd68724393d63cb223db333fa7","analyzedAt":"2026-08-12T17:18:50.444Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}