aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/models/videos/video-resolution.enum.ts
diff options
context:
space:
mode:
Diffstat (limited to 'shared/models/videos/video-resolution.enum.ts')
-rw-r--r--shared/models/videos/video-resolution.enum.ts45
1 files changed, 30 insertions, 15 deletions
diff --git a/shared/models/videos/video-resolution.enum.ts b/shared/models/videos/video-resolution.enum.ts
index e40e5b58b..2eee03843 100644
--- a/shared/models/videos/video-resolution.enum.ts
+++ b/shared/models/videos/video-resolution.enum.ts
@@ -9,13 +9,13 @@ export enum VideoResolution {
9} 9}
10 10
11/** 11/**
12 * Bitrate targets for different resolutions and frame rates, in bytes per second. 12 * Bitrate targets for different resolutions, at VideoTranscodingFPS.AVERAGE.
13 *
13 * Sources for individual quality levels: 14 * Sources for individual quality levels:
14 * Google Live Encoder: https://support.google.com/youtube/answer/2853702?hl=en 15 * Google Live Encoder: https://support.google.com/youtube/answer/2853702?hl=en
15 * YouTube Video Info (tested with random music video): https://www.h3xed.com/blogmedia/youtube-info.php 16 * YouTube Video Info (tested with random music video): https://www.h3xed.com/blogmedia/youtube-info.php
16 */ 17 */
17export function getTargetBitrate (resolution: VideoResolution, fps: number, 18function getBaseBitrate (resolution: VideoResolution) {
18 fpsTranscodingConstants: VideoTranscodingFPS) {
19 switch (resolution) { 19 switch (resolution) {
20 case VideoResolution.H_240P: 20 case VideoResolution.H_240P:
21 // quality according to Google Live Encoder: 300 - 700 Kbps 21 // quality according to Google Live Encoder: 300 - 700 Kbps
@@ -30,23 +30,11 @@ export function getTargetBitrate (resolution: VideoResolution, fps: number,
30 // Quality according to YouTube Video Info: 879 Kbps 30 // Quality according to YouTube Video Info: 879 Kbps
31 return 900 * 1000 31 return 900 * 1000
32 case VideoResolution.H_720P: 32 case VideoResolution.H_720P:
33 if (fps === fpsTranscodingConstants.MAX) {
34 // quality according to Google Live Encoder: 2,250 - 6,000 Kbps
35 // Quality according to YouTube Video Info: 2634 Kbps
36 return 2600 * 1000
37 }
38
39 // quality according to Google Live Encoder: 1,500 - 4,000 Kbps 33 // quality according to Google Live Encoder: 1,500 - 4,000 Kbps
40 // Quality according to YouTube Video Info: 1752 Kbps 34 // Quality according to YouTube Video Info: 1752 Kbps
41 return 1750 * 1000 35 return 1750 * 1000
42 case VideoResolution.H_1080P: // fallthrough 36 case VideoResolution.H_1080P: // fallthrough
43 default: 37 default:
44 if (fps === fpsTranscodingConstants.MAX) {
45 // quality according to Google Live Encoder: 3000 - 6000 Kbps
46 // Quality according to YouTube Video Info: 4387 Kbps
47 return 4400 * 1000
48 }
49
50 // quality according to Google Live Encoder: 3000 - 6000 Kbps 38 // quality according to Google Live Encoder: 3000 - 6000 Kbps
51 // Quality according to YouTube Video Info: 3277 Kbps 39 // Quality according to YouTube Video Info: 3277 Kbps
52 return 3300 * 1000 40 return 3300 * 1000
@@ -54,6 +42,33 @@ export function getTargetBitrate (resolution: VideoResolution, fps: number,
54} 42}
55 43
56/** 44/**
45 * Calculate the target bitrate based on video resolution and FPS.
46 *
47 * The calculation is based on two values:
48 * Bitrate at VideoTranscodingFPS.AVERAGE is always the same as
49 * getBaseBitrate(). Bitrate at VideoTranscodingFPS.MAX is always
50 * getBaseBitrate() * 1.4. All other values are calculated linearly
51 * between these two points.
52 */
53export function getTargetBitrate (resolution: VideoResolution, fps: number,
54 fpsTranscodingConstants: VideoTranscodingFPS) {
55 const baseBitrate = getBaseBitrate(resolution)
56 // The maximum bitrate, used when fps === VideoTranscodingFPS.MAX
57 // Based on numbers from Youtube, 60 fps bitrate divided by 30 fps bitrate:
58 // 720p: 2600 / 1750 = 1.49
59 // 1080p: 4400 / 3300 = 1.33
60 const maxBitrate = baseBitrate * 1.4
61 const maxBitrateDifference = maxBitrate - baseBitrate
62 const maxFpsDifference = fpsTranscodingConstants.MAX - fpsTranscodingConstants.AVERAGE
63 // For 1080p video with default settings, this results in the following formula:
64 // 3300 + (x - 30) * (1320/30)
65 // Example outputs:
66 // 1080p10: 2420 kbps, 1080p30: 3300 kbps, 1080p60: 4620 kbps
67 // 720p10: 1283 kbps, 720p30: 1750 kbps, 720p60: 2450 kbps
68 return baseBitrate + (fps - fpsTranscodingConstants.AVERAGE) * (maxBitrateDifference / maxFpsDifference)
69}
70
71/**
57 * The maximum bitrate we expect to see on a transcoded video in bytes per second. 72 * The maximum bitrate we expect to see on a transcoded video in bytes per second.
58 */ 73 */
59export function getMaxBitrate (resolution: VideoResolution, fps: number, 74export function getMaxBitrate (resolution: VideoResolution, fps: number,