diff options
Diffstat (limited to 'shared')
-rw-r--r-- | shared/models/videos/index.ts | 1 | ||||
-rw-r--r-- | shared/models/videos/video-resolution.enum.ts | 55 | ||||
-rw-r--r-- | shared/models/videos/video-transcoding-fps.model.ts | 6 |
3 files changed, 62 insertions, 0 deletions
diff --git a/shared/models/videos/index.ts b/shared/models/videos/index.ts index 90a0e3053..056ae06da 100644 --- a/shared/models/videos/index.ts +++ b/shared/models/videos/index.ts | |||
@@ -21,6 +21,7 @@ export * from './video-update.model' | |||
21 | export * from './video.model' | 21 | export * from './video.model' |
22 | export * from './video-query.type' | 22 | export * from './video-query.type' |
23 | export * from './video-state.enum' | 23 | export * from './video-state.enum' |
24 | export * from './video-transcoding-fps.model' | ||
24 | export * from './caption/video-caption.model' | 25 | export * from './caption/video-caption.model' |
25 | export * from './caption/video-caption-update.model' | 26 | export * from './caption/video-caption-update.model' |
26 | export * from './import/video-import-create.model' | 27 | export * from './import/video-import-create.model' |
diff --git a/shared/models/videos/video-resolution.enum.ts b/shared/models/videos/video-resolution.enum.ts index 100fc0e6e..3c52bbf98 100644 --- a/shared/models/videos/video-resolution.enum.ts +++ b/shared/models/videos/video-resolution.enum.ts | |||
@@ -1,3 +1,5 @@ | |||
1 | import { VideoTranscodingFPS } from './video-transcoding-fps.model' | ||
2 | |||
1 | export enum VideoResolution { | 3 | export enum VideoResolution { |
2 | H_240P = 240, | 4 | H_240P = 240, |
3 | H_360P = 360, | 5 | H_360P = 360, |
@@ -5,3 +7,56 @@ export enum VideoResolution { | |||
5 | H_720P = 720, | 7 | H_720P = 720, |
6 | H_1080P = 1080 | 8 | H_1080P = 1080 |
7 | } | 9 | } |
10 | |||
11 | /** | ||
12 | * Bitrate targets for different resolutions and frame rates, in bytes per second. | ||
13 | * Sources for individual quality levels: | ||
14 | * 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 | */ | ||
17 | export function getTargetBitrate (resolution: VideoResolution, fps: number, | ||
18 | fpsTranscodingConstants: VideoTranscodingFPS) { | ||
19 | switch (resolution) { | ||
20 | case VideoResolution.H_240P: | ||
21 | // quality according to Google Live Encoder: 300 - 700 Kbps | ||
22 | // Quality according to YouTube Video Info: 186 Kbps | ||
23 | return 250 * 1000 | ||
24 | case VideoResolution.H_360P: | ||
25 | // quality according to Google Live Encoder: 400 - 1,000 Kbps | ||
26 | // Quality according to YouTube Video Info: 480 Kbps | ||
27 | return 500 * 1000 | ||
28 | case VideoResolution.H_480P: | ||
29 | // quality according to Google Live Encoder: 500 - 2,000 Kbps | ||
30 | // Quality according to YouTube Video Info: 879 Kbps | ||
31 | return 900 * 1000 | ||
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 | } else { | ||
38 | // quality according to Google Live Encoder: 1,500 - 4,000 Kbps | ||
39 | // Quality according to YouTube Video Info: 1752 Kbps | ||
40 | return 1750 * 1000 | ||
41 | } | ||
42 | case VideoResolution.H_1080P: // fallthrough | ||
43 | 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 | } else { | ||
49 | // quality according to Google Live Encoder: 3000 - 6000 Kbps | ||
50 | // Quality according to YouTube Video Info: 3277 Kbps | ||
51 | return 3300 * 1000 | ||
52 | } | ||
53 | } | ||
54 | } | ||
55 | |||
56 | /** | ||
57 | * The maximum bitrate we expect to see on a transcoded video in bytes per second. | ||
58 | */ | ||
59 | export function getMaxBitrate (resolution: VideoResolution, fps: number, | ||
60 | fpsTranscodingConstants: VideoTranscodingFPS) { | ||
61 | return getTargetBitrate(resolution, fps, fpsTranscodingConstants) * 2 | ||
62 | } | ||
diff --git a/shared/models/videos/video-transcoding-fps.model.ts b/shared/models/videos/video-transcoding-fps.model.ts new file mode 100644 index 000000000..82022d2f1 --- /dev/null +++ b/shared/models/videos/video-transcoding-fps.model.ts | |||
@@ -0,0 +1,6 @@ | |||
1 | export type VideoTranscodingFPS = { | ||
2 | MIN: number, | ||
3 | AVERAGE: number, | ||
4 | MAX: number, | ||
5 | KEEP_ORIGIN_FPS_RESOLUTION_MIN: number | ||
6 | } | ||