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

  1. Ensure durationInSeconds is a finite, non-negative number of seconds before calling
  2. If duration is unknown, obtain it via metadata probing first instead of passing a placeholder like -1
  3. 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

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


AI-assisted analysis of remotion-dev/remotion@b2f4e34732 (2026-09-09). Data as JSON: /api/errors/269d1fb1d9742871. Report an issue: GitHub.