{"record":{"id":"09f02749b78565a5","repo":"remotion-dev/remotion","slug":"invalid-sync-byte","errorCode":null,"errorMessage":"Invalid sync byte","messagePattern":"Invalid sync byte","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/media-parser/src/containers/transport-stream/parse-packet.ts","lineNumber":23,"sourceCode":"import {parsePat, parseSdt} from './parse-pat';\nimport {parsePes} from './parse-pes';\nimport {parsePmt} from './parse-pmt';\nimport {parseStream} from './parse-stream-packet';\nimport {getProgramForId, getStreamForId} from './traversal';\n\nexport const parsePacket = ({\n\titerator,\n\tstructure,\n\ttransportStream,\n}: {\n\titerator: BufferIterator;\n\tstructure: TransportStreamStructure;\n\ttransportStream: TransportStreamState;\n}): TransportStreamBox | null => {\n\tconst offset = iterator.counter.getOffset();\n\tconst syncByte = iterator.getUint8();\n\tif (syncByte !== 0x47) {\n\t\tthrow new Error('Invalid sync byte');\n\t}\n\n\titerator.startReadingBits();\n\titerator.getBits(1); // transport error indicator\n\tconst payloadUnitStartIndicator = iterator.getBits(1);\n\titerator.getBits(1); // transport priority\n\tconst programId = iterator.getBits(13);\n\titerator.getBits(2); // transport scrambling control\n\tconst adaptationFieldControl1 = iterator.getBits(1); // adaptation field control 1\n\titerator.getBits(1); // adaptation field control 2\n\titerator.getBits(4); // continuity counter\n\titerator.stopReadingBits();\n\tif (adaptationFieldControl1 === 1) {\n\t\titerator.startReadingBits();\n\t\tconst adaptationFieldLength = iterator.getBits(8);\n\t\tconst headerOffset = iterator.counter.getOffset();\n\t\tif (adaptationFieldLength > 0) {\n\t\t\titerator.getBits(1); // discontinuity indicator","sourceCodeStart":5,"sourceCodeEnd":41,"githubUrl":"https://github.com/remotion-dev/remotion/blob/78fe4bb3fdb5a2cd68724393d63cb223db333fa7/packages/media-parser/src/containers/transport-stream/parse-packet.ts#L5-L41","documentation":"Thrown by parsePacket() when the first byte of a 188-byte MPEG-TS packet is not 0x47 (the MPEG-TS sync byte). Every TS packet must start with 0x47; any other value means the data is not aligned to a TS packet boundary or is not MPEG-TS at all.","triggerScenarios":"Misaligned TS data (the reader is not at a packet boundary), corrupt TS, or non-TS data routed to the TS parser. Common after a dropped/corrupt packet throws alignment off by N bytes.","commonSituations":"See trigger scenarios.","solutions":["Resync by scanning forward for the next 0x47 at a 188-byte stride before parsing.","Verify the file is MPEG-TS (ffprobe -show_format).","Re-mux the TS to repair alignment: ffmpeg -i in.ts -c copy out.ts."],"exampleFix":"// before\nconst syncByte = iterator.getUint8();\nif (syncByte !== 0x47) throw new Error('Invalid sync byte');\n\n// after: resync to next 0x47\nwhile (iterator.bytesRemaining() > 0 && iterator.getUint8() !== 0x47) { /* advance */ }","handlingStrategy":"validation","validationCode":"// Verify the 0x47 sync byte at each 188-byte boundary before parsing.\nfunction isTsSyncByte(b: number): boolean {\n  return b === 0x47;\n}\nif (!isTsSyncByte(iterator.getUint8())) {\n  // resync: scan forward for 0x47 at 188-byte stride\n}","typeGuard":"function isTsSyncByte(b: number): boolean {\n  return b === 0x47;\n}","tryCatchPattern":"try {\n  parsePacket({iterator, structure, transportStream});\n} catch (err) {\n  if (err instanceof Error && err.message === 'Invalid sync byte') {\n    // resync to next 0x47 and continue\n  } else throw err;\n}","preventionTips":["Resync on 0x47 at 188-byte stride after any corrupt packet.","Confirm the file is MPEG-TS with ffprobe before parsing.","Capture TS from the start so packet alignment is intact."],"tags":["transport-stream","mpeg-ts","sync-byte","alignment","media-parser"],"backgroundTag":null,"analyzedSha":"78fe4bb3fdb5a2cd68724393d63cb223db333fa7","analyzedAt":"2026-08-12T17:18:50.444Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}