summaryrefslogtreecommitdiff
path: root/apps/web/src/lib/project/fps.ts
blob: f031d348f8f874b7d897fb776a1dcf7842787d53 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import type { MediaAsset } from "@/lib/media/types";

type MediaAssetFpsInput = Pick<MediaAsset, "type" | "fps">;

export function getHighestImportedVideoFps({
	mediaAssets,
}: {
	mediaAssets: MediaAssetFpsInput[];
}): number | null {
	let highestFps: number | null = null;

	for (const asset of mediaAssets) {
		const fps = asset.fps ?? Number.NaN;
		if (asset.type !== "video") continue;
		if (!Number.isFinite(fps) || fps <= 0) continue;

		highestFps = highestFps === null ? fps : Math.max(highestFps, fps);
	}

	return highestFps;
}

export function getRaisedProjectFpsForImportedMedia({
	currentFps,
	importedAssets,
}: {
	currentFps: number;
	importedAssets: MediaAssetFpsInput[];
}): number | null {
	const highestImportedVideoFps = getHighestImportedVideoFps({
		mediaAssets: importedAssets,
	});

	if (highestImportedVideoFps === null || highestImportedVideoFps <= currentFps) {
		return null;
	}

	return highestImportedVideoFps;
}