{"record":{"id":"dc07cc45c26477bd","repo":"remotion-dev/remotion","slug":"video-frame-durations-must-be-non-negative","errorCode":null,"errorMessage":"Video frame durations must be non-negative.","messagePattern":"Video frame durations must be non-negative\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/video-matting/src/video-timing.ts","lineNumber":71,"sourceCode":"\treturn {\n\t\ttimestamp: visibleStart - videoStartTimestamp,\n\t\tduration: visibleEnd - visibleStart,\n\t};\n};\n\nexport const getVideoProcessingProgress = ({\n\ttimestamp,\n\tduration,\n\tfirstVideoTimestamp,\n\tdurationInSeconds,\n}: {\n\ttimestamp: number;\n\tduration: number;\n\tfirstVideoTimestamp: number;\n\tdurationInSeconds: number;\n}): {processedDurationInSeconds: number; progress: number} => {\n\tif (!Number.isFinite(duration) || duration < 0) {\n\t\tthrow new TypeError('Video frame durations must be non-negative.');\n\t}\n\n\tif (!Number.isFinite(durationInSeconds) || durationInSeconds < 0) {\n\t\tthrow new TypeError('The video duration must be non-negative.');\n\t}\n\n\tconst rebasedTimestamp = rebaseVideoTimestamp({\n\t\ttimestamp,\n\t\tfirstVideoTimestamp,\n\t});\n\tconst processedDurationInSeconds = Math.min(\n\t\tdurationInSeconds,\n\t\tMath.max(0, rebasedTimestamp + duration),\n\t);\n\n\treturn {\n\t\tprocessedDurationInSeconds,\n\t\tprogress:","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/remotion-dev/remotion/blob/b2f4e34732f3c6c222ea029413e22dc402218cd7/packages/video-matting/src/video-timing.ts#L53-L89","documentation":"getVideoProcessingProgress accumulates processed frame durations to compute progress against the total video duration. Each frame duration must be a finite number >= 0; NaN, Infinity or negative values throw this TypeError, since summing them would corrupt the progress metric.","triggerScenarios":"Calling getVideoProcessingProgress with a frame duration that is NaN, Infinity, or negative — typically from unsorted frames (next.ts - ts < 0), failed metadata parse, or Infinity placeholders.","commonSituations":"Progress reporting over frames decoded out of order, live/unbounded durations passed in, or duration fields left undefined and coerced to NaN by arithmetic.","solutions":["Sanitize frame durations: Math.max(0, finite value) before accumulating","Sort frames by timestamp so inter-frame durations are non-negative","Ensure total durationInSeconds is a real finite value before computing progress","Skip invalid frames in progress accounting instead of passing them through"],"exampleFix":"// before\nconst p = getVideoProcessingProgress({timestamp, duration: frame.dur, firstVideoTimestamp, durationInSeconds});\n// after\nconst dur = Number.isFinite(frame.dur) ? Math.max(0, frame.dur) : 0;\nconst p = getVideoProcessingProgress({timestamp, duration: dur, firstVideoTimestamp, durationInSeconds});","handlingStrategy":"validation","validationCode":"const safeFrameDuration = (d: number) => (Number.isFinite(d) && d >= 0 ? d : 0);\nconst total = frames.reduce((acc, f) => acc + safeFrameDuration(f.dur), 0);","typeGuard":"const isNonNegativeFinite = (d: unknown): d is number =>\n  typeof d === 'number' && Number.isFinite(d) && d >= 0;","tryCatchPattern":"try {\n  const {progress} = getVideoProcessingProgress({timestamp, duration, firstVideoTimestamp, durationInSeconds});\n} catch (err) {\n  if (err instanceof TypeError && err.message.includes('durations must be non-negative')) {\n    console.warn('Invalid frame duration; progress may be inaccurate');\n    return {processedDurationInSeconds: 0, progress: 0};\n  }\n  throw err;\n}","preventionTips":["Sanitize each frame duration with Math.max(0, d) before accumulation","Keep frames sorted so computed durations are non-negative","Validate total durationInSeconds is finite and >= 0 before progress reporting","Track progress incrementally so one bad frame doesn't zero out the metric"],"tags":["video-matting","duration","progress","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-14T00:17:10.932Z"}