mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-04 10:19:35 +02:00
Support studio transcoding in peertube runner
This commit is contained in:
parent
6a49056026
commit
5e47f6ab98
67 changed files with 1423 additions and 262 deletions
|
@ -1,6 +1,4 @@
|
|||
|
||||
import { JOB_PRIORITY } from '@server/initializers/constants'
|
||||
import { VideoModel } from '@server/models/video/video'
|
||||
import { MUserId, MVideoFile, MVideoFullLight } from '@server/types/models'
|
||||
|
||||
export abstract class AbstractJobBuilder {
|
||||
|
@ -20,20 +18,4 @@ export abstract class AbstractJobBuilder {
|
|||
isNewVideo: boolean
|
||||
user: MUserId | null
|
||||
}): Promise<any>
|
||||
|
||||
protected async getTranscodingJobPriority (options: {
|
||||
user: MUserId
|
||||
fallback: number
|
||||
}) {
|
||||
const { user, fallback } = options
|
||||
|
||||
if (!user) return fallback
|
||||
|
||||
const now = new Date()
|
||||
const lastWeek = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 7)
|
||||
|
||||
const videoUploadedByUser = await VideoModel.countVideosUploadedByUserSince(user.id, lastWeek)
|
||||
|
||||
return JOB_PRIORITY.TRANSCODING + videoUploadedByUser
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ import {
|
|||
OptimizeTranscodingPayload,
|
||||
VideoTranscodingPayload
|
||||
} from '@shared/models'
|
||||
import { getTranscodingJobPriority } from '../../transcoding-priority'
|
||||
import { canDoQuickTranscode } from '../../transcoding-quick-transcode'
|
||||
import { computeResolutionsToTranscode } from '../../transcoding-resolutions'
|
||||
import { AbstractJobBuilder } from './abstract-job-builder'
|
||||
|
@ -178,7 +179,7 @@ export class TranscodingJobQueueBuilder extends AbstractJobBuilder {
|
|||
|
||||
return {
|
||||
type: 'video-transcoding' as 'video-transcoding',
|
||||
priority: await this.getTranscodingJobPriority({ user, fallback: undefined }),
|
||||
priority: await getTranscodingJobPriority({ user, type: 'vod', fallback: undefined }),
|
||||
payload
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import { VideoPathManager } from '@server/lib/video-path-manager'
|
|||
import { MUserId, MVideoFile, MVideoFullLight, MVideoWithFileThumbnail } from '@server/types/models'
|
||||
import { MRunnerJob } from '@server/types/models/runners'
|
||||
import { ffprobePromise, getVideoStreamDimensionsInfo, getVideoStreamFPS, hasAudioStream, isAudioFile } from '@shared/ffmpeg'
|
||||
import { getTranscodingJobPriority } from '../../transcoding-priority'
|
||||
import { computeResolutionsToTranscode } from '../../transcoding-resolutions'
|
||||
import { AbstractJobBuilder } from './abstract-job-builder'
|
||||
|
||||
|
@ -49,7 +50,7 @@ export class TranscodingRunnerJobBuilder extends AbstractJobBuilder {
|
|||
: resolution
|
||||
|
||||
const fps = computeOutputFPS({ inputFPS, resolution: maxResolution })
|
||||
const priority = await this.getTranscodingJobPriority({ user, fallback: 0 })
|
||||
const priority = await getTranscodingJobPriority({ user, type: 'vod', fallback: 0 })
|
||||
|
||||
const mainRunnerJob = videoFile.isAudio()
|
||||
? await new VODAudioMergeTranscodingJobHandler().create({ video, resolution: maxResolution, fps, isNewVideo, priority })
|
||||
|
@ -63,7 +64,7 @@ export class TranscodingRunnerJobBuilder extends AbstractJobBuilder {
|
|||
fps,
|
||||
isNewVideo,
|
||||
dependsOnRunnerJob: mainRunnerJob,
|
||||
priority: await this.getTranscodingJobPriority({ user, fallback: 0 })
|
||||
priority: await getTranscodingJobPriority({ user, type: 'vod', fallback: 0 })
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -96,7 +97,7 @@ export class TranscodingRunnerJobBuilder extends AbstractJobBuilder {
|
|||
const maxResolution = Math.max(...resolutions)
|
||||
const { fps: inputFPS } = await video.probeMaxQualityFile()
|
||||
const maxFPS = computeOutputFPS({ inputFPS, resolution: maxResolution })
|
||||
const priority = await this.getTranscodingJobPriority({ user, fallback: 0 })
|
||||
const priority = await getTranscodingJobPriority({ user, type: 'vod', fallback: 0 })
|
||||
|
||||
const childrenResolutions = resolutions.filter(r => r !== maxResolution)
|
||||
|
||||
|
@ -121,7 +122,7 @@ export class TranscodingRunnerJobBuilder extends AbstractJobBuilder {
|
|||
isNewVideo,
|
||||
deleteWebVideoFiles: false,
|
||||
dependsOnRunnerJob,
|
||||
priority: await this.getTranscodingJobPriority({ user, fallback: 0 })
|
||||
priority: await getTranscodingJobPriority({ user, type: 'vod', fallback: 0 })
|
||||
})
|
||||
continue
|
||||
}
|
||||
|
@ -133,7 +134,7 @@ export class TranscodingRunnerJobBuilder extends AbstractJobBuilder {
|
|||
fps,
|
||||
isNewVideo,
|
||||
dependsOnRunnerJob,
|
||||
priority: await this.getTranscodingJobPriority({ user, fallback: 0 })
|
||||
priority: await getTranscodingJobPriority({ user, type: 'vod', fallback: 0 })
|
||||
})
|
||||
continue
|
||||
}
|
||||
|
@ -172,7 +173,7 @@ export class TranscodingRunnerJobBuilder extends AbstractJobBuilder {
|
|||
fps,
|
||||
isNewVideo,
|
||||
dependsOnRunnerJob: mainRunnerJob,
|
||||
priority: await this.getTranscodingJobPriority({ user, fallback: 0 })
|
||||
priority: await getTranscodingJobPriority({ user, type: 'vod', fallback: 0 })
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -184,7 +185,7 @@ export class TranscodingRunnerJobBuilder extends AbstractJobBuilder {
|
|||
isNewVideo,
|
||||
deleteWebVideoFiles: false,
|
||||
dependsOnRunnerJob: mainRunnerJob,
|
||||
priority: await this.getTranscodingJobPriority({ user, fallback: 0 })
|
||||
priority: await getTranscodingJobPriority({ user, type: 'vod', fallback: 0 })
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
24
server/lib/transcoding/transcoding-priority.ts
Normal file
24
server/lib/transcoding/transcoding-priority.ts
Normal file
|
@ -0,0 +1,24 @@
|
|||
import { JOB_PRIORITY } from '@server/initializers/constants'
|
||||
import { VideoModel } from '@server/models/video/video'
|
||||
import { MUserId } from '@server/types/models'
|
||||
|
||||
export async function getTranscodingJobPriority (options: {
|
||||
user: MUserId
|
||||
fallback: number
|
||||
type: 'vod' | 'studio'
|
||||
}) {
|
||||
const { user, fallback, type } = options
|
||||
|
||||
if (!user) return fallback
|
||||
|
||||
const now = new Date()
|
||||
const lastWeek = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 7)
|
||||
|
||||
const videoUploadedByUser = await VideoModel.countVideosUploadedByUserSince(user.id, lastWeek)
|
||||
|
||||
const base = type === 'vod'
|
||||
? JOB_PRIORITY.TRANSCODING
|
||||
: JOB_PRIORITY.VIDEO_STUDIO
|
||||
|
||||
return base + videoUploadedByUser
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue