From 0c9668f77901e7540e2c7045eb0f2974a4842a69 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 21 Apr 2023 14:55:10 +0200 Subject: Implement remote runner jobs in server Move ffmpeg functions to @shared --- server/lib/runners/job-handlers/shared/index.ts | 1 + .../lib/runners/job-handlers/shared/vod-helpers.ts | 44 ++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 server/lib/runners/job-handlers/shared/index.ts create mode 100644 server/lib/runners/job-handlers/shared/vod-helpers.ts (limited to 'server/lib/runners/job-handlers/shared') diff --git a/server/lib/runners/job-handlers/shared/index.ts b/server/lib/runners/job-handlers/shared/index.ts new file mode 100644 index 000000000..348273ae2 --- /dev/null +++ b/server/lib/runners/job-handlers/shared/index.ts @@ -0,0 +1 @@ +export * from './vod-helpers' diff --git a/server/lib/runners/job-handlers/shared/vod-helpers.ts b/server/lib/runners/job-handlers/shared/vod-helpers.ts new file mode 100644 index 000000000..93ae89ff8 --- /dev/null +++ b/server/lib/runners/job-handlers/shared/vod-helpers.ts @@ -0,0 +1,44 @@ +import { move } from 'fs-extra' +import { dirname, join } from 'path' +import { logger, LoggerTagsFn } from '@server/helpers/logger' +import { onTranscodingEnded } from '@server/lib/transcoding/ended-transcoding' +import { onWebTorrentVideoFileTranscoding } from '@server/lib/transcoding/web-transcoding' +import { buildNewFile } from '@server/lib/video-file' +import { VideoModel } from '@server/models/video/video' +import { MVideoFullLight } from '@server/types/models' +import { MRunnerJob } from '@server/types/models/runners' +import { RunnerJobVODAudioMergeTranscodingPrivatePayload, RunnerJobVODWebVideoTranscodingPrivatePayload } from '@shared/models' + +export async function onVODWebVideoOrAudioMergeTranscodingJob (options: { + video: MVideoFullLight + videoFilePath: string + privatePayload: RunnerJobVODWebVideoTranscodingPrivatePayload | RunnerJobVODAudioMergeTranscodingPrivatePayload +}) { + const { video, videoFilePath, privatePayload } = options + + const videoFile = await buildNewFile({ path: videoFilePath, mode: 'web-video' }) + videoFile.videoId = video.id + + const newVideoFilePath = join(dirname(videoFilePath), videoFile.filename) + await move(videoFilePath, newVideoFilePath) + + await onWebTorrentVideoFileTranscoding({ + video, + videoFile, + videoOutputPath: newVideoFilePath + }) + + await onTranscodingEnded({ isNewVideo: privatePayload.isNewVideo, moveVideoToNextState: true, video }) +} + +export async function loadTranscodingRunnerVideo (runnerJob: MRunnerJob, lTags: LoggerTagsFn) { + const videoUUID = runnerJob.privatePayload.videoUUID + + const video = await VideoModel.loadFull(videoUUID) + if (!video) { + logger.info('Video %s does not exist anymore after transcoding runner job.', videoUUID, lTags(videoUUID)) + return undefined + } + + return video +} -- cgit v1.2.3