{"record":{"id":"1c91838e05ad4941","repo":"remotion-dev/remotion","slug":"expected-0-bytes-bytesremaining-1c9183","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/tfdt.ts","lineNumber":28,"sourceCode":"export const parseTfdt = ({\n\titerator,\n\tsize,\n\toffset,\n}: {\n\titerator: BufferIterator;\n\tsize: number;\n\toffset: number;\n}): TfdtBox => {\n\tconst version = iterator.getUint8();\n\titerator.discard(3);\n\t// Flags, discard them\n\tconst num =\n\t\tversion === 0 ? iterator.getUint32() : Number(iterator.getUint64());\n\n\tconst bytesRemaining = size - (iterator.counter.getOffset() - offset);\n\n\tif (bytesRemaining !== 0) {\n\t\tthrow new Error('expected 0 bytes ' + bytesRemaining);\n\t}\n\n\treturn {\n\t\ttype: 'tfdt-box',\n\t\tversion,\n\t\tbaseMediaDecodeTime: num,\n\t\toffset,\n\t};\n};\n","sourceCodeStart":10,"sourceCodeEnd":38,"githubUrl":"https://github.com/remotion-dev/remotion/blob/78fe4bb3fdb5a2cd68724393d63cb223db333fa7/packages/media-parser/src/containers/iso-base-media/tfdt.ts#L10-L38","documentation":"After parsing the TFDT (Track Fragment Decode Time) box — version byte, flags, and a 32-bit or 64-bit baseMediaDecodeTime — the parser asserts zero bytes remaining. Any leftover bytes indicate an unexpected flag combination, a parser that under-read, or a malformed box with trailing data.","triggerScenarios":"bytesRemaining = size - (currentOffset - offset) is non-zero after reading version/flags/num. Happens when the declared box size is larger than the parsed content, or when an unrecognized flag should have caused extra fields to be read.","commonSituations":"Corrupt or non-standard tfdt boxes in fragmented MP4 (fMP4) from DASH/HLS sources, or files from encoders that add proprietary trailing data.","solutions":["Inspect the tfdt box with `mp4dump input.mp4` to see declared size vs parsed content.","Re-mux the fMP4: `ffmpeg -i input.mp4 -c copy -f mp4 -movflags +faststart remuxed.mp4`.","If the source is a DASH/HLS segment, re-fetch the segment.","For live fMP4 streams, ensure segments are not being parsed mid-append."],"exampleFix":"// before: tfdt box has trailing 4 bytes\nffmpeg -i segment.m4s -c copy -f mp4 remuxed.mp4\n// after: tfdt bytesRemaining === 0","handlingStrategy":"try-catch","validationCode":"// Verify tfdt box has no trailing bytes with mp4dump before parsing\n// tfdt content is 1 (version) + 3 (flags) + 4 or 8 (baseMediaDecodeTime) = 8 or 12 bytes\nfunction expectedTfdtSize(version: number): number {\n  return 8 + 4 + (version === 0 ? 4 : 8); // header + version/flags + field\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') && /* tfdt context */) {\n    // fMP4 tfdt has trailing bytes; re-mux or re-fetch segment\n  } else throw err;\n}","preventionTips":["Re-fetch DASH/HLS segments that fail integrity checks.","Re-mux fMP4 with ffmpeg to normalize tfdt boxes.","Confirm segments are fully written before parsing live streams."],"tags":["media-parser","isobmff","tfdt-box","fragmented-mp4","corrupt-file","mp4"],"backgroundTag":null,"analyzedSha":"78fe4bb3fdb5a2cd68724393d63cb223db333fa7","analyzedAt":"2026-08-12T17:18:50.444Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}