{"record":{"id":"a5e1ad517127dc25","repo":"remotion-dev/remotion","slug":"video-timestamps-must-be-finite-numbers","errorCode":null,"errorMessage":"Video timestamps must be finite numbers.","messagePattern":"Video timestamps must be finite numbers\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/video-matting/src/video-timing.ts","lineNumber":9,"sourceCode":"export const rebaseVideoTimestamp = ({\n\ttimestamp,\n\tfirstVideoTimestamp,\n}: {\n\ttimestamp: number;\n\tfirstVideoTimestamp: number;\n}): number => {\n\tif (!Number.isFinite(timestamp) || !Number.isFinite(firstVideoTimestamp)) {\n\t\tthrow new TypeError('Video timestamps must be finite numbers.');\n\t}\n\n\tconst rebased = timestamp - firstVideoTimestamp;\n\tif (rebased < -Number.EPSILON * 16) {\n\t\tthrow new Error('Video frames must be in presentation order.');\n\t}\n\n\treturn Math.max(0, rebased);\n};\n\nexport const getClippedVideoFrameTiming = ({\n\ttimestamp,\n\tduration,\n\tvideoStartTimestamp,\n\tvideoEndTimestamp,\n}: {\n\ttimestamp: number;\n\tduration: number;","sourceCodeStart":1,"sourceCodeEnd":27,"githubUrl":"https://github.com/remotion-dev/remotion/blob/b2f4e34732f3c6c222ea029413e22dc402218cd7/packages/video-matting/src/video-timing.ts#L1-L27","documentation":"rebaseVideoTimestamp shifts a frame timestamp relative to the first video timestamp and requires both to be finite numbers; NaN, Infinity or -Infinity triggers this TypeError. It protects the presentation-order check and downstream timing math from undefined behavior caused by non-finite values.","triggerScenarios":"Calling rebaseVideoTimestamp (directly or via rebasedTimestamp) with timestamp or firstVideoTimestamp being NaN/Infinity — typically from a failed media metadata parse, a missing duration field, or a divide-by-zero producing NaN upstream.","commonSituations":"Demuxer emitting NaN timestamps for unparseable packets, dividing by fps=0 to compute timestamps, or uninitialized firstVideoTimestamp when metadata hasn't loaded yet.","solutions":["Verify the demuxer/decoder supplies finite timestamps; log frames before rebasing","Ensure firstVideoTimestamp is initialized from a real frame before processing subsequent ones","Guard the caller: skip frames with non-finite timestamps instead of passing them through","Fix fps/duration math so no division by zero yields NaN"],"exampleFix":"// before\nconst ts = rebasedTimestamp({timestamp: frame.ts, firstVideoTimestamp});\n// after\nif (!Number.isFinite(frame.ts) || !Number.isFinite(firstVideoTimestamp)) return; // skip bad frame\nconst ts = rebasedTimestamp({timestamp: frame.ts, firstVideoTimestamp});","handlingStrategy":"validation","validationCode":"const canRebase = (ts: number, first: number) =>\n  Number.isFinite(ts) && Number.isFinite(first);\nif (!canRebase(frame.ts, firstVideoTimestamp)) return null;","typeGuard":"const isFiniteTimestamp = (t: unknown): t is number =>\n  typeof t === 'number' && Number.isFinite(t);","tryCatchPattern":"try {\n  const ts = rebasedTimestamp({timestamp: frame.ts, firstVideoTimestamp});\n} catch (err) {\n  if (err instanceof TypeError && err.message.includes('finite')) {\n    console.warn('Skipping frame with non-finite timestamp');\n    return null;\n  }\n  throw err;\n}","preventionTips":["Initialize firstVideoTimestamp from the first decoded frame, never leave it undefined","Check decoder output for NaN pts before processing","Avoid division by zero when computing timestamps from fps","Skip rather than process frames with non-finite timestamps"],"tags":["video-matting","timestamps","validation","typescript"],"backgroundTag":"invalid-argument-value","analyzedSha":"b2f4e34732f3c6c222ea029413e22dc402218cd7","analyzedAt":"2026-09-09T13:27:51.281Z","contentChangedAt":"2026-09-09T13:27:51.281Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}