From 5e47f6ab984a7d00782e4c7030afffa1ba480add Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 4 May 2023 15:29:34 +0200 Subject: Support studio transcoding in peertube runner --- server/controllers/api/config.ts | 5 ++++- server/controllers/api/runners/jobs-files.ts | 27 ++++++++++++++++++++++++++- server/controllers/api/runners/jobs.ts | 13 ++++++++++++- server/controllers/api/videos/studio.ts | 21 +++++++++++++-------- 4 files changed, 55 insertions(+), 11 deletions(-) (limited to 'server/controllers') diff --git a/server/controllers/api/config.ts b/server/controllers/api/config.ts index 0b9aaffda..3b6230f4a 100644 --- a/server/controllers/api/config.ts +++ b/server/controllers/api/config.ts @@ -274,7 +274,10 @@ function customConfig (): CustomConfig { } }, videoStudio: { - enabled: CONFIG.VIDEO_STUDIO.ENABLED + enabled: CONFIG.VIDEO_STUDIO.ENABLED, + remoteRunners: { + enabled: CONFIG.VIDEO_STUDIO.REMOTE_RUNNERS.ENABLED + } }, import: { videos: { diff --git a/server/controllers/api/runners/jobs-files.ts b/server/controllers/api/runners/jobs-files.ts index e43ce35f5..4efa40b3a 100644 --- a/server/controllers/api/runners/jobs-files.ts +++ b/server/controllers/api/runners/jobs-files.ts @@ -2,9 +2,13 @@ import express from 'express' import { logger, loggerTagsFactory } from '@server/helpers/logger' import { proxifyHLS, proxifyWebTorrentFile } from '@server/lib/object-storage' import { VideoPathManager } from '@server/lib/video-path-manager' +import { getStudioTaskFilePath } from '@server/lib/video-studio' import { asyncMiddleware } from '@server/middlewares' import { jobOfRunnerGetValidator } from '@server/middlewares/validators/runners' -import { runnerJobGetVideoTranscodingFileValidator } from '@server/middlewares/validators/runners/job-files' +import { + runnerJobGetVideoStudioTaskFileValidator, + runnerJobGetVideoTranscodingFileValidator +} from '@server/middlewares/validators/runners/job-files' import { VideoStorage } from '@shared/models' const lTags = loggerTagsFactory('api', 'runner') @@ -23,6 +27,13 @@ runnerJobFilesRouter.post('/jobs/:jobUUID/files/videos/:videoId/previews/max-qua getMaxQualityVideoPreview ) +runnerJobFilesRouter.post('/jobs/:jobUUID/files/videos/:videoId/studio/task-files/:filename', + asyncMiddleware(jobOfRunnerGetValidator), + asyncMiddleware(runnerJobGetVideoTranscodingFileValidator), + runnerJobGetVideoStudioTaskFileValidator, + getVideoEditionTaskFile +) + // --------------------------------------------------------------------------- export { @@ -82,3 +93,17 @@ function getMaxQualityVideoPreview (req: express.Request, res: express.Response) return res.sendFile(file.getPath()) } + +function getVideoEditionTaskFile (req: express.Request, res: express.Response) { + const runnerJob = res.locals.runnerJob + const runner = runnerJob.Runner + const video = res.locals.videoAll + const filename = req.params.filename + + logger.info( + 'Get video edition task file %s of video %s of job %s for runner %s', filename, video.uuid, runnerJob.uuid, runner.name, + lTags(runner.name, runnerJob.id, runnerJob.type) + ) + + return res.sendFile(getStudioTaskFilePath(filename)) +} diff --git a/server/controllers/api/runners/jobs.ts b/server/controllers/api/runners/jobs.ts index 7d488ec11..8e34c07a3 100644 --- a/server/controllers/api/runners/jobs.ts +++ b/server/controllers/api/runners/jobs.ts @@ -17,6 +17,7 @@ import { import { abortRunnerJobValidator, acceptRunnerJobValidator, + cancelRunnerJobValidator, errorRunnerJobValidator, getRunnerFromTokenValidator, jobOfRunnerGetValidator, @@ -41,6 +42,7 @@ import { RunnerJobUpdateBody, RunnerJobUpdatePayload, UserRight, + VideoEditionTranscodingSuccess, VODAudioMergeTranscodingSuccess, VODHLSTranscodingSuccess, VODWebVideoTranscodingSuccess @@ -110,6 +112,7 @@ runnerJobsRouter.post('/jobs/:jobUUID/cancel', authenticate, ensureUserHasRight(UserRight.MANAGE_RUNNERS), asyncMiddleware(runnerJobGetValidator), + cancelRunnerJobValidator, asyncMiddleware(cancelRunnerJob) ) @@ -297,6 +300,14 @@ const jobSuccessPayloadBuilders: { } }, + 'video-edition-transcoding': (payload: VideoEditionTranscodingSuccess, files) => { + return { + ...payload, + + videoFile: files['payload[videoFile]'][0].path + } + }, + 'live-rtmp-hls-transcoding': () => ({}) } @@ -327,7 +338,7 @@ async function postRunnerJobSuccess (req: express.Request, res: express.Response async function cancelRunnerJob (req: express.Request, res: express.Response) { const runnerJob = res.locals.runnerJob - logger.info('Cancelling job %s (%s)', runnerJob.type, lTags(runnerJob.uuid, runnerJob.type)) + logger.info('Cancelling job %s (%s)', runnerJob.uuid, runnerJob.type, lTags(runnerJob.uuid, runnerJob.type)) const RunnerJobHandler = getRunnerJobHandlerClass(runnerJob) await new RunnerJobHandler().cancel({ runnerJob }) diff --git a/server/controllers/api/videos/studio.ts b/server/controllers/api/videos/studio.ts index 2ccb2fb89..7c31dfd2b 100644 --- a/server/controllers/api/videos/studio.ts +++ b/server/controllers/api/videos/studio.ts @@ -1,12 +1,10 @@ import Bluebird from 'bluebird' import express from 'express' import { move } from 'fs-extra' -import { basename, join } from 'path' +import { basename } from 'path' import { createAnyReqFiles } from '@server/helpers/express-utils' -import { CONFIG } from '@server/initializers/config' -import { MIMETYPES } from '@server/initializers/constants' -import { JobQueue } from '@server/lib/job-queue' -import { buildTaskFileFieldname, getTaskFileFromReq } from '@server/lib/video-studio' +import { MIMETYPES, VIDEO_FILTERS } from '@server/initializers/constants' +import { buildTaskFileFieldname, createVideoStudioJob, getStudioTaskFilePath, getTaskFileFromReq } from '@server/lib/video-studio' import { HttpStatusCode, VideoState, @@ -75,7 +73,11 @@ async function createEditionTasks (req: express.Request, res: express.Response) tasks: await Bluebird.mapSeries(body.tasks, (t, i) => buildTaskPayload(t, i, files)) } - JobQueue.Instance.createJobAsync({ type: 'video-studio-edition', payload }) + await createVideoStudioJob({ + user: res.locals.oauth.token.User, + payload, + video + }) return res.sendStatus(HttpStatusCode.NO_CONTENT_204) } @@ -124,13 +126,16 @@ async function buildWatermarkTask (task: VideoStudioTaskWatermark, indice: numbe return { name: task.name, options: { - file: destination + file: destination, + watermarkSizeRatio: VIDEO_FILTERS.WATERMARK.SIZE_RATIO, + horitonzalMarginRatio: VIDEO_FILTERS.WATERMARK.HORIZONTAL_MARGIN_RATIO, + verticalMarginRatio: VIDEO_FILTERS.WATERMARK.VERTICAL_MARGIN_RATIO } } } async function moveStudioFileToPersistentTMP (file: string) { - const destination = join(CONFIG.STORAGE.TMP_PERSISTENT_DIR, basename(file)) + const destination = getStudioTaskFilePath(basename(file)) await move(file, destination) -- cgit v1.2.3