diff options
author | Chocobozzz <me@florianbigard.com> | 2023-05-04 15:29:34 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2023-05-09 08:57:34 +0200 |
commit | 5e47f6ab984a7d00782e4c7030afffa1ba480add (patch) | |
tree | 1ce586b591a8d71acbc301eba29b9a5e6490439e /server/lib/transcoding | |
parent | 6a4905602636afd6650c9e6f4d0fcc2105d91100 (diff) | |
download | PeerTube-5e47f6ab984a7d00782e4c7030afffa1ba480add.tar.gz PeerTube-5e47f6ab984a7d00782e4c7030afffa1ba480add.tar.zst PeerTube-5e47f6ab984a7d00782e4c7030afffa1ba480add.zip |
Support studio transcoding in peertube runner
Diffstat (limited to 'server/lib/transcoding')
4 files changed, 34 insertions, 26 deletions
diff --git a/server/lib/transcoding/shared/job-builders/abstract-job-builder.ts b/server/lib/transcoding/shared/job-builders/abstract-job-builder.ts index 576e786d5..80dc05bfb 100644 --- a/server/lib/transcoding/shared/job-builders/abstract-job-builder.ts +++ b/server/lib/transcoding/shared/job-builders/abstract-job-builder.ts | |||
@@ -1,6 +1,4 @@ | |||
1 | 1 | ||
2 | import { JOB_PRIORITY } from '@server/initializers/constants' | ||
3 | import { VideoModel } from '@server/models/video/video' | ||
4 | import { MUserId, MVideoFile, MVideoFullLight } from '@server/types/models' | 2 | import { MUserId, MVideoFile, MVideoFullLight } from '@server/types/models' |
5 | 3 | ||
6 | export abstract class AbstractJobBuilder { | 4 | export abstract class AbstractJobBuilder { |
@@ -20,20 +18,4 @@ export abstract class AbstractJobBuilder { | |||
20 | isNewVideo: boolean | 18 | isNewVideo: boolean |
21 | user: MUserId | null | 19 | user: MUserId | null |
22 | }): Promise<any> | 20 | }): Promise<any> |
23 | |||
24 | protected async getTranscodingJobPriority (options: { | ||
25 | user: MUserId | ||
26 | fallback: number | ||
27 | }) { | ||
28 | const { user, fallback } = options | ||
29 | |||
30 | if (!user) return fallback | ||
31 | |||
32 | const now = new Date() | ||
33 | const lastWeek = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 7) | ||
34 | |||
35 | const videoUploadedByUser = await VideoModel.countVideosUploadedByUserSince(user.id, lastWeek) | ||
36 | |||
37 | return JOB_PRIORITY.TRANSCODING + videoUploadedByUser | ||
38 | } | ||
39 | } | 21 | } |
diff --git a/server/lib/transcoding/shared/job-builders/transcoding-job-queue-builder.ts b/server/lib/transcoding/shared/job-builders/transcoding-job-queue-builder.ts index 5a9c93ee5..29ee2ca61 100644 --- a/server/lib/transcoding/shared/job-builders/transcoding-job-queue-builder.ts +++ b/server/lib/transcoding/shared/job-builders/transcoding-job-queue-builder.ts | |||
@@ -16,6 +16,7 @@ import { | |||
16 | OptimizeTranscodingPayload, | 16 | OptimizeTranscodingPayload, |
17 | VideoTranscodingPayload | 17 | VideoTranscodingPayload |
18 | } from '@shared/models' | 18 | } from '@shared/models' |
19 | import { getTranscodingJobPriority } from '../../transcoding-priority' | ||
19 | import { canDoQuickTranscode } from '../../transcoding-quick-transcode' | 20 | import { canDoQuickTranscode } from '../../transcoding-quick-transcode' |
20 | import { computeResolutionsToTranscode } from '../../transcoding-resolutions' | 21 | import { computeResolutionsToTranscode } from '../../transcoding-resolutions' |
21 | import { AbstractJobBuilder } from './abstract-job-builder' | 22 | import { AbstractJobBuilder } from './abstract-job-builder' |
@@ -178,7 +179,7 @@ export class TranscodingJobQueueBuilder extends AbstractJobBuilder { | |||
178 | 179 | ||
179 | return { | 180 | return { |
180 | type: 'video-transcoding' as 'video-transcoding', | 181 | type: 'video-transcoding' as 'video-transcoding', |
181 | priority: await this.getTranscodingJobPriority({ user, fallback: undefined }), | 182 | priority: await getTranscodingJobPriority({ user, type: 'vod', fallback: undefined }), |
182 | payload | 183 | payload |
183 | } | 184 | } |
184 | } | 185 | } |
diff --git a/server/lib/transcoding/shared/job-builders/transcoding-runner-job-builder.ts b/server/lib/transcoding/shared/job-builders/transcoding-runner-job-builder.ts index 274dce21b..90b035402 100644 --- a/server/lib/transcoding/shared/job-builders/transcoding-runner-job-builder.ts +++ b/server/lib/transcoding/shared/job-builders/transcoding-runner-job-builder.ts | |||
@@ -8,6 +8,7 @@ import { VideoPathManager } from '@server/lib/video-path-manager' | |||
8 | import { MUserId, MVideoFile, MVideoFullLight, MVideoWithFileThumbnail } from '@server/types/models' | 8 | import { MUserId, MVideoFile, MVideoFullLight, MVideoWithFileThumbnail } from '@server/types/models' |
9 | import { MRunnerJob } from '@server/types/models/runners' | 9 | import { MRunnerJob } from '@server/types/models/runners' |
10 | import { ffprobePromise, getVideoStreamDimensionsInfo, getVideoStreamFPS, hasAudioStream, isAudioFile } from '@shared/ffmpeg' | 10 | import { ffprobePromise, getVideoStreamDimensionsInfo, getVideoStreamFPS, hasAudioStream, isAudioFile } from '@shared/ffmpeg' |
11 | import { getTranscodingJobPriority } from '../../transcoding-priority' | ||
11 | import { computeResolutionsToTranscode } from '../../transcoding-resolutions' | 12 | import { computeResolutionsToTranscode } from '../../transcoding-resolutions' |
12 | import { AbstractJobBuilder } from './abstract-job-builder' | 13 | import { AbstractJobBuilder } from './abstract-job-builder' |
13 | 14 | ||
@@ -49,7 +50,7 @@ export class TranscodingRunnerJobBuilder extends AbstractJobBuilder { | |||
49 | : resolution | 50 | : resolution |
50 | 51 | ||
51 | const fps = computeOutputFPS({ inputFPS, resolution: maxResolution }) | 52 | const fps = computeOutputFPS({ inputFPS, resolution: maxResolution }) |
52 | const priority = await this.getTranscodingJobPriority({ user, fallback: 0 }) | 53 | const priority = await getTranscodingJobPriority({ user, type: 'vod', fallback: 0 }) |
53 | 54 | ||
54 | const mainRunnerJob = videoFile.isAudio() | 55 | const mainRunnerJob = videoFile.isAudio() |
55 | ? await new VODAudioMergeTranscodingJobHandler().create({ video, resolution: maxResolution, fps, isNewVideo, priority }) | 56 | ? await new VODAudioMergeTranscodingJobHandler().create({ video, resolution: maxResolution, fps, isNewVideo, priority }) |
@@ -63,7 +64,7 @@ export class TranscodingRunnerJobBuilder extends AbstractJobBuilder { | |||
63 | fps, | 64 | fps, |
64 | isNewVideo, | 65 | isNewVideo, |
65 | dependsOnRunnerJob: mainRunnerJob, | 66 | dependsOnRunnerJob: mainRunnerJob, |
66 | priority: await this.getTranscodingJobPriority({ user, fallback: 0 }) | 67 | priority: await getTranscodingJobPriority({ user, type: 'vod', fallback: 0 }) |
67 | }) | 68 | }) |
68 | } | 69 | } |
69 | 70 | ||
@@ -96,7 +97,7 @@ export class TranscodingRunnerJobBuilder extends AbstractJobBuilder { | |||
96 | const maxResolution = Math.max(...resolutions) | 97 | const maxResolution = Math.max(...resolutions) |
97 | const { fps: inputFPS } = await video.probeMaxQualityFile() | 98 | const { fps: inputFPS } = await video.probeMaxQualityFile() |
98 | const maxFPS = computeOutputFPS({ inputFPS, resolution: maxResolution }) | 99 | const maxFPS = computeOutputFPS({ inputFPS, resolution: maxResolution }) |
99 | const priority = await this.getTranscodingJobPriority({ user, fallback: 0 }) | 100 | const priority = await getTranscodingJobPriority({ user, type: 'vod', fallback: 0 }) |
100 | 101 | ||
101 | const childrenResolutions = resolutions.filter(r => r !== maxResolution) | 102 | const childrenResolutions = resolutions.filter(r => r !== maxResolution) |
102 | 103 | ||
@@ -121,7 +122,7 @@ export class TranscodingRunnerJobBuilder extends AbstractJobBuilder { | |||
121 | isNewVideo, | 122 | isNewVideo, |
122 | deleteWebVideoFiles: false, | 123 | deleteWebVideoFiles: false, |
123 | dependsOnRunnerJob, | 124 | dependsOnRunnerJob, |
124 | priority: await this.getTranscodingJobPriority({ user, fallback: 0 }) | 125 | priority: await getTranscodingJobPriority({ user, type: 'vod', fallback: 0 }) |
125 | }) | 126 | }) |
126 | continue | 127 | continue |
127 | } | 128 | } |
@@ -133,7 +134,7 @@ export class TranscodingRunnerJobBuilder extends AbstractJobBuilder { | |||
133 | fps, | 134 | fps, |
134 | isNewVideo, | 135 | isNewVideo, |
135 | dependsOnRunnerJob, | 136 | dependsOnRunnerJob, |
136 | priority: await this.getTranscodingJobPriority({ user, fallback: 0 }) | 137 | priority: await getTranscodingJobPriority({ user, type: 'vod', fallback: 0 }) |
137 | }) | 138 | }) |
138 | continue | 139 | continue |
139 | } | 140 | } |
@@ -172,7 +173,7 @@ export class TranscodingRunnerJobBuilder extends AbstractJobBuilder { | |||
172 | fps, | 173 | fps, |
173 | isNewVideo, | 174 | isNewVideo, |
174 | dependsOnRunnerJob: mainRunnerJob, | 175 | dependsOnRunnerJob: mainRunnerJob, |
175 | priority: await this.getTranscodingJobPriority({ user, fallback: 0 }) | 176 | priority: await getTranscodingJobPriority({ user, type: 'vod', fallback: 0 }) |
176 | }) | 177 | }) |
177 | } | 178 | } |
178 | 179 | ||
@@ -184,7 +185,7 @@ export class TranscodingRunnerJobBuilder extends AbstractJobBuilder { | |||
184 | isNewVideo, | 185 | isNewVideo, |
185 | deleteWebVideoFiles: false, | 186 | deleteWebVideoFiles: false, |
186 | dependsOnRunnerJob: mainRunnerJob, | 187 | dependsOnRunnerJob: mainRunnerJob, |
187 | priority: await this.getTranscodingJobPriority({ user, fallback: 0 }) | 188 | priority: await getTranscodingJobPriority({ user, type: 'vod', fallback: 0 }) |
188 | }) | 189 | }) |
189 | } | 190 | } |
190 | } | 191 | } |
diff --git a/server/lib/transcoding/transcoding-priority.ts b/server/lib/transcoding/transcoding-priority.ts new file mode 100644 index 000000000..82ab6f2f1 --- /dev/null +++ b/server/lib/transcoding/transcoding-priority.ts | |||
@@ -0,0 +1,24 @@ | |||
1 | import { JOB_PRIORITY } from '@server/initializers/constants' | ||
2 | import { VideoModel } from '@server/models/video/video' | ||
3 | import { MUserId } from '@server/types/models' | ||
4 | |||
5 | export async function getTranscodingJobPriority (options: { | ||
6 | user: MUserId | ||
7 | fallback: number | ||
8 | type: 'vod' | 'studio' | ||
9 | }) { | ||
10 | const { user, fallback, type } = options | ||
11 | |||
12 | if (!user) return fallback | ||
13 | |||
14 | const now = new Date() | ||
15 | const lastWeek = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 7) | ||
16 | |||
17 | const videoUploadedByUser = await VideoModel.countVideosUploadedByUserSince(user.id, lastWeek) | ||
18 | |||
19 | const base = type === 'vod' | ||
20 | ? JOB_PRIORITY.TRANSCODING | ||
21 | : JOB_PRIORITY.VIDEO_STUDIO | ||
22 | |||
23 | return base + videoUploadedByUser | ||
24 | } | ||