From 67eeec8b955339120ff5d3c8286fdf0715e6270c Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 10 Nov 2021 11:04:00 +0100 Subject: Add minimum bitrate limit --- shared/core-utils/videos/bitrate.ts | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'shared/core-utils/videos') diff --git a/shared/core-utils/videos/bitrate.ts b/shared/core-utils/videos/bitrate.ts index 18c6e2f6c..c1891188f 100644 --- a/shared/core-utils/videos/bitrate.ts +++ b/shared/core-utils/videos/bitrate.ts @@ -4,6 +4,18 @@ type BitPerPixel = { [ id in VideoResolution ]: number } // https://bitmovin.com/video-bitrate-streaming-hls-dash/ +const minLimitBitPerPixel: BitPerPixel = { + [VideoResolution.H_NOVIDEO]: 0, + [VideoResolution.H_144P]: 0.02, + [VideoResolution.H_240P]: 0.02, + [VideoResolution.H_360P]: 0.02, + [VideoResolution.H_480P]: 0.02, + [VideoResolution.H_720P]: 0.02, + [VideoResolution.H_1080P]: 0.02, + [VideoResolution.H_1440P]: 0.02, + [VideoResolution.H_4K]: 0.02 +} + const averageBitPerPixel: BitPerPixel = { [VideoResolution.H_NOVIDEO]: 0, [VideoResolution.H_144P]: 0.19, @@ -50,11 +62,23 @@ function getMaxBitrate (options: { return targetBitrate } +function getMinLimitBitrate (options: { + resolution: VideoResolution + ratio: number + fps: number +}) { + const minLimitBitrate = calculateBitrate({ ...options, bitPerPixel: minLimitBitPerPixel }) + if (!minLimitBitrate) return 10 * 1000 + + return minLimitBitrate +} + // --------------------------------------------------------------------------- export { getAverageBitrate, - getMaxBitrate + getMaxBitrate, + getMinLimitBitrate } // --------------------------------------------------------------------------- -- cgit v1.2.3