X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=shared%2Fcore-utils%2Fvideos%2Fbitrate.ts;h=c1891188f1581dc9fbc4da78b3032695a2012a7a;hb=66175ae8b4b9307105fb3b3f9a77800e5d35518f;hp=a6712f8a4a8abafb333fbe17ed9d6f694af5c8d9;hpb=10ef089102f2225c5ec3ed426bc612e4f2bc8655;p=github%2FChocobozzz%2FPeerTube.git diff --git a/shared/core-utils/videos/bitrate.ts b/shared/core-utils/videos/bitrate.ts index a6712f8a4..c1891188f 100644 --- a/shared/core-utils/videos/bitrate.ts +++ b/shared/core-utils/videos/bitrate.ts @@ -4,8 +4,21 @@ 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, [VideoResolution.H_240P]: 0.17, [VideoResolution.H_360P]: 0.15, [VideoResolution.H_480P]: 0.12, @@ -17,6 +30,7 @@ const averageBitPerPixel: BitPerPixel = { const maxBitPerPixel: BitPerPixel = { [VideoResolution.H_NOVIDEO]: 0, + [VideoResolution.H_144P]: 0.32, [VideoResolution.H_240P]: 0.29, [VideoResolution.H_360P]: 0.26, [VideoResolution.H_480P]: 0.22, @@ -48,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 } // --------------------------------------------------------------------------- @@ -73,6 +99,7 @@ function calculateBitrate (options: { VideoResolution.H_480P, VideoResolution.H_360P, VideoResolution.H_240P, + VideoResolution.H_144P, VideoResolution.H_NOVIDEO ]