aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--shared/models/videos/video-resolution.enum.ts37
1 files changed, 22 insertions, 15 deletions
diff --git a/shared/models/videos/video-resolution.enum.ts b/shared/models/videos/video-resolution.enum.ts
index e40e5b58b..13c0fe9a7 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, 18export function 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,25 @@ 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 */
47export function getTargetBitrate (resolution: VideoResolution, fps: number,
48 fpsTranscodingConstants: VideoTranscodingFPS) {
49 const baseBitrate = getBaseBitrate(resolution)
50 // The maximum bitrate, used when fps === VideoTranscodingFPS.MAX
51 // Based on numbers from Youtube, 60 fps bitrate divided by 30 fps bitrate:
52 // 2600 / 1750 = 1.48571428571
53 // 4400 / 3300 = 1.33333333333
54 const maxBitrate = baseBitrate * 1.4
55 const maxBitrateDifference = maxBitrate - baseBitrate
56 const maxFpsDifference = fpsTranscodingConstants.MAX - fpsTranscodingConstants.AVERAGE
57 // For 1080p video with default settings, this results in the following formula:
58 // 3300 + (x - 30) * (1320/30)
59 // Example outputs: 1080p30: 3300 kbps, 1080p60: 4620 kbps, 720p30: 1750, 720p60: 2450
60 return baseBitrate + (fps - fpsTranscodingConstants.AVERAGE) * (maxBitrateDifference / maxFpsDifference)
61}
62
63/**
57 * The maximum bitrate we expect to see on a transcoded video in bytes per second. 64 * The maximum bitrate we expect to see on a transcoded video in bytes per second.
58 */ 65 */
59export function getMaxBitrate (resolution: VideoResolution, fps: number, 66export function getMaxBitrate (resolution: VideoResolution, fps: number,