2023-07-31 07:34:36 -05:00
|
|
|
import { logger } from '@server/helpers/logger.js'
|
|
|
|
import { VideoJobInfoModel } from '@server/models/video/video-job-info.js'
|
|
|
|
import { MVideo } from '@server/types/models/index.js'
|
|
|
|
import { MRunnerJob } from '@server/types/models/runners/index.js'
|
|
|
|
import { pick } from '@peertube/peertube-core-utils'
|
|
|
|
import { buildUUID } from '@peertube/peertube-node-utils'
|
2023-04-21 07:55:10 -05:00
|
|
|
import {
|
|
|
|
RunnerJobUpdatePayload,
|
|
|
|
RunnerJobVODAudioMergeTranscodingPayload,
|
|
|
|
RunnerJobVODWebVideoTranscodingPrivatePayload,
|
|
|
|
VODAudioMergeTranscodingSuccess
|
2023-07-31 07:34:36 -05:00
|
|
|
} from '@peertube/peertube-models'
|
|
|
|
import { generateRunnerTranscodingVideoInputFileUrl, generateRunnerTranscodingVideoPreviewFileUrl } from '../runner-urls.js'
|
|
|
|
import { AbstractVODTranscodingJobHandler } from './abstract-vod-transcoding-job-handler.js'
|
|
|
|
import { loadTranscodingRunnerVideo, onVODWebVideoOrAudioMergeTranscodingJob } from './shared/index.js'
|
2023-04-21 07:55:10 -05:00
|
|
|
|
|
|
|
type CreateOptions = {
|
|
|
|
video: MVideo
|
|
|
|
isNewVideo: boolean
|
|
|
|
resolution: number
|
|
|
|
fps: number
|
|
|
|
priority: number
|
2023-11-17 09:25:11 -06:00
|
|
|
deleteInputFileId: number | null
|
2023-04-21 07:55:10 -05:00
|
|
|
dependsOnRunnerJob?: MRunnerJob
|
|
|
|
}
|
|
|
|
|
|
|
|
// eslint-disable-next-line max-len
|
|
|
|
export class VODAudioMergeTranscodingJobHandler extends AbstractVODTranscodingJobHandler<CreateOptions, RunnerJobUpdatePayload, VODAudioMergeTranscodingSuccess> {
|
|
|
|
|
|
|
|
async create (options: CreateOptions) {
|
|
|
|
const { video, resolution, fps, priority, dependsOnRunnerJob } = options
|
|
|
|
|
|
|
|
const jobUUID = buildUUID()
|
|
|
|
const payload: RunnerJobVODAudioMergeTranscodingPayload = {
|
|
|
|
input: {
|
|
|
|
audioFileUrl: generateRunnerTranscodingVideoInputFileUrl(jobUUID, video.uuid),
|
|
|
|
previewFileUrl: generateRunnerTranscodingVideoPreviewFileUrl(jobUUID, video.uuid)
|
|
|
|
},
|
|
|
|
output: {
|
|
|
|
resolution,
|
|
|
|
fps
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const privatePayload: RunnerJobVODWebVideoTranscodingPrivatePayload = {
|
2023-11-17 09:25:11 -06:00
|
|
|
...pick(options, [ 'isNewVideo', 'deleteInputFileId' ]),
|
2023-04-21 07:55:10 -05:00
|
|
|
|
|
|
|
videoUUID: video.uuid
|
|
|
|
}
|
|
|
|
|
|
|
|
const job = await this.createRunnerJob({
|
|
|
|
type: 'vod-audio-merge-transcoding',
|
|
|
|
jobUUID,
|
|
|
|
payload,
|
|
|
|
privatePayload,
|
|
|
|
priority,
|
|
|
|
dependsOnRunnerJob
|
|
|
|
})
|
|
|
|
|
|
|
|
await VideoJobInfoModel.increaseOrCreate(video.uuid, 'pendingTranscode')
|
|
|
|
|
|
|
|
return job
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2023-05-04 08:29:34 -05:00
|
|
|
protected async specificComplete (options: {
|
2023-04-21 07:55:10 -05:00
|
|
|
runnerJob: MRunnerJob
|
|
|
|
resultPayload: VODAudioMergeTranscodingSuccess
|
|
|
|
}) {
|
|
|
|
const { runnerJob, resultPayload } = options
|
|
|
|
const privatePayload = runnerJob.privatePayload as RunnerJobVODWebVideoTranscodingPrivatePayload
|
|
|
|
|
|
|
|
const video = await loadTranscodingRunnerVideo(runnerJob, this.lTags)
|
|
|
|
if (!video) return
|
|
|
|
|
|
|
|
const videoFilePath = resultPayload.videoFile as string
|
|
|
|
|
2024-02-27 04:18:56 -06:00
|
|
|
await onVODWebVideoOrAudioMergeTranscodingJob({ video, videoFilePath, privatePayload, wasAudioFile: true })
|
2023-04-21 07:55:10 -05:00
|
|
|
|
|
|
|
logger.info(
|
|
|
|
'Runner VOD audio merge transcoding job %s for %s ended.',
|
|
|
|
runnerJob.uuid, video.uuid, this.lTags(video.uuid, runnerJob.uuid)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|