{"record":{"id":"5af548f94f1a8f43","repo":"remotion-dev/remotion","slug":"expected-0-bytes-bytesremaining-5af548","errorCode":null,"errorMessage":"expected 0 bytes ${bytesRemaining}","messagePattern":"expected 0 bytes (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/media-parser/src/containers/iso-base-media/tfhd.ts","lineNumber":53,"sourceCode":"\t\t? iterator.getUint32()\n\t\t: 0;\n\n\tconst defaultSampleDurationPresent = flags & 0x08;\n\tconst defaultSampleDuration = defaultSampleDurationPresent\n\t\t? iterator.getUint32()\n\t\t: 0;\n\n\tconst defaultSampleSizePresent = flags & 0x10;\n\tconst defaultSampleSize = defaultSampleSizePresent ? iterator.getUint32() : 0;\n\n\tconst defaultSampleFlagsPresent = flags & 0x20;\n\tconst defaultSampleFlags = defaultSampleFlagsPresent\n\t\t? iterator.getUint32()\n\t\t: 0;\n\n\tconst bytesRemaining = size - (iterator.counter.getOffset() - offset);\n\tif (bytesRemaining !== 0) {\n\t\tthrow new Error('expected 0 bytes ' + bytesRemaining);\n\t}\n\n\treturn {\n\t\ttype: 'tfhd-box',\n\t\tversion,\n\t\ttrackId,\n\t\tbaseDataOffset,\n\t\tbaseSampleDescriptionIndex,\n\t\tdefaultSampleDuration,\n\t\tdefaultSampleSize,\n\t\tdefaultSampleFlags,\n\t};\n};\n","sourceCodeStart":35,"sourceCodeEnd":67,"githubUrl":"https://github.com/remotion-dev/remotion/blob/78fe4bb3fdb5a2cd68724393d63cb223db333fa7/packages/media-parser/src/containers/iso-base-media/tfhd.ts#L35-L67","documentation":"After parsing the TFHD (Track Fragment Header) box fields conditionally based on flags (baseDataOffset, sample description index, default durations/sizes/flags), the parser asserts zero bytes remaining. Non-zero bytesRemaining means an unrecognized flag bit indicated extra fields the parser did not consume, or the box has trailing/padding data.","triggerScenarios":"The tfhd flags field has a bit set that the parser does not handle, leaving bytes unconsumed; or the declared size includes data the parser does not expect.","commonSituations":"Fragmented MP4 from DASH/HLS with proprietary or newer-spec tfhd flag bits; corrupt traf boxes; or files from non-conformant live packagers.","solutions":["Dump the tfhd box: `mp4dump input.mp4 | grep -A5 tfhd` to see the flags and size.","Re-mux: `ffmpeg -i input.mp4 -c copy -f mp4 -movflags +faststart remuxed.mp4`.","For DASH/HLS, re-fetch the offending segment.","Report upstream if a standard tfhd flag bit is genuinely unsupported."],"exampleFix":"// before: tfhd with unsupported flag bit leaves trailing bytes\nffmpeg -i segment.m4s -c copy remuxed.mp4\n// after: tfhd bytesRemaining === 0","handlingStrategy":"try-catch","validationCode":"// Verify tfhd flag bits are all handled before parsing\n// Known handled flags: 0x01 (baseDataOffset), 0x02 (sampleDescIndex), 0x08 (defaultDuration), 0x10 (defaultSize), 0x20 (defaultFlags)\nconst HANDLED_TFHD_FLAGS = 0x01 | 0x02 | 0x08 | 0x10 | 0x20;\nfunction hasUnhandledTfhdFlags(flags: number): boolean {\n  return (flags & ~HANDLED_TFHD_FLAGS) !== 0;\n}","typeGuard":null,"tryCatchPattern":"try {\n  await parseMedia({src, fields: {dimensions: true}});\n} catch (err) {\n  if (err instanceof Error && err.message.startsWith('expected 0 bytes') && /* tfhd context */) {\n    // tfhd has unhandled flag bit or trailing bytes; re-mux\n  } else throw err;\n}","preventionTips":["Re-mux fMP4 with ffmpeg to normalize tfhd flags.","Re-fetch suspicious HLS/DASH segments.","Inspect tfhd flags with mp4dump for non-standard packagers."],"tags":["media-parser","isobmff","tfhd-box","fragmented-mp4","corrupt-file","mp4"],"backgroundTag":null,"analyzedSha":"78fe4bb3fdb5a2cd68724393d63cb223db333fa7","analyzedAt":"2026-08-12T17:18:50.444Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}