X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=shared%2Fcore-utils%2Fvideos%2Fbitrate.ts;h=6be0278267a6f88edbcc59c3ba57679ff3b460f4;hb=fa1f8915dea4bc4ffc69ca98987a06cac01e9c46;hp=18c6e2f6cef4ef6c45de5b97cf3b0399959317ad;hpb=8dd754c76735417305c4b68e2ada6f623e9d7650;p=github%2FChocobozzz%2FPeerTube.git diff --git a/shared/core-utils/videos/bitrate.ts b/shared/core-utils/videos/bitrate.ts index 18c6e2f6c..6be027826 100644 --- a/shared/core-utils/videos/bitrate.ts +++ b/shared/core-utils/videos/bitrate.ts @@ -1,9 +1,21 @@ -import { VideoResolution } from "@shared/models" +import { VideoResolution } from '@shared/models' 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, @@ -28,7 +40,7 @@ const maxBitPerPixel: BitPerPixel = { [VideoResolution.H_4K]: 0.14 } -function getAverageBitrate (options: { +function getAverageTheoreticalBitrate (options: { resolution: VideoResolution ratio: number fps: number @@ -39,7 +51,7 @@ function getAverageBitrate (options: { return targetBitrate } -function getMaxBitrate (options: { +function getMaxTheoreticalBitrate (options: { resolution: VideoResolution ratio: number fps: number @@ -50,11 +62,23 @@ function getMaxBitrate (options: { return targetBitrate } +function getMinTheoreticalBitrate (options: { + resolution: VideoResolution + ratio: number + fps: number +}) { + const minLimitBitrate = calculateBitrate({ ...options, bitPerPixel: minLimitBitPerPixel }) + if (!minLimitBitrate) return 10 * 1000 + + return minLimitBitrate +} + // --------------------------------------------------------------------------- export { - getAverageBitrate, - getMaxBitrate + getAverageTheoreticalBitrate, + getMaxTheoreticalBitrate, + getMinTheoreticalBitrate } // ---------------------------------------------------------------------------