aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2023-05-04 15:29:34 +0200
committerChocobozzz <chocobozzz@cpy.re>2023-05-09 08:57:34 +0200
commit5e47f6ab984a7d00782e4c7030afffa1ba480add (patch)
tree1ce586b591a8d71acbc301eba29b9a5e6490439e /server/controllers
parent6a4905602636afd6650c9e6f4d0fcc2105d91100 (diff)
downloadPeerTube-5e47f6ab984a7d00782e4c7030afffa1ba480add.tar.gz
PeerTube-5e47f6ab984a7d00782e4c7030afffa1ba480add.tar.zst
PeerTube-5e47f6ab984a7d00782e4c7030afffa1ba480add.zip
Support studio transcoding in peertube runner
Diffstat (limited to 'server/controllers')
-rw-r--r--server/controllers/api/config.ts5
-rw-r--r--server/controllers/api/runners/jobs-files.ts27
-rw-r--r--server/controllers/api/runners/jobs.ts13
-rw-r--r--server/controllers/api/videos/studio.ts21
4 files changed, 55 insertions, 11 deletions
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 {
274 } 274 }
275 }, 275 },
276 videoStudio: { 276 videoStudio: {
277 enabled: CONFIG.VIDEO_STUDIO.ENABLED 277 enabled: CONFIG.VIDEO_STUDIO.ENABLED,
278 remoteRunners: {
279 enabled: CONFIG.VIDEO_STUDIO.REMOTE_RUNNERS.ENABLED
280 }
278 }, 281 },
279 import: { 282 import: {
280 videos: { 283 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'
2import { logger, loggerTagsFactory } from '@server/helpers/logger' 2import { logger, loggerTagsFactory } from '@server/helpers/logger'
3import { proxifyHLS, proxifyWebTorrentFile } from '@server/lib/object-storage' 3import { proxifyHLS, proxifyWebTorrentFile } from '@server/lib/object-storage'
4import { VideoPathManager } from '@server/lib/video-path-manager' 4import { VideoPathManager } from '@server/lib/video-path-manager'
5import { getStudioTaskFilePath } from '@server/lib/video-studio'
5import { asyncMiddleware } from '@server/middlewares' 6import { asyncMiddleware } from '@server/middlewares'
6import { jobOfRunnerGetValidator } from '@server/middlewares/validators/runners' 7import { jobOfRunnerGetValidator } from '@server/middlewares/validators/runners'
7import { runnerJobGetVideoTranscodingFileValidator } from '@server/middlewares/validators/runners/job-files' 8import {
9 runnerJobGetVideoStudioTaskFileValidator,
10 runnerJobGetVideoTranscodingFileValidator
11} from '@server/middlewares/validators/runners/job-files'
8import { VideoStorage } from '@shared/models' 12import { VideoStorage } from '@shared/models'
9 13
10const lTags = loggerTagsFactory('api', 'runner') 14const lTags = loggerTagsFactory('api', 'runner')
@@ -23,6 +27,13 @@ runnerJobFilesRouter.post('/jobs/:jobUUID/files/videos/:videoId/previews/max-qua
23 getMaxQualityVideoPreview 27 getMaxQualityVideoPreview
24) 28)
25 29
30runnerJobFilesRouter.post('/jobs/:jobUUID/files/videos/:videoId/studio/task-files/:filename',
31 asyncMiddleware(jobOfRunnerGetValidator),
32 asyncMiddleware(runnerJobGetVideoTranscodingFileValidator),
33 runnerJobGetVideoStudioTaskFileValidator,
34 getVideoEditionTaskFile
35)
36
26// --------------------------------------------------------------------------- 37// ---------------------------------------------------------------------------
27 38
28export { 39export {
@@ -82,3 +93,17 @@ function getMaxQualityVideoPreview (req: express.Request, res: express.Response)
82 93
83 return res.sendFile(file.getPath()) 94 return res.sendFile(file.getPath())
84} 95}
96
97function getVideoEditionTaskFile (req: express.Request, res: express.Response) {
98 const runnerJob = res.locals.runnerJob
99 const runner = runnerJob.Runner
100 const video = res.locals.videoAll
101 const filename = req.params.filename
102
103 logger.info(
104 'Get video edition task file %s of video %s of job %s for runner %s', filename, video.uuid, runnerJob.uuid, runner.name,
105 lTags(runner.name, runnerJob.id, runnerJob.type)
106 )
107
108 return res.sendFile(getStudioTaskFilePath(filename))
109}
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 {
17import { 17import {
18 abortRunnerJobValidator, 18 abortRunnerJobValidator,
19 acceptRunnerJobValidator, 19 acceptRunnerJobValidator,
20 cancelRunnerJobValidator,
20 errorRunnerJobValidator, 21 errorRunnerJobValidator,
21 getRunnerFromTokenValidator, 22 getRunnerFromTokenValidator,
22 jobOfRunnerGetValidator, 23 jobOfRunnerGetValidator,
@@ -41,6 +42,7 @@ import {
41 RunnerJobUpdateBody, 42 RunnerJobUpdateBody,
42 RunnerJobUpdatePayload, 43 RunnerJobUpdatePayload,
43 UserRight, 44 UserRight,
45 VideoEditionTranscodingSuccess,
44 VODAudioMergeTranscodingSuccess, 46 VODAudioMergeTranscodingSuccess,
45 VODHLSTranscodingSuccess, 47 VODHLSTranscodingSuccess,
46 VODWebVideoTranscodingSuccess 48 VODWebVideoTranscodingSuccess
@@ -110,6 +112,7 @@ runnerJobsRouter.post('/jobs/:jobUUID/cancel',
110 authenticate, 112 authenticate,
111 ensureUserHasRight(UserRight.MANAGE_RUNNERS), 113 ensureUserHasRight(UserRight.MANAGE_RUNNERS),
112 asyncMiddleware(runnerJobGetValidator), 114 asyncMiddleware(runnerJobGetValidator),
115 cancelRunnerJobValidator,
113 asyncMiddleware(cancelRunnerJob) 116 asyncMiddleware(cancelRunnerJob)
114) 117)
115 118
@@ -297,6 +300,14 @@ const jobSuccessPayloadBuilders: {
297 } 300 }
298 }, 301 },
299 302
303 'video-edition-transcoding': (payload: VideoEditionTranscodingSuccess, files) => {
304 return {
305 ...payload,
306
307 videoFile: files['payload[videoFile]'][0].path
308 }
309 },
310
300 'live-rtmp-hls-transcoding': () => ({}) 311 'live-rtmp-hls-transcoding': () => ({})
301} 312}
302 313
@@ -327,7 +338,7 @@ async function postRunnerJobSuccess (req: express.Request, res: express.Response
327async function cancelRunnerJob (req: express.Request, res: express.Response) { 338async function cancelRunnerJob (req: express.Request, res: express.Response) {
328 const runnerJob = res.locals.runnerJob 339 const runnerJob = res.locals.runnerJob
329 340
330 logger.info('Cancelling job %s (%s)', runnerJob.type, lTags(runnerJob.uuid, runnerJob.type)) 341 logger.info('Cancelling job %s (%s)', runnerJob.uuid, runnerJob.type, lTags(runnerJob.uuid, runnerJob.type))
331 342
332 const RunnerJobHandler = getRunnerJobHandlerClass(runnerJob) 343 const RunnerJobHandler = getRunnerJobHandlerClass(runnerJob)
333 await new RunnerJobHandler().cancel({ runnerJob }) 344 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 @@
1import Bluebird from 'bluebird' 1import Bluebird from 'bluebird'
2import express from 'express' 2import express from 'express'
3import { move } from 'fs-extra' 3import { move } from 'fs-extra'
4import { basename, join } from 'path' 4import { basename } from 'path'
5import { createAnyReqFiles } from '@server/helpers/express-utils' 5import { createAnyReqFiles } from '@server/helpers/express-utils'
6import { CONFIG } from '@server/initializers/config' 6import { MIMETYPES, VIDEO_FILTERS } from '@server/initializers/constants'
7import { MIMETYPES } from '@server/initializers/constants' 7import { buildTaskFileFieldname, createVideoStudioJob, getStudioTaskFilePath, getTaskFileFromReq } from '@server/lib/video-studio'
8import { JobQueue } from '@server/lib/job-queue'
9import { buildTaskFileFieldname, getTaskFileFromReq } from '@server/lib/video-studio'
10import { 8import {
11 HttpStatusCode, 9 HttpStatusCode,
12 VideoState, 10 VideoState,
@@ -75,7 +73,11 @@ async function createEditionTasks (req: express.Request, res: express.Response)
75 tasks: await Bluebird.mapSeries(body.tasks, (t, i) => buildTaskPayload(t, i, files)) 73 tasks: await Bluebird.mapSeries(body.tasks, (t, i) => buildTaskPayload(t, i, files))
76 } 74 }
77 75
78 JobQueue.Instance.createJobAsync({ type: 'video-studio-edition', payload }) 76 await createVideoStudioJob({
77 user: res.locals.oauth.token.User,
78 payload,
79 video
80 })
79 81
80 return res.sendStatus(HttpStatusCode.NO_CONTENT_204) 82 return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
81} 83}
@@ -124,13 +126,16 @@ async function buildWatermarkTask (task: VideoStudioTaskWatermark, indice: numbe
124 return { 126 return {
125 name: task.name, 127 name: task.name,
126 options: { 128 options: {
127 file: destination 129 file: destination,
130 watermarkSizeRatio: VIDEO_FILTERS.WATERMARK.SIZE_RATIO,
131 horitonzalMarginRatio: VIDEO_FILTERS.WATERMARK.HORIZONTAL_MARGIN_RATIO,
132 verticalMarginRatio: VIDEO_FILTERS.WATERMARK.VERTICAL_MARGIN_RATIO
128 } 133 }
129 } 134 }
130} 135}
131 136
132async function moveStudioFileToPersistentTMP (file: string) { 137async function moveStudioFileToPersistentTMP (file: string) {
133 const destination = join(CONFIG.STORAGE.TMP_PERSISTENT_DIR, basename(file)) 138 const destination = getStudioTaskFilePath(basename(file))
134 139
135 await move(file, destination) 140 await move(file, destination)
136 141