diff options
author | Chocobozzz <me@florianbigard.com> | 2019-02-11 11:52:34 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-02-11 11:52:34 +0100 |
commit | 88108880bbdba473cfe36ecbebc1c3c4f972e102 (patch) | |
tree | b242efb3b4f0d7e49d88f2d1f2063b5b3b0489c0 /shared/models/videos | |
parent | 53a94c7cfa8368da4cd248d65df8346905938f0c (diff) | |
parent | 9b712a2017e4ab3cf12cd6bd58278905520159d0 (diff) | |
download | PeerTube-88108880bbdba473cfe36ecbebc1c3c4f972e102.tar.gz PeerTube-88108880bbdba473cfe36ecbebc1c3c4f972e102.tar.zst PeerTube-88108880bbdba473cfe36ecbebc1c3c4f972e102.zip |
Merge branch 'develop' into pr/1217
Diffstat (limited to 'shared/models/videos')
-rw-r--r-- | shared/models/videos/blacklist/video-blacklist-create.model.ts | 1 | ||||
-rw-r--r-- | shared/models/videos/blacklist/video-blacklist.model.ts | 1 | ||||
-rw-r--r-- | shared/models/videos/index.ts | 1 | ||||
-rw-r--r-- | shared/models/videos/video-query.type.ts | 2 | ||||
-rw-r--r-- | shared/models/videos/video-rate.type.ts | 2 | ||||
-rw-r--r-- | shared/models/videos/video-resolution.enum.ts | 68 | ||||
-rw-r--r-- | shared/models/videos/video-streaming-playlist.model.ts | 12 | ||||
-rw-r--r-- | shared/models/videos/video-streaming-playlist.type.ts | 3 | ||||
-rw-r--r-- | shared/models/videos/video-transcoding-fps.model.ts | 6 | ||||
-rw-r--r-- | shared/models/videos/video.model.ts | 9 |
10 files changed, 101 insertions, 4 deletions
diff --git a/shared/models/videos/blacklist/video-blacklist-create.model.ts b/shared/models/videos/blacklist/video-blacklist-create.model.ts index 89c69cb56..6e7d36421 100644 --- a/shared/models/videos/blacklist/video-blacklist-create.model.ts +++ b/shared/models/videos/blacklist/video-blacklist-create.model.ts | |||
@@ -1,3 +1,4 @@ | |||
1 | export interface VideoBlacklistCreate { | 1 | export interface VideoBlacklistCreate { |
2 | reason?: string | 2 | reason?: string |
3 | unfederate?: boolean | ||
3 | } | 4 | } |
diff --git a/shared/models/videos/blacklist/video-blacklist.model.ts b/shared/models/videos/blacklist/video-blacklist.model.ts index ef4e5e3a2..4bd976190 100644 --- a/shared/models/videos/blacklist/video-blacklist.model.ts +++ b/shared/models/videos/blacklist/video-blacklist.model.ts | |||
@@ -2,6 +2,7 @@ export interface VideoBlacklist { | |||
2 | id: number | 2 | id: number |
3 | createdAt: Date | 3 | createdAt: Date |
4 | updatedAt: Date | 4 | updatedAt: Date |
5 | unfederated: boolean | ||
5 | reason?: string | 6 | reason?: string |
6 | 7 | ||
7 | video: { | 8 | video: { |
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-query.type.ts b/shared/models/videos/video-query.type.ts index ff0f527f3..f76a91aad 100644 --- a/shared/models/videos/video-query.type.ts +++ b/shared/models/videos/video-query.type.ts | |||
@@ -1 +1 @@ | |||
export type VideoFilter = 'local' | export type VideoFilter = 'local' | 'all-local' | ||
diff --git a/shared/models/videos/video-rate.type.ts b/shared/models/videos/video-rate.type.ts index 17aaba5a5..d48774a4b 100644 --- a/shared/models/videos/video-rate.type.ts +++ b/shared/models/videos/video-rate.type.ts | |||
@@ -1 +1 @@ | |||
export type VideoRateType = 'like' | 'dislike' | 'none' | export type VideoRateType = 'like' | 'dislike' | ||
diff --git a/shared/models/videos/video-resolution.enum.ts b/shared/models/videos/video-resolution.enum.ts index 100fc0e6e..7da5e7100 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,69 @@ 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, at VideoTranscodingFPS.AVERAGE. | ||
13 | * | ||
14 | * Sources for individual quality levels: | ||
15 | * Google Live Encoder: https://support.google.com/youtube/answer/2853702?hl=en | ||
16 | * YouTube Video Info (tested with random music video): https://www.h3xed.com/blogmedia/youtube-info.php | ||
17 | */ | ||
18 | function getBaseBitrate (resolution: VideoResolution) { | ||
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 | // quality according to Google Live Encoder: 1,500 - 4,000 Kbps | ||
34 | // Quality according to YouTube Video Info: 1752 Kbps | ||
35 | return 1750 * 1000 | ||
36 | case VideoResolution.H_1080P: // fallthrough | ||
37 | default: | ||
38 | // quality according to Google Live Encoder: 3000 - 6000 Kbps | ||
39 | // Quality according to YouTube Video Info: 3277 Kbps | ||
40 | return 3300 * 1000 | ||
41 | } | ||
42 | } | ||
43 | |||
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 | */ | ||
53 | export function getTargetBitrate (resolution: VideoResolution, fps: number, fpsTranscodingConstants: VideoTranscodingFPS) { | ||
54 | const baseBitrate = getBaseBitrate(resolution) | ||
55 | // The maximum bitrate, used when fps === VideoTranscodingFPS.MAX | ||
56 | // Based on numbers from Youtube, 60 fps bitrate divided by 30 fps bitrate: | ||
57 | // 720p: 2600 / 1750 = 1.49 | ||
58 | // 1080p: 4400 / 3300 = 1.33 | ||
59 | const maxBitrate = baseBitrate * 1.4 | ||
60 | const maxBitrateDifference = maxBitrate - baseBitrate | ||
61 | const maxFpsDifference = fpsTranscodingConstants.MAX - fpsTranscodingConstants.AVERAGE | ||
62 | // For 1080p video with default settings, this results in the following formula: | ||
63 | // 3300 + (x - 30) * (1320/30) | ||
64 | // Example outputs: | ||
65 | // 1080p10: 2420 kbps, 1080p30: 3300 kbps, 1080p60: 4620 kbps | ||
66 | // 720p10: 1283 kbps, 720p30: 1750 kbps, 720p60: 2450 kbps | ||
67 | return baseBitrate + (fps - fpsTranscodingConstants.AVERAGE) * (maxBitrateDifference / maxFpsDifference) | ||
68 | } | ||
69 | |||
70 | /** | ||
71 | * The maximum bitrate we expect to see on a transcoded video in bytes per second. | ||
72 | */ | ||
73 | export function getMaxBitrate (resolution: VideoResolution, fps: number, fpsTranscodingConstants: VideoTranscodingFPS) { | ||
74 | return getTargetBitrate(resolution, fps, fpsTranscodingConstants) * 2 | ||
75 | } | ||
diff --git a/shared/models/videos/video-streaming-playlist.model.ts b/shared/models/videos/video-streaming-playlist.model.ts new file mode 100644 index 000000000..17f8fe865 --- /dev/null +++ b/shared/models/videos/video-streaming-playlist.model.ts | |||
@@ -0,0 +1,12 @@ | |||
1 | import { VideoStreamingPlaylistType } from './video-streaming-playlist.type' | ||
2 | |||
3 | export class VideoStreamingPlaylist { | ||
4 | id: number | ||
5 | type: VideoStreamingPlaylistType | ||
6 | playlistUrl: string | ||
7 | segmentsSha256Url: string | ||
8 | |||
9 | redundancies: { | ||
10 | baseUrl: string | ||
11 | }[] | ||
12 | } | ||
diff --git a/shared/models/videos/video-streaming-playlist.type.ts b/shared/models/videos/video-streaming-playlist.type.ts new file mode 100644 index 000000000..3b403f295 --- /dev/null +++ b/shared/models/videos/video-streaming-playlist.type.ts | |||
@@ -0,0 +1,3 @@ | |||
1 | export enum VideoStreamingPlaylistType { | ||
2 | HLS = 1 | ||
3 | } | ||
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 | } | ||
diff --git a/shared/models/videos/video.model.ts b/shared/models/videos/video.model.ts index 4a792fcbc..891831a9e 100644 --- a/shared/models/videos/video.model.ts +++ b/shared/models/videos/video.model.ts | |||
@@ -5,6 +5,7 @@ import { VideoChannel } from './channel/video-channel.model' | |||
5 | import { VideoPrivacy } from './video-privacy.enum' | 5 | import { VideoPrivacy } from './video-privacy.enum' |
6 | import { VideoScheduleUpdate } from './video-schedule-update.model' | 6 | import { VideoScheduleUpdate } from './video-schedule-update.model' |
7 | import { VideoConstant } from './video-constant.model' | 7 | import { VideoConstant } from './video-constant.model' |
8 | import { VideoStreamingPlaylist } from './video-streaming-playlist.model' | ||
8 | 9 | ||
9 | export interface VideoFile { | 10 | export interface VideoFile { |
10 | magnetUri: string | 11 | magnetUri: string |
@@ -24,7 +25,7 @@ export interface VideoChannelAttribute { | |||
24 | displayName: string | 25 | displayName: string |
25 | url: string | 26 | url: string |
26 | host: string | 27 | host: string |
27 | avatar: Avatar | 28 | avatar?: Avatar |
28 | } | 29 | } |
29 | 30 | ||
30 | export interface AccountAttribute { | 31 | export interface AccountAttribute { |
@@ -34,7 +35,7 @@ export interface AccountAttribute { | |||
34 | displayName: string | 35 | displayName: string |
35 | url: string | 36 | url: string |
36 | host: string | 37 | host: string |
37 | avatar: Avatar | 38 | avatar?: Avatar |
38 | } | 39 | } |
39 | 40 | ||
40 | export interface Video { | 41 | export interface Video { |
@@ -87,4 +88,8 @@ export interface VideoDetails extends Video { | |||
87 | // Not optional in details (unlike in Video) | 88 | // Not optional in details (unlike in Video) |
88 | waitTranscoding: boolean | 89 | waitTranscoding: boolean |
89 | state: VideoConstant<VideoState> | 90 | state: VideoConstant<VideoState> |
91 | |||
92 | trackerUrls: string[] | ||
93 | |||
94 | streamingPlaylists: VideoStreamingPlaylist[] | ||
90 | } | 95 | } |