diff options
author | Chocobozzz <me@florianbigard.com> | 2021-11-10 11:04:00 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-11-10 11:04:00 +0100 |
commit | 67eeec8b955339120ff5d3c8286fdf0715e6270c (patch) | |
tree | ec28e8c218ed4e80f5f1f86f59fe2acb360950a9 /shared | |
parent | 93904032506dd222404d9be60fd2e41763554665 (diff) | |
download | PeerTube-67eeec8b955339120ff5d3c8286fdf0715e6270c.tar.gz PeerTube-67eeec8b955339120ff5d3c8286fdf0715e6270c.tar.zst PeerTube-67eeec8b955339120ff5d3c8286fdf0715e6270c.zip |
Add minimum bitrate limit
Diffstat (limited to 'shared')
-rw-r--r-- | shared/core-utils/videos/bitrate.ts | 26 |
1 files changed, 25 insertions, 1 deletions
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 } | |||
4 | 4 | ||
5 | // https://bitmovin.com/video-bitrate-streaming-hls-dash/ | 5 | // https://bitmovin.com/video-bitrate-streaming-hls-dash/ |
6 | 6 | ||
7 | const minLimitBitPerPixel: BitPerPixel = { | ||
8 | [VideoResolution.H_NOVIDEO]: 0, | ||
9 | [VideoResolution.H_144P]: 0.02, | ||
10 | [VideoResolution.H_240P]: 0.02, | ||
11 | [VideoResolution.H_360P]: 0.02, | ||
12 | [VideoResolution.H_480P]: 0.02, | ||
13 | [VideoResolution.H_720P]: 0.02, | ||
14 | [VideoResolution.H_1080P]: 0.02, | ||
15 | [VideoResolution.H_1440P]: 0.02, | ||
16 | [VideoResolution.H_4K]: 0.02 | ||
17 | } | ||
18 | |||
7 | const averageBitPerPixel: BitPerPixel = { | 19 | const averageBitPerPixel: BitPerPixel = { |
8 | [VideoResolution.H_NOVIDEO]: 0, | 20 | [VideoResolution.H_NOVIDEO]: 0, |
9 | [VideoResolution.H_144P]: 0.19, | 21 | [VideoResolution.H_144P]: 0.19, |
@@ -50,11 +62,23 @@ function getMaxBitrate (options: { | |||
50 | return targetBitrate | 62 | return targetBitrate |
51 | } | 63 | } |
52 | 64 | ||
65 | function getMinLimitBitrate (options: { | ||
66 | resolution: VideoResolution | ||
67 | ratio: number | ||
68 | fps: number | ||
69 | }) { | ||
70 | const minLimitBitrate = calculateBitrate({ ...options, bitPerPixel: minLimitBitPerPixel }) | ||
71 | if (!minLimitBitrate) return 10 * 1000 | ||
72 | |||
73 | return minLimitBitrate | ||
74 | } | ||
75 | |||
53 | // --------------------------------------------------------------------------- | 76 | // --------------------------------------------------------------------------- |
54 | 77 | ||
55 | export { | 78 | export { |
56 | getAverageBitrate, | 79 | getAverageBitrate, |
57 | getMaxBitrate | 80 | getMaxBitrate, |
81 | getMinLimitBitrate | ||
58 | } | 82 | } |
59 | 83 | ||
60 | // --------------------------------------------------------------------------- | 84 | // --------------------------------------------------------------------------- |