{"record":{"id":"a7cd42cdf2874795","repo":"remotion-dev/remotion","slug":"the-video-frame-duration-must-be-non-negative","errorCode":null,"errorMessage":"The video frame duration must be non-negative.","messagePattern":"The video frame duration must be non-negative\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/video-matting/src/video-timing.ts","lineNumber":36,"sourceCode":"};\n\nexport const getClippedVideoFrameTiming = ({\n\ttimestamp,\n\tduration,\n\tvideoStartTimestamp,\n\tvideoEndTimestamp,\n}: {\n\ttimestamp: number;\n\tduration: number;\n\tvideoStartTimestamp: number;\n\tvideoEndTimestamp: number;\n}): {timestamp: number; duration: number} | null => {\n\tif (!Number.isFinite(timestamp)) {\n\t\tthrow new TypeError('The video frame timestamp must be finite.');\n\t}\n\n\tif (!Number.isFinite(duration) || duration < 0) {\n\t\tthrow new TypeError('The video frame duration must be non-negative.');\n\t}\n\n\tif (\n\t\t!Number.isFinite(videoStartTimestamp) ||\n\t\t!Number.isFinite(videoEndTimestamp) ||\n\t\tvideoEndTimestamp < videoStartTimestamp\n\t) {\n\t\tthrow new TypeError('The video presentation range is invalid.');\n\t}\n\n\tconst visibleStart = Math.max(timestamp, videoStartTimestamp);\n\tconst visibleEnd = Math.min(timestamp + duration, videoEndTimestamp);\n\tif (visibleEnd <= visibleStart) {\n\t\treturn null;\n\t}\n\n\treturn {\n\t\ttimestamp: visibleStart - videoStartTimestamp,","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/remotion-dev/remotion/blob/b2f4e34732f3c6c222ea029413e22dc402218cd7/packages/video-matting/src/video-timing.ts#L18-L54","documentation":"getClippedVideoFrameTiming requires duration to be a finite number >= 0, since it computes the frame's visible span as timestamp + duration. NaN, Infinity or a negative duration throws this TypeError. Zero is allowed (a frame with no visible span simply clips to null).","triggerScenarios":"Passing a negative duration (e.g. end - start computed backwards), NaN from missing metadata, or Infinity from a live-stream style duration placeholder.","commonSituations":"Computing duration as nextTs - ts with unsorted timestamps yielding negatives, a config where frameDuration was left as -1 'auto', or unit confusion (ms vs seconds producing odd values).","solutions":["Compute duration as Math.max(0, end - start) and ensure frames are sorted first","Check that the duration source field is populated and in the expected unit","Replace sentinel values like -1/Infinity with real durations or explicit null handling","Validate inputs before calling and skip frames with invalid durations"],"exampleFix":"// before\nconst dur = next.ts - frame.ts; // can be negative if unsorted\n// after\nconst ordered = [...frames].sort((a, b) => a.ts - b.ts);\nconst dur = Math.max(0, next.ts - frame.ts);","handlingStrategy":"validation","validationCode":"const safeDuration = Math.max(0, Number.isFinite(d) ? d : 0);\nif (d < 0 || !Number.isFinite(d)) console.warn('Invalid frame duration corrected');","typeGuard":"const isNonNegativeFinite = (d: unknown): d is number =>\n  typeof d === 'number' && Number.isFinite(d) && d >= 0;","tryCatchPattern":"try {\n  const timing = getClippedVideoFrameTiming({timestamp, duration, videoStartTimestamp, videoEndTimestamp});\n} catch (err) {\n  if (err instanceof TypeError && err.message.includes('duration must be non-negative')) {\n    return getClippedVideoFrameTiming({timestamp, duration: 0, videoStartTimestamp, videoEndTimestamp});\n  }\n  throw err;\n}","preventionTips":["Sort frames by timestamp before computing inter-frame durations","Clamp durations with Math.max(0, d)","Replace sentinel values (-1, Infinity) with real defaults at config load","Keep duration units consistent (seconds vs milliseconds) across the pipeline"],"tags":["video-matting","duration","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"}