1 import { pick } from 'lodash'
2 import { logger } from '@server/helpers/logger'
3 import { VideoJobInfoModel } from '@server/models/video/video-job-info'
4 import { MVideo } from '@server/types/models'
5 import { MRunnerJob } from '@server/types/models/runners'
6 import { buildUUID } from '@shared/extra-utils'
8 RunnerJobUpdatePayload,
9 RunnerJobVODWebVideoTranscodingPayload,
10 RunnerJobVODWebVideoTranscodingPrivatePayload,
11 VODWebVideoTranscodingSuccess
12 } from '@shared/models'
13 import { generateRunnerTranscodingVideoInputFileUrl } from '../runner-urls'
14 import { AbstractVODTranscodingJobHandler } from './abstract-vod-transcoding-job-handler'
15 import { loadTranscodingRunnerVideo, onVODWebVideoOrAudioMergeTranscodingJob } from './shared'
17 type CreateOptions = {
23 dependsOnRunnerJob?: MRunnerJob
26 // eslint-disable-next-line max-len
27 export class VODWebVideoTranscodingJobHandler extends AbstractVODTranscodingJobHandler<CreateOptions, RunnerJobUpdatePayload, VODWebVideoTranscodingSuccess> {
29 async create (options: CreateOptions) {
30 const { video, resolution, fps, priority, dependsOnRunnerJob } = options
32 const jobUUID = buildUUID()
33 const payload: RunnerJobVODWebVideoTranscodingPayload = {
35 videoFileUrl: generateRunnerTranscodingVideoInputFileUrl(jobUUID, video.uuid)
43 const privatePayload: RunnerJobVODWebVideoTranscodingPrivatePayload = {
44 ...pick(options, [ 'isNewVideo' ]),
49 const job = await this.createRunnerJob({
50 type: 'vod-web-video-transcoding',
58 await VideoJobInfoModel.increaseOrCreate(video.uuid, 'pendingTranscode')
63 // ---------------------------------------------------------------------------
65 protected async specificComplete (options: {
67 resultPayload: VODWebVideoTranscodingSuccess
69 const { runnerJob, resultPayload } = options
70 const privatePayload = runnerJob.privatePayload as RunnerJobVODWebVideoTranscodingPrivatePayload
72 const video = await loadTranscodingRunnerVideo(runnerJob, this.lTags)
75 const videoFilePath = resultPayload.videoFile as string
77 await onVODWebVideoOrAudioMergeTranscodingJob({ video, videoFilePath, privatePayload })
80 'Runner VOD web video transcoding job %s for %s ended.',
81 runnerJob.uuid, video.uuid, this.lTags(video.uuid, runnerJob.uuid)