Skip to content
Source
Sign inSign up
Open History to see the last commit

videoFrameFit.ts

14 lines534 Bytes

1interface Size {
2 readonly width: number;
3 readonly height: number;
4}
5​
6/** Largest frame with the video's aspect ratio that fits the bounds and the inline width cap. */
7export function fitVideoFrame(video: Size, bounds: Size, maxWidth: number): Size | null {
8 if (video.width <= 0 || video.height <= 0 || bounds.width <= 0 || bounds.height <= 0) {
9 return null;
10 }
11 const ratio = video.width / video.height;
12 const width = Math.min(bounds.width, maxWidth, bounds.height * ratio);
13 return { width, height: width / ratio };