remotion-dev/remotion · error · TypeError
The video duration must be non-negative.
Error message
The video duration must be non-negative.
What it means
getVideoProcessingProgress() validates the total video duration (durationInSeconds) before computing rebased timestamps and progress. A non-finite value (NaN, Infinity) or a negative number makes progress calculation meaningless, so the library throws a TypeError instead of returning bogus data.
Source
Thrown at packages/video-matting/src/video-timing.ts:75
};
export const getVideoProcessingProgress = ({
timestamp,
duration,
firstVideoTimestamp,
durationInSeconds,
}: {
timestamp: number;
duration: number;
firstVideoTimestamp: number;
durationInSeconds: number;
}): {processedDurationInSeconds: number; progress: number} => {
if (!Number.isFinite(duration) || duration < 0) {
throw new TypeError('Video frame durations must be non-negative.');
}
if (!Number.isFinite(durationInSeconds) || durationInSeconds < 0) {
throw new TypeError('The video duration must be non-negative.');
}
const rebasedTimestamp = rebaseVideoTimestamp({
timestamp,
firstVideoTimestamp,
});
const processedDurationInSeconds = Math.min(
durationInSeconds,
Math.max(0, rebasedTimestamp + duration),
);
return {
processedDurationInSeconds,
progress:
durationInSeconds === 0
? 1
: Math.min(1, processedDurationInSeconds / durationInSeconds),
};View on GitHub (pinned to b2f4e34732)
Solutions
- Ensure durationInSeconds is a finite, non-negative number of seconds before calling
- If duration is unknown, obtain it via metadata probing first instead of passing a placeholder like -1
- Check for NaN from earlier arithmetic (e.g. parsing failures) upstream of the call
Example fix
// before
const progress = getVideoProcessingProgress({durationInSeconds: -1, duration, timestamp});
// after
const durationInSeconds = Math.max(0, metadata.duration); // must be finite and >= 0
const progress = getVideoProcessingProgress({durationInSeconds, duration, timestamp}); Defensive patterns
Strategy: validation
Validate before calling
if (!Number.isFinite(durationInSeconds) || durationInSeconds < 0) throw new Error('durationInSeconds must be a finite, non-negative number'); Type guard
const isValidDuration = (d: unknown): d is number => typeof d === 'number' && Number.isFinite(d) && d >= 0;
Try / catch
try {
const p = getVideoProcessingProgress({durationInSeconds, duration, timestamp});
} catch (e) {
if (e instanceof TypeError && e.message.includes('non-negative')) {
durationInSeconds = await probeDuration(source);
} else throw e;
} Prevention
- Probe duration from metadata instead of using placeholders like -1
- Check for NaN after any arithmetic that derives durations
- Validate all numeric inputs once at the boundary of your app
When it happens
Trigger: Calling getVideoProcessingProgress() with durationInSeconds of a negative number, NaN, or Infinity — e.g. duration parsed from metadata that failed, an uninitialized variable, or a wrong unit sign flip.
Common situations: Metadata probing returning -1 for unknown duration; dividing/deriving durations with NaN inputs; passing a timestamp variable by mistake in place of the total duration.
Related errors
- You have passed a volume of type ${typeof props.volume} to y
- You have passed a volume below 0 to your <${component} /> co
- You have passed a playbackRate of type ${typeof props.playba
- You have passed a playbackRate of ${props.playbackRate} to y
- 'preservePitch' must be a boolean or undefined but got '${ty
AI-assisted analysis of remotion-dev/remotion@b2f4e34732 (2026-09-09).
Data as JSON: /api/errors/269d1fb1d9742871.
Report an issue: GitHub.