aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/transcoding
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2023-05-04 15:29:34 +0200
committerChocobozzz <chocobozzz@cpy.re>2023-05-09 08:57:34 +0200
commit5e47f6ab984a7d00782e4c7030afffa1ba480add (patch)
tree1ce586b591a8d71acbc301eba29b9a5e6490439e /server/lib/transcoding
parent6a4905602636afd6650c9e6f4d0fcc2105d91100 (diff)
downloadPeerTube-5e47f6ab984a7d00782e4c7030afffa1ba480add.tar.gz
PeerTube-5e47f6ab984a7d00782e4c7030afffa1ba480add.tar.zst
PeerTube-5e47f6ab984a7d00782e4c7030afffa1ba480add.zip
Support studio transcoding in peertube runner
Diffstat (limited to 'server/lib/transcoding')
-rw-r--r--server/lib/transcoding/shared/job-builders/abstract-job-builder.ts18
-rw-r--r--server/lib/transcoding/shared/job-builders/transcoding-job-queue-builder.ts3
-rw-r--r--server/lib/transcoding/shared/job-builders/transcoding-runner-job-builder.ts15
-rw-r--r--server/lib/transcoding/transcoding-priority.ts24
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
2import { JOB_PRIORITY } from '@server/initializers/constants'
3import { VideoModel } from '@server/models/video/video'
4import { MUserId, MVideoFile, MVideoFullLight } from '@server/types/models' 2import { MUserId, MVideoFile, MVideoFullLight } from '@server/types/models'
5 3
6export abstract class AbstractJobBuilder { 4export 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'
19import { getTranscodingJobPriority } from '../../transcoding-priority'
19import { canDoQuickTranscode } from '../../transcoding-quick-transcode' 20import { canDoQuickTranscode } from '../../transcoding-quick-transcode'
20import { computeResolutionsToTranscode } from '../../transcoding-resolutions' 21import { computeResolutionsToTranscode } from '../../transcoding-resolutions'
21import { AbstractJobBuilder } from './abstract-job-builder' 22import { 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'
8import { MUserId, MVideoFile, MVideoFullLight, MVideoWithFileThumbnail } from '@server/types/models' 8import { MUserId, MVideoFile, MVideoFullLight, MVideoWithFileThumbnail } from '@server/types/models'
9import { MRunnerJob } from '@server/types/models/runners' 9import { MRunnerJob } from '@server/types/models/runners'
10import { ffprobePromise, getVideoStreamDimensionsInfo, getVideoStreamFPS, hasAudioStream, isAudioFile } from '@shared/ffmpeg' 10import { ffprobePromise, getVideoStreamDimensionsInfo, getVideoStreamFPS, hasAudioStream, isAudioFile } from '@shared/ffmpeg'
11import { getTranscodingJobPriority } from '../../transcoding-priority'
11import { computeResolutionsToTranscode } from '../../transcoding-resolutions' 12import { computeResolutionsToTranscode } from '../../transcoding-resolutions'
12import { AbstractJobBuilder } from './abstract-job-builder' 13import { 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 @@
1import { JOB_PRIORITY } from '@server/initializers/constants'
2import { VideoModel } from '@server/models/video/video'
3import { MUserId } from '@server/types/models'
4
5export 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}