aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
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
parent6a4905602636afd6650c9e6f4d0fcc2105d91100 (diff)
downloadPeerTube-5e47f6ab984a7d00782e4c7030afffa1ba480add.tar.gz
PeerTube-5e47f6ab984a7d00782e4c7030afffa1ba480add.tar.zst
PeerTube-5e47f6ab984a7d00782e4c7030afffa1ba480add.zip
Support studio transcoding in peertube runner
Diffstat (limited to 'server')
-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
-rw-r--r--server/helpers/custom-validators/misc.ts8
-rw-r--r--server/helpers/custom-validators/runners/jobs.ts23
-rw-r--r--server/initializers/checker-before-init.ts2
-rw-r--r--server/initializers/config.ts5
-rw-r--r--server/initializers/constants.ts3
-rw-r--r--server/lib/job-queue/handlers/video-studio-edition.ts79
-rw-r--r--server/lib/runners/job-handlers/abstract-job-handler.ts11
-rw-r--r--server/lib/runners/job-handlers/abstract-vod-transcoding-job-handler.ts10
-rw-r--r--server/lib/runners/job-handlers/index.ts3
-rw-r--r--server/lib/runners/job-handlers/live-rtmp-hls-transcoding-job-handler.ts2
-rw-r--r--server/lib/runners/job-handlers/runner-job-handlers.ts4
-rw-r--r--server/lib/runners/job-handlers/video-edition-transcoding-job-handler.ts157
-rw-r--r--server/lib/runners/job-handlers/vod-audio-merge-transcoding-job-handler.ts2
-rw-r--r--server/lib/runners/job-handlers/vod-hls-transcoding-job-handler.ts2
-rw-r--r--server/lib/runners/job-handlers/vod-web-video-transcoding-job-handler.ts2
-rw-r--r--server/lib/runners/runner-urls.ts4
-rw-r--r--server/lib/server-config-manager.ts5
-rw-r--r--server/lib/transcoding/shared/job-builders/abstract-job-builder.ts18
-rw-r--r--server/lib/transcoding/shared/job-builders/transcoding-job-queue-builder.ts3
-rw-r--r--server/lib/transcoding/shared/job-builders/transcoding-runner-job-builder.ts15
-rw-r--r--server/lib/transcoding/transcoding-priority.ts24
-rw-r--r--server/lib/video-studio.ts109
-rw-r--r--server/middlewares/validators/config.ts1
-rw-r--r--server/middlewares/validators/runners/job-files.ts35
-rw-r--r--server/middlewares/validators/runners/jobs.ts22
-rw-r--r--server/tests/api/check-params/config.ts5
-rw-r--r--server/tests/api/check-params/runners.ts211
-rw-r--r--server/tests/api/runners/index.ts1
-rw-r--r--server/tests/api/runners/runner-common.ts12
-rw-r--r--server/tests/api/runners/runner-studio-transcoding.ts168
-rw-r--r--server/tests/api/runners/runner-vod-transcoding.ts16
-rw-r--r--server/tests/api/server/config.ts7
-rw-r--r--server/tests/api/transcoding/video-studio.ts42
-rw-r--r--server/tests/peertube-runner/index.ts1
-rw-r--r--server/tests/peertube-runner/live-transcoding.ts15
-rw-r--r--server/tests/peertube-runner/studio-transcoding.ts116
-rw-r--r--server/tests/peertube-runner/vod-transcoding.ts14
-rw-r--r--server/tests/shared/checks.ts17
-rw-r--r--server/tests/shared/directories.ts21
43 files changed, 1049 insertions, 212 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
diff --git a/server/helpers/custom-validators/misc.ts b/server/helpers/custom-validators/misc.ts
index fa0f469f6..2c4cd1b9f 100644
--- a/server/helpers/custom-validators/misc.ts
+++ b/server/helpers/custom-validators/misc.ts
@@ -15,8 +15,12 @@ function isSafePath (p: string) {
15 }) 15 })
16} 16}
17 17
18function isSafeFilename (filename: string, extension: string) { 18function isSafeFilename (filename: string, extension?: string) {
19 return typeof filename === 'string' && !!filename.match(new RegExp(`^[a-z0-9-]+\\.${extension}$`)) 19 const regex = extension
20 ? new RegExp(`^[a-z0-9-]+\\.${extension}$`)
21 : new RegExp(`^[a-z0-9-]+\\.[a-z0-9]{1,8}$`)
22
23 return typeof filename === 'string' && !!filename.match(regex)
20} 24}
21 25
22function isSafePeerTubeFilenameWithoutExtension (filename: string) { 26function isSafePeerTubeFilenameWithoutExtension (filename: string) {
diff --git a/server/helpers/custom-validators/runners/jobs.ts b/server/helpers/custom-validators/runners/jobs.ts
index 5f755d5bb..934bd37c9 100644
--- a/server/helpers/custom-validators/runners/jobs.ts
+++ b/server/helpers/custom-validators/runners/jobs.ts
@@ -6,6 +6,7 @@ import {
6 RunnerJobSuccessPayload, 6 RunnerJobSuccessPayload,
7 RunnerJobType, 7 RunnerJobType,
8 RunnerJobUpdatePayload, 8 RunnerJobUpdatePayload,
9 VideoEditionTranscodingSuccess,
9 VODAudioMergeTranscodingSuccess, 10 VODAudioMergeTranscodingSuccess,
10 VODHLSTranscodingSuccess, 11 VODHLSTranscodingSuccess,
11 VODWebVideoTranscodingSuccess 12 VODWebVideoTranscodingSuccess
@@ -23,7 +24,8 @@ function isRunnerJobSuccessPayloadValid (value: RunnerJobSuccessPayload, type: R
23 return isRunnerJobVODWebVideoResultPayloadValid(value as VODWebVideoTranscodingSuccess, type, files) || 24 return isRunnerJobVODWebVideoResultPayloadValid(value as VODWebVideoTranscodingSuccess, type, files) ||
24 isRunnerJobVODHLSResultPayloadValid(value as VODHLSTranscodingSuccess, type, files) || 25 isRunnerJobVODHLSResultPayloadValid(value as VODHLSTranscodingSuccess, type, files) ||
25 isRunnerJobVODAudioMergeResultPayloadValid(value as VODHLSTranscodingSuccess, type, files) || 26 isRunnerJobVODAudioMergeResultPayloadValid(value as VODHLSTranscodingSuccess, type, files) ||
26 isRunnerJobLiveRTMPHLSResultPayloadValid(value as LiveRTMPHLSTranscodingSuccess, type) 27 isRunnerJobLiveRTMPHLSResultPayloadValid(value as LiveRTMPHLSTranscodingSuccess, type) ||
28 isRunnerJobVideoEditionResultPayloadValid(value as VideoEditionTranscodingSuccess, type, files)
27} 29}
28 30
29// --------------------------------------------------------------------------- 31// ---------------------------------------------------------------------------
@@ -35,6 +37,7 @@ function isRunnerJobProgressValid (value: string) {
35function isRunnerJobUpdatePayloadValid (value: RunnerJobUpdatePayload, type: RunnerJobType, files: UploadFilesForCheck) { 37function isRunnerJobUpdatePayloadValid (value: RunnerJobUpdatePayload, type: RunnerJobType, files: UploadFilesForCheck) {
36 return isRunnerJobVODWebVideoUpdatePayloadValid(value, type, files) || 38 return isRunnerJobVODWebVideoUpdatePayloadValid(value, type, files) ||
37 isRunnerJobVODHLSUpdatePayloadValid(value, type, files) || 39 isRunnerJobVODHLSUpdatePayloadValid(value, type, files) ||
40 isRunnerJobVideoEditionUpdatePayloadValid(value, type, files) ||
38 isRunnerJobVODAudioMergeUpdatePayloadValid(value, type, files) || 41 isRunnerJobVODAudioMergeUpdatePayloadValid(value, type, files) ||
39 isRunnerJobLiveRTMPHLSUpdatePayloadValid(value, type, files) 42 isRunnerJobLiveRTMPHLSUpdatePayloadValid(value, type, files)
40} 43}
@@ -102,6 +105,15 @@ function isRunnerJobLiveRTMPHLSResultPayloadValid (
102 return type === 'live-rtmp-hls-transcoding' && (!value || (typeof value === 'object' && Object.keys(value).length === 0)) 105 return type === 'live-rtmp-hls-transcoding' && (!value || (typeof value === 'object' && Object.keys(value).length === 0))
103} 106}
104 107
108function isRunnerJobVideoEditionResultPayloadValid (
109 _value: VideoEditionTranscodingSuccess,
110 type: RunnerJobType,
111 files: UploadFilesForCheck
112) {
113 return type === 'video-edition-transcoding' &&
114 isFileValid({ files, field: 'payload[videoFile]', mimeTypeRegex: null, maxSize: null })
115}
116
105// --------------------------------------------------------------------------- 117// ---------------------------------------------------------------------------
106 118
107function isRunnerJobVODWebVideoUpdatePayloadValid ( 119function isRunnerJobVODWebVideoUpdatePayloadValid (
@@ -164,3 +176,12 @@ function isRunnerJobLiveRTMPHLSUpdatePayloadValid (
164 ) 176 )
165 ) 177 )
166} 178}
179
180function isRunnerJobVideoEditionUpdatePayloadValid (
181 value: RunnerJobUpdatePayload,
182 type: RunnerJobType,
183 _files: UploadFilesForCheck
184) {
185 return type === 'video-edition-transcoding' &&
186 (!value || (typeof value === 'object' && Object.keys(value).length === 0))
187}
diff --git a/server/initializers/checker-before-init.ts b/server/initializers/checker-before-init.ts
index 2361aa1eb..2f5a274e4 100644
--- a/server/initializers/checker-before-init.ts
+++ b/server/initializers/checker-before-init.ts
@@ -38,7 +38,7 @@ function checkMissedConfig () {
38 'transcoding.resolutions.0p', 'transcoding.resolutions.144p', 'transcoding.resolutions.240p', 'transcoding.resolutions.360p', 38 'transcoding.resolutions.0p', 'transcoding.resolutions.144p', 'transcoding.resolutions.240p', 'transcoding.resolutions.360p',
39 'transcoding.resolutions.480p', 'transcoding.resolutions.720p', 'transcoding.resolutions.1080p', 'transcoding.resolutions.1440p', 39 'transcoding.resolutions.480p', 'transcoding.resolutions.720p', 'transcoding.resolutions.1080p', 'transcoding.resolutions.1440p',
40 'transcoding.resolutions.2160p', 'transcoding.always_transcode_original_resolution', 'transcoding.remote_runners.enabled', 40 'transcoding.resolutions.2160p', 'transcoding.always_transcode_original_resolution', 'transcoding.remote_runners.enabled',
41 'video_studio.enabled', 41 'video_studio.enabled', 'video_studio.remote_runners.enabled',
42 'remote_runners.stalled_jobs.vod', 'remote_runners.stalled_jobs.live', 42 'remote_runners.stalled_jobs.vod', 'remote_runners.stalled_jobs.live',
43 'import.videos.http.enabled', 'import.videos.torrent.enabled', 'import.videos.concurrency', 'import.videos.timeout', 43 'import.videos.http.enabled', 'import.videos.torrent.enabled', 'import.videos.concurrency', 'import.videos.timeout',
44 'import.video_channel_synchronization.enabled', 'import.video_channel_synchronization.max_per_user', 44 'import.video_channel_synchronization.enabled', 'import.video_channel_synchronization.max_per_user',
diff --git a/server/initializers/config.ts b/server/initializers/config.ts
index f2d8f99b5..9c2705689 100644
--- a/server/initializers/config.ts
+++ b/server/initializers/config.ts
@@ -423,7 +423,10 @@ const CONFIG = {
423 } 423 }
424 }, 424 },
425 VIDEO_STUDIO: { 425 VIDEO_STUDIO: {
426 get ENABLED () { return config.get<boolean>('video_studio.enabled') } 426 get ENABLED () { return config.get<boolean>('video_studio.enabled') },
427 REMOTE_RUNNERS: {
428 get ENABLED () { return config.get<boolean>('video_studio.remote_runners.enabled') }
429 }
427 }, 430 },
428 IMPORT: { 431 IMPORT: {
429 VIDEOS: { 432 VIDEOS: {
diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts
index 279e77421..6a757a0ff 100644
--- a/server/initializers/constants.ts
+++ b/server/initializers/constants.ts
@@ -229,7 +229,8 @@ const REPEAT_JOBS: { [ id in JobType ]?: RepeatOptions } = {
229 } 229 }
230} 230}
231const JOB_PRIORITY = { 231const JOB_PRIORITY = {
232 TRANSCODING: 100 232 TRANSCODING: 100,
233 VIDEO_STUDIO: 150
233} 234}
234 235
235const JOB_REMOVAL_OPTIONS = { 236const JOB_REMOVAL_OPTIONS = {
diff --git a/server/lib/job-queue/handlers/video-studio-edition.ts b/server/lib/job-queue/handlers/video-studio-edition.ts
index 5e8dd4f51..df73caf72 100644
--- a/server/lib/job-queue/handlers/video-studio-edition.ts
+++ b/server/lib/job-queue/handlers/video-studio-edition.ts
@@ -1,25 +1,18 @@
1import { Job } from 'bullmq' 1import { Job } from 'bullmq'
2import { move, remove } from 'fs-extra' 2import { remove } from 'fs-extra'
3import { join } from 'path' 3import { join } from 'path'
4import { getFFmpegCommandWrapperOptions } from '@server/helpers/ffmpeg' 4import { getFFmpegCommandWrapperOptions } from '@server/helpers/ffmpeg'
5import { createTorrentAndSetInfoHashFromPath } from '@server/helpers/webtorrent'
6import { CONFIG } from '@server/initializers/config' 5import { CONFIG } from '@server/initializers/config'
7import { VIDEO_FILTERS } from '@server/initializers/constants'
8import { federateVideoIfNeeded } from '@server/lib/activitypub/videos'
9import { generateWebTorrentVideoFilename } from '@server/lib/paths'
10import { createOptimizeOrMergeAudioJobs } from '@server/lib/transcoding/create-transcoding-job'
11import { VideoTranscodingProfilesManager } from '@server/lib/transcoding/default-transcoding-profiles' 6import { VideoTranscodingProfilesManager } from '@server/lib/transcoding/default-transcoding-profiles'
12import { isAbleToUploadVideo } from '@server/lib/user' 7import { isAbleToUploadVideo } from '@server/lib/user'
13import { buildFileMetadata, removeHLSPlaylist, removeWebTorrentFile } from '@server/lib/video-file'
14import { VideoPathManager } from '@server/lib/video-path-manager' 8import { VideoPathManager } from '@server/lib/video-path-manager'
15import { approximateIntroOutroAdditionalSize, safeCleanupStudioTMPFiles } from '@server/lib/video-studio' 9import { approximateIntroOutroAdditionalSize, onVideoEditionEnded, safeCleanupStudioTMPFiles } from '@server/lib/video-studio'
16import { UserModel } from '@server/models/user/user' 10import { UserModel } from '@server/models/user/user'
17import { VideoModel } from '@server/models/video/video' 11import { VideoModel } from '@server/models/video/video'
18import { VideoFileModel } from '@server/models/video/video-file' 12import { MVideo, MVideoFullLight } from '@server/types/models'
19import { MVideo, MVideoFile, MVideoFullLight, MVideoId, MVideoWithAllFiles } from '@server/types/models' 13import { pick } from '@shared/core-utils'
20import { getLowercaseExtension, pick } from '@shared/core-utils' 14import { buildUUID } from '@shared/extra-utils'
21import { buildUUID, getFileSize } from '@shared/extra-utils' 15import { FFmpegEdition } from '@shared/ffmpeg'
22import { FFmpegEdition, ffprobePromise, getVideoStreamDimensionsInfo, getVideoStreamDuration, getVideoStreamFPS } from '@shared/ffmpeg'
23import { 16import {
24 VideoStudioEditionPayload, 17 VideoStudioEditionPayload,
25 VideoStudioTask, 18 VideoStudioTask,
@@ -46,7 +39,7 @@ async function processVideoStudioEdition (job: Job) {
46 if (!video) { 39 if (!video) {
47 logger.info('Can\'t process job %d, video does not exist.', job.id, lTags) 40 logger.info('Can\'t process job %d, video does not exist.', job.id, lTags)
48 41
49 await safeCleanupStudioTMPFiles(payload) 42 await safeCleanupStudioTMPFiles(payload.tasks)
50 return undefined 43 return undefined
51 } 44 }
52 45
@@ -81,28 +74,9 @@ async function processVideoStudioEdition (job: Job) {
81 74
82 logger.info('Video edition ended for video %s.', video.uuid, lTags) 75 logger.info('Video edition ended for video %s.', video.uuid, lTags)
83 76
84 const newFile = await buildNewFile(video, editionResultPath) 77 await onVideoEditionEnded({ video, editionResultPath, tasks: payload.tasks })
85
86 const outputPath = VideoPathManager.Instance.getFSVideoFileOutputPath(video, newFile)
87 await move(editionResultPath, outputPath)
88
89 await safeCleanupStudioTMPFiles(payload)
90
91 await createTorrentAndSetInfoHashFromPath(video, newFile, outputPath)
92 await removeAllFiles(video, newFile)
93
94 await newFile.save()
95
96 video.duration = await getVideoStreamDuration(outputPath)
97 await video.save()
98
99 await federateVideoIfNeeded(video, false, undefined)
100
101 const user = await UserModel.loadByVideoId(video.id)
102
103 await createOptimizeOrMergeAudioJobs({ video, videoFile: newFile, isNewVideo: false, user, videoFileAlreadyLocked: false })
104 } catch (err) { 78 } catch (err) {
105 await safeCleanupStudioTMPFiles(payload) 79 await safeCleanupStudioTMPFiles(payload.tasks)
106 80
107 throw err 81 throw err
108 } 82 }
@@ -181,44 +155,15 @@ function processAddWatermark (options: TaskProcessorOptions<VideoStudioTaskWater
181 watermarkPath: task.options.file, 155 watermarkPath: task.options.file,
182 156
183 videoFilters: { 157 videoFilters: {
184 watermarkSizeRatio: VIDEO_FILTERS.WATERMARK.SIZE_RATIO, 158 watermarkSizeRatio: task.options.watermarkSizeRatio,
185 horitonzalMarginRatio: VIDEO_FILTERS.WATERMARK.HORIZONTAL_MARGIN_RATIO, 159 horitonzalMarginRatio: task.options.horitonzalMarginRatio,
186 verticalMarginRatio: VIDEO_FILTERS.WATERMARK.VERTICAL_MARGIN_RATIO 160 verticalMarginRatio: task.options.verticalMarginRatio
187 } 161 }
188 }) 162 })
189} 163}
190 164
191// --------------------------------------------------------------------------- 165// ---------------------------------------------------------------------------
192 166
193async function buildNewFile (video: MVideoId, path: string) {
194 const videoFile = new VideoFileModel({
195 extname: getLowercaseExtension(path),
196 size: await getFileSize(path),
197 metadata: await buildFileMetadata(path),
198 videoStreamingPlaylistId: null,
199 videoId: video.id
200 })
201
202 const probe = await ffprobePromise(path)
203
204 videoFile.fps = await getVideoStreamFPS(path, probe)
205 videoFile.resolution = (await getVideoStreamDimensionsInfo(path, probe)).resolution
206
207 videoFile.filename = generateWebTorrentVideoFilename(videoFile.resolution, videoFile.extname)
208
209 return videoFile
210}
211
212async function removeAllFiles (video: MVideoWithAllFiles, webTorrentFileException: MVideoFile) {
213 await removeHLSPlaylist(video)
214
215 for (const file of video.VideoFiles) {
216 if (file.id === webTorrentFileException.id) continue
217
218 await removeWebTorrentFile(video, file.id)
219 }
220}
221
222async function checkUserQuotaOrThrow (video: MVideoFullLight, payload: VideoStudioEditionPayload) { 167async function checkUserQuotaOrThrow (video: MVideoFullLight, payload: VideoStudioEditionPayload) {
223 const user = await UserModel.loadByVideoId(video.id) 168 const user = await UserModel.loadByVideoId(video.id)
224 169
diff --git a/server/lib/runners/job-handlers/abstract-job-handler.ts b/server/lib/runners/job-handlers/abstract-job-handler.ts
index 74b455107..76fd1c5ac 100644
--- a/server/lib/runners/job-handlers/abstract-job-handler.ts
+++ b/server/lib/runners/job-handlers/abstract-job-handler.ts
@@ -1,3 +1,4 @@
1import { throttle } from 'lodash'
1import { retryTransactionWrapper } from '@server/helpers/database-utils' 2import { retryTransactionWrapper } from '@server/helpers/database-utils'
2import { logger, loggerTagsFactory } from '@server/helpers/logger' 3import { logger, loggerTagsFactory } from '@server/helpers/logger'
3import { RUNNER_JOBS } from '@server/initializers/constants' 4import { RUNNER_JOBS } from '@server/initializers/constants'
@@ -14,6 +15,8 @@ import {
14 RunnerJobSuccessPayload, 15 RunnerJobSuccessPayload,
15 RunnerJobType, 16 RunnerJobType,
16 RunnerJobUpdatePayload, 17 RunnerJobUpdatePayload,
18 RunnerJobVideoEditionTranscodingPayload,
19 RunnerJobVideoEditionTranscodingPrivatePayload,
17 RunnerJobVODAudioMergeTranscodingPayload, 20 RunnerJobVODAudioMergeTranscodingPayload,
18 RunnerJobVODAudioMergeTranscodingPrivatePayload, 21 RunnerJobVODAudioMergeTranscodingPrivatePayload,
19 RunnerJobVODHLSTranscodingPayload, 22 RunnerJobVODHLSTranscodingPayload,
@@ -21,7 +24,6 @@ import {
21 RunnerJobVODWebVideoTranscodingPayload, 24 RunnerJobVODWebVideoTranscodingPayload,
22 RunnerJobVODWebVideoTranscodingPrivatePayload 25 RunnerJobVODWebVideoTranscodingPrivatePayload
23} from '@shared/models' 26} from '@shared/models'
24import { throttle } from 'lodash'
25 27
26type CreateRunnerJobArg = 28type CreateRunnerJobArg =
27 { 29 {
@@ -43,6 +45,11 @@ type CreateRunnerJobArg =
43 type: Extract<RunnerJobType, 'live-rtmp-hls-transcoding'> 45 type: Extract<RunnerJobType, 'live-rtmp-hls-transcoding'>
44 payload: RunnerJobLiveRTMPHLSTranscodingPayload 46 payload: RunnerJobLiveRTMPHLSTranscodingPayload
45 privatePayload: RunnerJobLiveRTMPHLSTranscodingPrivatePayload 47 privatePayload: RunnerJobLiveRTMPHLSTranscodingPrivatePayload
48 } |
49 {
50 type: Extract<RunnerJobType, 'video-edition-transcoding'>
51 payload: RunnerJobVideoEditionTranscodingPayload
52 privatePayload: RunnerJobVideoEditionTranscodingPrivatePayload
46 } 53 }
47 54
48export abstract class AbstractJobHandler <C, U extends RunnerJobUpdatePayload, S extends RunnerJobSuccessPayload> { 55export abstract class AbstractJobHandler <C, U extends RunnerJobUpdatePayload, S extends RunnerJobSuccessPayload> {
@@ -62,6 +69,8 @@ export abstract class AbstractJobHandler <C, U extends RunnerJobUpdatePayload, S
62 }): Promise<MRunnerJob> { 69 }): Promise<MRunnerJob> {
63 const { priority, dependsOnRunnerJob } = options 70 const { priority, dependsOnRunnerJob } = options
64 71
72 logger.debug('Creating runner job', { options, ...this.lTags(options.type) })
73
65 const runnerJob = new RunnerJobModel({ 74 const runnerJob = new RunnerJobModel({
66 ...pick(options, [ 'type', 'payload', 'privatePayload' ]), 75 ...pick(options, [ 'type', 'payload', 'privatePayload' ]),
67 76
diff --git a/server/lib/runners/job-handlers/abstract-vod-transcoding-job-handler.ts b/server/lib/runners/job-handlers/abstract-vod-transcoding-job-handler.ts
index 517645848..a910ae383 100644
--- a/server/lib/runners/job-handlers/abstract-vod-transcoding-job-handler.ts
+++ b/server/lib/runners/job-handlers/abstract-vod-transcoding-job-handler.ts
@@ -4,27 +4,19 @@ import { logger } from '@server/helpers/logger'
4import { moveToFailedTranscodingState, moveToNextState } from '@server/lib/video-state' 4import { moveToFailedTranscodingState, moveToNextState } from '@server/lib/video-state'
5import { VideoJobInfoModel } from '@server/models/video/video-job-info' 5import { VideoJobInfoModel } from '@server/models/video/video-job-info'
6import { MRunnerJob } from '@server/types/models/runners' 6import { MRunnerJob } from '@server/types/models/runners'
7import { 7import { RunnerJobSuccessPayload, RunnerJobUpdatePayload, RunnerJobVODPrivatePayload } from '@shared/models'
8 LiveRTMPHLSTranscodingUpdatePayload,
9 RunnerJobSuccessPayload,
10 RunnerJobUpdatePayload,
11 RunnerJobVODPrivatePayload
12} from '@shared/models'
13import { AbstractJobHandler } from './abstract-job-handler' 8import { AbstractJobHandler } from './abstract-job-handler'
14import { loadTranscodingRunnerVideo } from './shared' 9import { loadTranscodingRunnerVideo } from './shared'
15 10
16// eslint-disable-next-line max-len 11// eslint-disable-next-line max-len
17export abstract class AbstractVODTranscodingJobHandler <C, U extends RunnerJobUpdatePayload, S extends RunnerJobSuccessPayload> extends AbstractJobHandler<C, U, S> { 12export abstract class AbstractVODTranscodingJobHandler <C, U extends RunnerJobUpdatePayload, S extends RunnerJobSuccessPayload> extends AbstractJobHandler<C, U, S> {
18 13
19 // ---------------------------------------------------------------------------
20
21 protected isAbortSupported () { 14 protected isAbortSupported () {
22 return true 15 return true
23 } 16 }
24 17
25 protected specificUpdate (_options: { 18 protected specificUpdate (_options: {
26 runnerJob: MRunnerJob 19 runnerJob: MRunnerJob
27 updatePayload?: LiveRTMPHLSTranscodingUpdatePayload
28 }) { 20 }) {
29 // empty 21 // empty
30 } 22 }
diff --git a/server/lib/runners/job-handlers/index.ts b/server/lib/runners/job-handlers/index.ts
index 0fca72b9a..a40cee865 100644
--- a/server/lib/runners/job-handlers/index.ts
+++ b/server/lib/runners/job-handlers/index.ts
@@ -1,6 +1,7 @@
1export * from './abstract-job-handler' 1export * from './abstract-job-handler'
2export * from './live-rtmp-hls-transcoding-job-handler' 2export * from './live-rtmp-hls-transcoding-job-handler'
3export * from './runner-job-handlers'
4export * from './video-edition-transcoding-job-handler'
3export * from './vod-audio-merge-transcoding-job-handler' 5export * from './vod-audio-merge-transcoding-job-handler'
4export * from './vod-hls-transcoding-job-handler' 6export * from './vod-hls-transcoding-job-handler'
5export * from './vod-web-video-transcoding-job-handler' 7export * from './vod-web-video-transcoding-job-handler'
6export * from './runner-job-handlers'
diff --git a/server/lib/runners/job-handlers/live-rtmp-hls-transcoding-job-handler.ts b/server/lib/runners/job-handlers/live-rtmp-hls-transcoding-job-handler.ts
index c3d0e427d..48a70d891 100644
--- a/server/lib/runners/job-handlers/live-rtmp-hls-transcoding-job-handler.ts
+++ b/server/lib/runners/job-handlers/live-rtmp-hls-transcoding-job-handler.ts
@@ -70,7 +70,7 @@ export class LiveRTMPHLSTranscodingJobHandler extends AbstractJobHandler<CreateO
70 70
71 // --------------------------------------------------------------------------- 71 // ---------------------------------------------------------------------------
72 72
73 async specificUpdate (options: { 73 protected async specificUpdate (options: {
74 runnerJob: MRunnerJob 74 runnerJob: MRunnerJob
75 updatePayload: LiveRTMPHLSTranscodingUpdatePayload 75 updatePayload: LiveRTMPHLSTranscodingUpdatePayload
76 }) { 76 }) {
diff --git a/server/lib/runners/job-handlers/runner-job-handlers.ts b/server/lib/runners/job-handlers/runner-job-handlers.ts
index 7bad1bc77..4ea6684ea 100644
--- a/server/lib/runners/job-handlers/runner-job-handlers.ts
+++ b/server/lib/runners/job-handlers/runner-job-handlers.ts
@@ -2,6 +2,7 @@ import { MRunnerJob } from '@server/types/models/runners'
2import { RunnerJobSuccessPayload, RunnerJobType, RunnerJobUpdatePayload } from '@shared/models' 2import { RunnerJobSuccessPayload, RunnerJobType, RunnerJobUpdatePayload } from '@shared/models'
3import { AbstractJobHandler } from './abstract-job-handler' 3import { AbstractJobHandler } from './abstract-job-handler'
4import { LiveRTMPHLSTranscodingJobHandler } from './live-rtmp-hls-transcoding-job-handler' 4import { LiveRTMPHLSTranscodingJobHandler } from './live-rtmp-hls-transcoding-job-handler'
5import { VideoEditionTranscodingJobHandler } from './video-edition-transcoding-job-handler'
5import { VODAudioMergeTranscodingJobHandler } from './vod-audio-merge-transcoding-job-handler' 6import { VODAudioMergeTranscodingJobHandler } from './vod-audio-merge-transcoding-job-handler'
6import { VODHLSTranscodingJobHandler } from './vod-hls-transcoding-job-handler' 7import { VODHLSTranscodingJobHandler } from './vod-hls-transcoding-job-handler'
7import { VODWebVideoTranscodingJobHandler } from './vod-web-video-transcoding-job-handler' 8import { VODWebVideoTranscodingJobHandler } from './vod-web-video-transcoding-job-handler'
@@ -10,7 +11,8 @@ const processors: Record<RunnerJobType, new() => AbstractJobHandler<unknown, Run
10 'vod-web-video-transcoding': VODWebVideoTranscodingJobHandler, 11 'vod-web-video-transcoding': VODWebVideoTranscodingJobHandler,
11 'vod-hls-transcoding': VODHLSTranscodingJobHandler, 12 'vod-hls-transcoding': VODHLSTranscodingJobHandler,
12 'vod-audio-merge-transcoding': VODAudioMergeTranscodingJobHandler, 13 'vod-audio-merge-transcoding': VODAudioMergeTranscodingJobHandler,
13 'live-rtmp-hls-transcoding': LiveRTMPHLSTranscodingJobHandler 14 'live-rtmp-hls-transcoding': LiveRTMPHLSTranscodingJobHandler,
15 'video-edition-transcoding': VideoEditionTranscodingJobHandler
14} 16}
15 17
16export function getRunnerJobHandlerClass (job: MRunnerJob) { 18export function getRunnerJobHandlerClass (job: MRunnerJob) {
diff --git a/server/lib/runners/job-handlers/video-edition-transcoding-job-handler.ts b/server/lib/runners/job-handlers/video-edition-transcoding-job-handler.ts
new file mode 100644
index 000000000..39a755c48
--- /dev/null
+++ b/server/lib/runners/job-handlers/video-edition-transcoding-job-handler.ts
@@ -0,0 +1,157 @@
1
2import { basename } from 'path'
3import { logger } from '@server/helpers/logger'
4import { onVideoEditionEnded, safeCleanupStudioTMPFiles } from '@server/lib/video-studio'
5import { MVideo } from '@server/types/models'
6import { MRunnerJob } from '@server/types/models/runners'
7import { buildUUID } from '@shared/extra-utils'
8import {
9 isVideoStudioTaskIntro,
10 isVideoStudioTaskOutro,
11 isVideoStudioTaskWatermark,
12 RunnerJobState,
13 RunnerJobUpdatePayload,
14 RunnerJobVideoEditionTranscodingPayload,
15 RunnerJobVideoEditionTranscodingPrivatePayload,
16 VideoEditionTranscodingSuccess,
17 VideoState,
18 VideoStudioTaskPayload
19} from '@shared/models'
20import { generateRunnerEditionTranscodingVideoInputFileUrl, generateRunnerTranscodingVideoInputFileUrl } from '../runner-urls'
21import { AbstractJobHandler } from './abstract-job-handler'
22import { loadTranscodingRunnerVideo } from './shared'
23
24type CreateOptions = {
25 video: MVideo
26 tasks: VideoStudioTaskPayload[]
27 priority: number
28}
29
30// eslint-disable-next-line max-len
31export class VideoEditionTranscodingJobHandler extends AbstractJobHandler<CreateOptions, RunnerJobUpdatePayload, VideoEditionTranscodingSuccess> {
32
33 async create (options: CreateOptions) {
34 const { video, priority, tasks } = options
35
36 const jobUUID = buildUUID()
37 const payload: RunnerJobVideoEditionTranscodingPayload = {
38 input: {
39 videoFileUrl: generateRunnerTranscodingVideoInputFileUrl(jobUUID, video.uuid)
40 },
41 tasks: tasks.map(t => {
42 if (isVideoStudioTaskIntro(t) || isVideoStudioTaskOutro(t)) {
43 return {
44 ...t,
45
46 options: {
47 ...t.options,
48
49 file: generateRunnerEditionTranscodingVideoInputFileUrl(jobUUID, video.uuid, basename(t.options.file))
50 }
51 }
52 }
53
54 if (isVideoStudioTaskWatermark(t)) {
55 return {
56 ...t,
57
58 options: {
59 ...t.options,
60
61 file: generateRunnerEditionTranscodingVideoInputFileUrl(jobUUID, video.uuid, basename(t.options.file))
62 }
63 }
64 }
65
66 return t
67 })
68 }
69
70 const privatePayload: RunnerJobVideoEditionTranscodingPrivatePayload = {
71 videoUUID: video.uuid,
72 originalTasks: tasks
73 }
74
75 const job = await this.createRunnerJob({
76 type: 'video-edition-transcoding',
77 jobUUID,
78 payload,
79 privatePayload,
80 priority
81 })
82
83 return job
84 }
85
86 // ---------------------------------------------------------------------------
87
88 protected isAbortSupported () {
89 return true
90 }
91
92 protected specificUpdate (_options: {
93 runnerJob: MRunnerJob
94 }) {
95 // empty
96 }
97
98 protected specificAbort (_options: {
99 runnerJob: MRunnerJob
100 }) {
101 // empty
102 }
103
104 protected async specificComplete (options: {
105 runnerJob: MRunnerJob
106 resultPayload: VideoEditionTranscodingSuccess
107 }) {
108 const { runnerJob, resultPayload } = options
109 const privatePayload = runnerJob.privatePayload as RunnerJobVideoEditionTranscodingPrivatePayload
110
111 const video = await loadTranscodingRunnerVideo(runnerJob, this.lTags)
112 if (!video) {
113 await safeCleanupStudioTMPFiles(privatePayload.originalTasks)
114
115 }
116
117 const videoFilePath = resultPayload.videoFile as string
118
119 await onVideoEditionEnded({ video, editionResultPath: videoFilePath, tasks: privatePayload.originalTasks })
120
121 logger.info(
122 'Runner video edition transcoding job %s for %s ended.',
123 runnerJob.uuid, video.uuid, this.lTags(video.uuid, runnerJob.uuid)
124 )
125 }
126
127 protected specificError (options: {
128 runnerJob: MRunnerJob
129 nextState: RunnerJobState
130 }) {
131 if (options.nextState === RunnerJobState.ERRORED) {
132 return this.specificErrorOrCancel(options)
133 }
134
135 return Promise.resolve()
136 }
137
138 protected specificCancel (options: {
139 runnerJob: MRunnerJob
140 }) {
141 return this.specificErrorOrCancel(options)
142 }
143
144 private async specificErrorOrCancel (options: {
145 runnerJob: MRunnerJob
146 }) {
147 const { runnerJob } = options
148
149 const payload = runnerJob.privatePayload as RunnerJobVideoEditionTranscodingPrivatePayload
150 await safeCleanupStudioTMPFiles(payload.originalTasks)
151
152 const video = await loadTranscodingRunnerVideo(options.runnerJob, this.lTags)
153 if (!video) return
154
155 return video.setNewState(VideoState.PUBLISHED, false, undefined)
156 }
157}
diff --git a/server/lib/runners/job-handlers/vod-audio-merge-transcoding-job-handler.ts b/server/lib/runners/job-handlers/vod-audio-merge-transcoding-job-handler.ts
index a7b33f87e..5f247d792 100644
--- a/server/lib/runners/job-handlers/vod-audio-merge-transcoding-job-handler.ts
+++ b/server/lib/runners/job-handlers/vod-audio-merge-transcoding-job-handler.ts
@@ -64,7 +64,7 @@ export class VODAudioMergeTranscodingJobHandler extends AbstractVODTranscodingJo
64 64
65 // --------------------------------------------------------------------------- 65 // ---------------------------------------------------------------------------
66 66
67 async specificComplete (options: { 67 protected async specificComplete (options: {
68 runnerJob: MRunnerJob 68 runnerJob: MRunnerJob
69 resultPayload: VODAudioMergeTranscodingSuccess 69 resultPayload: VODAudioMergeTranscodingSuccess
70 }) { 70 }) {
diff --git a/server/lib/runners/job-handlers/vod-hls-transcoding-job-handler.ts b/server/lib/runners/job-handlers/vod-hls-transcoding-job-handler.ts
index 02566b9d5..cc94bcbda 100644
--- a/server/lib/runners/job-handlers/vod-hls-transcoding-job-handler.ts
+++ b/server/lib/runners/job-handlers/vod-hls-transcoding-job-handler.ts
@@ -71,7 +71,7 @@ export class VODHLSTranscodingJobHandler extends AbstractVODTranscodingJobHandle
71 71
72 // --------------------------------------------------------------------------- 72 // ---------------------------------------------------------------------------
73 73
74 async specificComplete (options: { 74 protected async specificComplete (options: {
75 runnerJob: MRunnerJob 75 runnerJob: MRunnerJob
76 resultPayload: VODHLSTranscodingSuccess 76 resultPayload: VODHLSTranscodingSuccess
77 }) { 77 }) {
diff --git a/server/lib/runners/job-handlers/vod-web-video-transcoding-job-handler.ts b/server/lib/runners/job-handlers/vod-web-video-transcoding-job-handler.ts
index 57761a7a1..663d3306e 100644
--- a/server/lib/runners/job-handlers/vod-web-video-transcoding-job-handler.ts
+++ b/server/lib/runners/job-handlers/vod-web-video-transcoding-job-handler.ts
@@ -62,7 +62,7 @@ export class VODWebVideoTranscodingJobHandler extends AbstractVODTranscodingJobH
62 62
63 // --------------------------------------------------------------------------- 63 // ---------------------------------------------------------------------------
64 64
65 async specificComplete (options: { 65 protected async specificComplete (options: {
66 runnerJob: MRunnerJob 66 runnerJob: MRunnerJob
67 resultPayload: VODWebVideoTranscodingSuccess 67 resultPayload: VODWebVideoTranscodingSuccess
68 }) { 68 }) {
diff --git a/server/lib/runners/runner-urls.ts b/server/lib/runners/runner-urls.ts
index 329fb1170..a27060b33 100644
--- a/server/lib/runners/runner-urls.ts
+++ b/server/lib/runners/runner-urls.ts
@@ -7,3 +7,7 @@ export function generateRunnerTranscodingVideoInputFileUrl (jobUUID: string, vid
7export function generateRunnerTranscodingVideoPreviewFileUrl (jobUUID: string, videoUUID: string) { 7export function generateRunnerTranscodingVideoPreviewFileUrl (jobUUID: string, videoUUID: string) {
8 return WEBSERVER.URL + '/api/v1/runners/jobs/' + jobUUID + '/files/videos/' + videoUUID + '/previews/max-quality' 8 return WEBSERVER.URL + '/api/v1/runners/jobs/' + jobUUID + '/files/videos/' + videoUUID + '/previews/max-quality'
9} 9}
10
11export function generateRunnerEditionTranscodingVideoInputFileUrl (jobUUID: string, videoUUID: string, filename: string) {
12 return WEBSERVER.URL + '/api/v1/runners/jobs/' + jobUUID + '/files/videos/' + videoUUID + '/studio/task-files/' + filename
13}
diff --git a/server/lib/server-config-manager.ts b/server/lib/server-config-manager.ts
index ba7916363..924adb337 100644
--- a/server/lib/server-config-manager.ts
+++ b/server/lib/server-config-manager.ts
@@ -166,7 +166,10 @@ class ServerConfigManager {
166 } 166 }
167 }, 167 },
168 videoStudio: { 168 videoStudio: {
169 enabled: CONFIG.VIDEO_STUDIO.ENABLED 169 enabled: CONFIG.VIDEO_STUDIO.ENABLED,
170 remoteRunners: {
171 enabled: CONFIG.VIDEO_STUDIO.REMOTE_RUNNERS.ENABLED
172 }
170 }, 173 },
171 import: { 174 import: {
172 videos: { 175 videos: {
diff --git a/server/lib/transcoding/shared/job-builders/abstract-job-builder.ts b/server/lib/transcoding/shared/job-builders/abstract-job-builder.ts
index 576e786d5..80dc05bfb 100644
--- a/server/lib/transcoding/shared/job-builders/abstract-job-builder.ts
+++ b/server/lib/transcoding/shared/job-builders/abstract-job-builder.ts
@@ -1,6 +1,4 @@
1 1
2import { JOB_PRIORITY } from '@server/initializers/constants'
3import { VideoModel } from '@server/models/video/video'
4import { MUserId, MVideoFile, MVideoFullLight } from '@server/types/models' 2import { MUserId, MVideoFile, MVideoFullLight } from '@server/types/models'
5 3
6export abstract class AbstractJobBuilder { 4export abstract class AbstractJobBuilder {
@@ -20,20 +18,4 @@ export abstract class AbstractJobBuilder {
20 isNewVideo: boolean 18 isNewVideo: boolean
21 user: MUserId | null 19 user: MUserId | null
22 }): Promise<any> 20 }): Promise<any>
23
24 protected async getTranscodingJobPriority (options: {
25 user: MUserId
26 fallback: number
27 }) {
28 const { user, fallback } = options
29
30 if (!user) return fallback
31
32 const now = new Date()
33 const lastWeek = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 7)
34
35 const videoUploadedByUser = await VideoModel.countVideosUploadedByUserSince(user.id, lastWeek)
36
37 return JOB_PRIORITY.TRANSCODING + videoUploadedByUser
38 }
39} 21}
diff --git a/server/lib/transcoding/shared/job-builders/transcoding-job-queue-builder.ts b/server/lib/transcoding/shared/job-builders/transcoding-job-queue-builder.ts
index 5a9c93ee5..29ee2ca61 100644
--- a/server/lib/transcoding/shared/job-builders/transcoding-job-queue-builder.ts
+++ b/server/lib/transcoding/shared/job-builders/transcoding-job-queue-builder.ts
@@ -16,6 +16,7 @@ import {
16 OptimizeTranscodingPayload, 16 OptimizeTranscodingPayload,
17 VideoTranscodingPayload 17 VideoTranscodingPayload
18} from '@shared/models' 18} from '@shared/models'
19import { getTranscodingJobPriority } from '../../transcoding-priority'
19import { canDoQuickTranscode } from '../../transcoding-quick-transcode' 20import { canDoQuickTranscode } from '../../transcoding-quick-transcode'
20import { computeResolutionsToTranscode } from '../../transcoding-resolutions' 21import { computeResolutionsToTranscode } from '../../transcoding-resolutions'
21import { AbstractJobBuilder } from './abstract-job-builder' 22import { AbstractJobBuilder } from './abstract-job-builder'
@@ -178,7 +179,7 @@ export class TranscodingJobQueueBuilder extends AbstractJobBuilder {
178 179
179 return { 180 return {
180 type: 'video-transcoding' as 'video-transcoding', 181 type: 'video-transcoding' as 'video-transcoding',
181 priority: await this.getTranscodingJobPriority({ user, fallback: undefined }), 182 priority: await getTranscodingJobPriority({ user, type: 'vod', fallback: undefined }),
182 payload 183 payload
183 } 184 }
184 } 185 }
diff --git a/server/lib/transcoding/shared/job-builders/transcoding-runner-job-builder.ts b/server/lib/transcoding/shared/job-builders/transcoding-runner-job-builder.ts
index 274dce21b..90b035402 100644
--- a/server/lib/transcoding/shared/job-builders/transcoding-runner-job-builder.ts
+++ b/server/lib/transcoding/shared/job-builders/transcoding-runner-job-builder.ts
@@ -8,6 +8,7 @@ import { VideoPathManager } from '@server/lib/video-path-manager'
8import { MUserId, MVideoFile, MVideoFullLight, MVideoWithFileThumbnail } from '@server/types/models' 8import { MUserId, MVideoFile, MVideoFullLight, MVideoWithFileThumbnail } from '@server/types/models'
9import { MRunnerJob } from '@server/types/models/runners' 9import { MRunnerJob } from '@server/types/models/runners'
10import { ffprobePromise, getVideoStreamDimensionsInfo, getVideoStreamFPS, hasAudioStream, isAudioFile } from '@shared/ffmpeg' 10import { ffprobePromise, getVideoStreamDimensionsInfo, getVideoStreamFPS, hasAudioStream, isAudioFile } from '@shared/ffmpeg'
11import { getTranscodingJobPriority } from '../../transcoding-priority'
11import { computeResolutionsToTranscode } from '../../transcoding-resolutions' 12import { computeResolutionsToTranscode } from '../../transcoding-resolutions'
12import { AbstractJobBuilder } from './abstract-job-builder' 13import { AbstractJobBuilder } from './abstract-job-builder'
13 14
@@ -49,7 +50,7 @@ export class TranscodingRunnerJobBuilder extends AbstractJobBuilder {
49 : resolution 50 : resolution
50 51
51 const fps = computeOutputFPS({ inputFPS, resolution: maxResolution }) 52 const fps = computeOutputFPS({ inputFPS, resolution: maxResolution })
52 const priority = await this.getTranscodingJobPriority({ user, fallback: 0 }) 53 const priority = await getTranscodingJobPriority({ user, type: 'vod', fallback: 0 })
53 54
54 const mainRunnerJob = videoFile.isAudio() 55 const mainRunnerJob = videoFile.isAudio()
55 ? await new VODAudioMergeTranscodingJobHandler().create({ video, resolution: maxResolution, fps, isNewVideo, priority }) 56 ? await new VODAudioMergeTranscodingJobHandler().create({ video, resolution: maxResolution, fps, isNewVideo, priority })
@@ -63,7 +64,7 @@ export class TranscodingRunnerJobBuilder extends AbstractJobBuilder {
63 fps, 64 fps,
64 isNewVideo, 65 isNewVideo,
65 dependsOnRunnerJob: mainRunnerJob, 66 dependsOnRunnerJob: mainRunnerJob,
66 priority: await this.getTranscodingJobPriority({ user, fallback: 0 }) 67 priority: await getTranscodingJobPriority({ user, type: 'vod', fallback: 0 })
67 }) 68 })
68 } 69 }
69 70
@@ -96,7 +97,7 @@ export class TranscodingRunnerJobBuilder extends AbstractJobBuilder {
96 const maxResolution = Math.max(...resolutions) 97 const maxResolution = Math.max(...resolutions)
97 const { fps: inputFPS } = await video.probeMaxQualityFile() 98 const { fps: inputFPS } = await video.probeMaxQualityFile()
98 const maxFPS = computeOutputFPS({ inputFPS, resolution: maxResolution }) 99 const maxFPS = computeOutputFPS({ inputFPS, resolution: maxResolution })
99 const priority = await this.getTranscodingJobPriority({ user, fallback: 0 }) 100 const priority = await getTranscodingJobPriority({ user, type: 'vod', fallback: 0 })
100 101
101 const childrenResolutions = resolutions.filter(r => r !== maxResolution) 102 const childrenResolutions = resolutions.filter(r => r !== maxResolution)
102 103
@@ -121,7 +122,7 @@ export class TranscodingRunnerJobBuilder extends AbstractJobBuilder {
121 isNewVideo, 122 isNewVideo,
122 deleteWebVideoFiles: false, 123 deleteWebVideoFiles: false,
123 dependsOnRunnerJob, 124 dependsOnRunnerJob,
124 priority: await this.getTranscodingJobPriority({ user, fallback: 0 }) 125 priority: await getTranscodingJobPriority({ user, type: 'vod', fallback: 0 })
125 }) 126 })
126 continue 127 continue
127 } 128 }
@@ -133,7 +134,7 @@ export class TranscodingRunnerJobBuilder extends AbstractJobBuilder {
133 fps, 134 fps,
134 isNewVideo, 135 isNewVideo,
135 dependsOnRunnerJob, 136 dependsOnRunnerJob,
136 priority: await this.getTranscodingJobPriority({ user, fallback: 0 }) 137 priority: await getTranscodingJobPriority({ user, type: 'vod', fallback: 0 })
137 }) 138 })
138 continue 139 continue
139 } 140 }
@@ -172,7 +173,7 @@ export class TranscodingRunnerJobBuilder extends AbstractJobBuilder {
172 fps, 173 fps,
173 isNewVideo, 174 isNewVideo,
174 dependsOnRunnerJob: mainRunnerJob, 175 dependsOnRunnerJob: mainRunnerJob,
175 priority: await this.getTranscodingJobPriority({ user, fallback: 0 }) 176 priority: await getTranscodingJobPriority({ user, type: 'vod', fallback: 0 })
176 }) 177 })
177 } 178 }
178 179
@@ -184,7 +185,7 @@ export class TranscodingRunnerJobBuilder extends AbstractJobBuilder {
184 isNewVideo, 185 isNewVideo,
185 deleteWebVideoFiles: false, 186 deleteWebVideoFiles: false,
186 dependsOnRunnerJob: mainRunnerJob, 187 dependsOnRunnerJob: mainRunnerJob,
187 priority: await this.getTranscodingJobPriority({ user, fallback: 0 }) 188 priority: await getTranscodingJobPriority({ user, type: 'vod', fallback: 0 })
188 }) 189 })
189 } 190 }
190 } 191 }
diff --git a/server/lib/transcoding/transcoding-priority.ts b/server/lib/transcoding/transcoding-priority.ts
new file mode 100644
index 000000000..82ab6f2f1
--- /dev/null
+++ b/server/lib/transcoding/transcoding-priority.ts
@@ -0,0 +1,24 @@
1import { JOB_PRIORITY } from '@server/initializers/constants'
2import { VideoModel } from '@server/models/video/video'
3import { MUserId } from '@server/types/models'
4
5export async function getTranscodingJobPriority (options: {
6 user: MUserId
7 fallback: number
8 type: 'vod' | 'studio'
9}) {
10 const { user, fallback, type } = options
11
12 if (!user) return fallback
13
14 const now = new Date()
15 const lastWeek = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 7)
16
17 const videoUploadedByUser = await VideoModel.countVideosUploadedByUserSince(user.id, lastWeek)
18
19 const base = type === 'vod'
20 ? JOB_PRIORITY.TRANSCODING
21 : JOB_PRIORITY.VIDEO_STUDIO
22
23 return base + videoUploadedByUser
24}
diff --git a/server/lib/video-studio.ts b/server/lib/video-studio.ts
index beda326a0..2c993faeb 100644
--- a/server/lib/video-studio.ts
+++ b/server/lib/video-studio.ts
@@ -1,19 +1,38 @@
1import { logger } from '@server/helpers/logger' 1import { move, remove } from 'fs-extra'
2import { MVideoFullLight } from '@server/types/models' 2import { join } from 'path'
3import { logger, loggerTagsFactory } from '@server/helpers/logger'
4import { createTorrentAndSetInfoHashFromPath } from '@server/helpers/webtorrent'
5import { CONFIG } from '@server/initializers/config'
6import { UserModel } from '@server/models/user/user'
7import { MUser, MVideo, MVideoFile, MVideoFullLight, MVideoWithAllFiles } from '@server/types/models'
3import { getVideoStreamDuration } from '@shared/ffmpeg' 8import { getVideoStreamDuration } from '@shared/ffmpeg'
4import { VideoStudioEditionPayload, VideoStudioTask } from '@shared/models' 9import { VideoStudioEditionPayload, VideoStudioTask, VideoStudioTaskPayload } from '@shared/models'
5import { remove } from 'fs-extra' 10import { federateVideoIfNeeded } from './activitypub/videos'
11import { JobQueue } from './job-queue'
12import { VideoEditionTranscodingJobHandler } from './runners'
13import { createOptimizeOrMergeAudioJobs } from './transcoding/create-transcoding-job'
14import { getTranscodingJobPriority } from './transcoding/transcoding-priority'
15import { buildNewFile, removeHLSPlaylist, removeWebTorrentFile } from './video-file'
16import { VideoPathManager } from './video-path-manager'
6 17
7function buildTaskFileFieldname (indice: number, fieldName = 'file') { 18const lTags = loggerTagsFactory('video-edition')
19
20export function buildTaskFileFieldname (indice: number, fieldName = 'file') {
8 return `tasks[${indice}][options][${fieldName}]` 21 return `tasks[${indice}][options][${fieldName}]`
9} 22}
10 23
11function getTaskFileFromReq (files: Express.Multer.File[], indice: number, fieldName = 'file') { 24export function getTaskFileFromReq (files: Express.Multer.File[], indice: number, fieldName = 'file') {
12 return files.find(f => f.fieldname === buildTaskFileFieldname(indice, fieldName)) 25 return files.find(f => f.fieldname === buildTaskFileFieldname(indice, fieldName))
13} 26}
14 27
15async function safeCleanupStudioTMPFiles (payload: VideoStudioEditionPayload) { 28export function getStudioTaskFilePath (filename: string) {
16 for (const task of payload.tasks) { 29 return join(CONFIG.STORAGE.TMP_PERSISTENT_DIR, filename)
30}
31
32export async function safeCleanupStudioTMPFiles (tasks: VideoStudioTaskPayload[]) {
33 logger.info('Removing studio task files', { tasks, ...lTags() })
34
35 for (const task of tasks) {
17 try { 36 try {
18 if (task.name === 'add-intro' || task.name === 'add-outro') { 37 if (task.name === 'add-intro' || task.name === 'add-outro') {
19 await remove(task.options.file) 38 await remove(task.options.file)
@@ -26,7 +45,13 @@ async function safeCleanupStudioTMPFiles (payload: VideoStudioEditionPayload) {
26 } 45 }
27} 46}
28 47
29async function approximateIntroOutroAdditionalSize (video: MVideoFullLight, tasks: VideoStudioTask[], fileFinder: (i: number) => string) { 48// ---------------------------------------------------------------------------
49
50export async function approximateIntroOutroAdditionalSize (
51 video: MVideoFullLight,
52 tasks: VideoStudioTask[],
53 fileFinder: (i: number) => string
54) {
30 let additionalDuration = 0 55 let additionalDuration = 0
31 56
32 for (let i = 0; i < tasks.length; i++) { 57 for (let i = 0; i < tasks.length; i++) {
@@ -41,9 +66,65 @@ async function approximateIntroOutroAdditionalSize (video: MVideoFullLight, task
41 return (video.getMaxQualityFile().size / video.duration) * additionalDuration 66 return (video.getMaxQualityFile().size / video.duration) * additionalDuration
42} 67}
43 68
44export { 69// ---------------------------------------------------------------------------
45 approximateIntroOutroAdditionalSize, 70
46 buildTaskFileFieldname, 71export async function createVideoStudioJob (options: {
47 getTaskFileFromReq, 72 video: MVideo
48 safeCleanupStudioTMPFiles 73 user: MUser
74 payload: VideoStudioEditionPayload
75}) {
76 const { video, user, payload } = options
77
78 const priority = await getTranscodingJobPriority({ user, type: 'studio', fallback: 0 })
79
80 if (CONFIG.VIDEO_STUDIO.REMOTE_RUNNERS.ENABLED) {
81 await new VideoEditionTranscodingJobHandler().create({ video, tasks: payload.tasks, priority })
82 return
83 }
84
85 await JobQueue.Instance.createJob({ type: 'video-studio-edition', payload, priority })
86}
87
88export async function onVideoEditionEnded (options: {
89 editionResultPath: string
90 tasks: VideoStudioTaskPayload[]
91 video: MVideoFullLight
92}) {
93 const { video, tasks, editionResultPath } = options
94
95 const newFile = await buildNewFile({ path: editionResultPath, mode: 'web-video' })
96 newFile.videoId = video.id
97
98 const outputPath = VideoPathManager.Instance.getFSVideoFileOutputPath(video, newFile)
99 await move(editionResultPath, outputPath)
100
101 await safeCleanupStudioTMPFiles(tasks)
102
103 await createTorrentAndSetInfoHashFromPath(video, newFile, outputPath)
104 await removeAllFiles(video, newFile)
105
106 await newFile.save()
107
108 video.duration = await getVideoStreamDuration(outputPath)
109 await video.save()
110
111 await federateVideoIfNeeded(video, false, undefined)
112
113 const user = await UserModel.loadByVideoId(video.id)
114
115 await createOptimizeOrMergeAudioJobs({ video, videoFile: newFile, isNewVideo: false, user, videoFileAlreadyLocked: false })
116}
117
118// ---------------------------------------------------------------------------
119// Private
120// ---------------------------------------------------------------------------
121
122async function removeAllFiles (video: MVideoWithAllFiles, webTorrentFileException: MVideoFile) {
123 await removeHLSPlaylist(video)
124
125 for (const file of video.VideoFiles) {
126 if (file.id === webTorrentFileException.id) continue
127
128 await removeWebTorrentFile(video, file.id)
129 }
49} 130}
diff --git a/server/middlewares/validators/config.ts b/server/middlewares/validators/config.ts
index b3e7e5011..a0074cb24 100644
--- a/server/middlewares/validators/config.ts
+++ b/server/middlewares/validators/config.ts
@@ -62,6 +62,7 @@ const customConfigUpdateValidator = [
62 body('transcoding.hls.enabled').isBoolean(), 62 body('transcoding.hls.enabled').isBoolean(),
63 63
64 body('videoStudio.enabled').isBoolean(), 64 body('videoStudio.enabled').isBoolean(),
65 body('videoStudio.remoteRunners.enabled').isBoolean(),
65 66
66 body('import.videos.concurrency').isInt({ min: 0 }), 67 body('import.videos.concurrency').isInt({ min: 0 }),
67 body('import.videos.http.enabled').isBoolean(), 68 body('import.videos.http.enabled').isBoolean(),
diff --git a/server/middlewares/validators/runners/job-files.ts b/server/middlewares/validators/runners/job-files.ts
index 56afa39aa..e5afff0e5 100644
--- a/server/middlewares/validators/runners/job-files.ts
+++ b/server/middlewares/validators/runners/job-files.ts
@@ -1,5 +1,8 @@
1import express from 'express' 1import express from 'express'
2import { HttpStatusCode } from '@shared/models' 2import { param } from 'express-validator'
3import { basename } from 'path'
4import { isSafeFilename } from '@server/helpers/custom-validators/misc'
5import { hasVideoStudioTaskFile, HttpStatusCode, RunnerJobVideoEditionTranscodingPayload } from '@shared/models'
3import { areValidationErrors, doesVideoExist, isValidVideoIdParam } from '../shared' 6import { areValidationErrors, doesVideoExist, isValidVideoIdParam } from '../shared'
4 7
5const tags = [ 'runner' ] 8const tags = [ 'runner' ]
@@ -25,3 +28,33 @@ export const runnerJobGetVideoTranscodingFileValidator = [
25 return next() 28 return next()
26 } 29 }
27] 30]
31
32export const runnerJobGetVideoStudioTaskFileValidator = [
33 param('filename').custom(v => isSafeFilename(v)),
34
35 (req: express.Request, res: express.Response, next: express.NextFunction) => {
36 if (areValidationErrors(req, res)) return
37
38 const filename = req.params.filename
39
40 const payload = res.locals.runnerJob.payload as RunnerJobVideoEditionTranscodingPayload
41
42 const found = Array.isArray(payload?.tasks) && payload.tasks.some(t => {
43 if (hasVideoStudioTaskFile(t)) {
44 return basename(t.options.file) === filename
45 }
46
47 return false
48 })
49
50 if (!found) {
51 return res.fail({
52 status: HttpStatusCode.BAD_REQUEST_400,
53 message: 'File is not associated to this edition task',
54 tags: [ ...tags, res.locals.videoAll.uuid ]
55 })
56 }
57
58 return next()
59 }
60]
diff --git a/server/middlewares/validators/runners/jobs.ts b/server/middlewares/validators/runners/jobs.ts
index 8cb87e946..de956a1ca 100644
--- a/server/middlewares/validators/runners/jobs.ts
+++ b/server/middlewares/validators/runners/jobs.ts
@@ -91,6 +91,28 @@ export const successRunnerJobValidator = [
91 } 91 }
92] 92]
93 93
94export const cancelRunnerJobValidator = [
95 (req: express.Request, res: express.Response, next: express.NextFunction) => {
96 const runnerJob = res.locals.runnerJob
97
98 const allowedStates = new Set<RunnerJobState>([
99 RunnerJobState.PENDING,
100 RunnerJobState.PROCESSING,
101 RunnerJobState.WAITING_FOR_PARENT_JOB
102 ])
103
104 if (allowedStates.has(runnerJob.state) !== true) {
105 return res.fail({
106 status: HttpStatusCode.BAD_REQUEST_400,
107 message: 'Cannot cancel this job that is not in "pending", "processing" or "waiting for parent job" state',
108 tags
109 })
110 }
111
112 return next()
113 }
114]
115
94export const runnerJobGetValidator = [ 116export const runnerJobGetValidator = [
95 param('jobUUID').custom(isUUIDValid), 117 param('jobUUID').custom(isUUIDValid),
96 118
diff --git a/server/tests/api/check-params/config.ts b/server/tests/api/check-params/config.ts
index c5cda203e..472cad182 100644
--- a/server/tests/api/check-params/config.ts
+++ b/server/tests/api/check-params/config.ts
@@ -162,7 +162,10 @@ describe('Test config API validators', function () {
162 } 162 }
163 }, 163 },
164 videoStudio: { 164 videoStudio: {
165 enabled: true 165 enabled: true,
166 remoteRunners: {
167 enabled: true
168 }
166 }, 169 },
167 import: { 170 import: {
168 videos: { 171 videos: {
diff --git a/server/tests/api/check-params/runners.ts b/server/tests/api/check-params/runners.ts
index 4da6fd91d..90a301392 100644
--- a/server/tests/api/check-params/runners.ts
+++ b/server/tests/api/check-params/runners.ts
@@ -1,6 +1,17 @@
1import { basename } from 'path'
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 2/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '@server/tests/shared' 3import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '@server/tests/shared'
3import { HttpStatusCode, RunnerJob, RunnerJobState, RunnerJobSuccessPayload, RunnerJobUpdatePayload, VideoPrivacy } from '@shared/models' 4import {
5 HttpStatusCode,
6 isVideoStudioTaskIntro,
7 RunnerJob,
8 RunnerJobState,
9 RunnerJobSuccessPayload,
10 RunnerJobUpdatePayload,
11 RunnerJobVideoEditionTranscodingPayload,
12 VideoPrivacy,
13 VideoStudioTaskIntro
14} from '@shared/models'
4import { 15import {
5 cleanupTests, 16 cleanupTests,
6 createSingleServer, 17 createSingleServer,
@@ -10,6 +21,7 @@ import {
10 setAccessTokensToServers, 21 setAccessTokensToServers,
11 setDefaultVideoChannel, 22 setDefaultVideoChannel,
12 stopFfmpeg, 23 stopFfmpeg,
24 VideoStudioCommand,
13 waitJobs 25 waitJobs
14} from '@shared/server-commands' 26} from '@shared/server-commands'
15 27
@@ -53,7 +65,10 @@ describe('Test managing runners', function () {
53 registrationTokenId = data[0].id 65 registrationTokenId = data[0].id
54 66
55 await server.config.enableTranscoding(true, true) 67 await server.config.enableTranscoding(true, true)
68 await server.config.enableStudio()
56 await server.config.enableRemoteTranscoding() 69 await server.config.enableRemoteTranscoding()
70 await server.config.enableRemoteStudio()
71
57 runnerToken = await server.runners.autoRegisterRunner() 72 runnerToken = await server.runners.autoRegisterRunner()
58 runnerToken2 = await server.runners.autoRegisterRunner() 73 runnerToken2 = await server.runners.autoRegisterRunner()
59 74
@@ -249,6 +264,10 @@ describe('Test managing runners', function () {
249 await server.runnerJobs.cancelByAdmin({ jobUUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) 264 await server.runnerJobs.cancelByAdmin({ jobUUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
250 }) 265 })
251 266
267 it('Should fail with an already cancelled job', async function () {
268 await server.runnerJobs.cancelByAdmin({ jobUUID: cancelledJobUUID, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
269 })
270
252 it('Should succeed with the correct params', async function () { 271 it('Should succeed with the correct params', async function () {
253 await server.runnerJobs.cancelByAdmin({ jobUUID }) 272 await server.runnerJobs.cancelByAdmin({ jobUUID })
254 }) 273 })
@@ -296,9 +315,13 @@ describe('Test managing runners', function () {
296 315
297 let pendingUUID: string 316 let pendingUUID: string
298 317
318 let videoStudioUUID: string
319 let studioFile: string
320
299 let liveAcceptedJob: RunnerJob & { jobToken: string } 321 let liveAcceptedJob: RunnerJob & { jobToken: string }
322 let studioAcceptedJob: RunnerJob & { jobToken: string }
300 323
301 async function fetchFiles (options: { 324 async function fetchVideoInputFiles (options: {
302 jobUUID: string 325 jobUUID: string
303 videoUUID: string 326 videoUUID: string
304 runnerToken: string 327 runnerToken: string
@@ -315,6 +338,21 @@ describe('Test managing runners', function () {
315 } 338 }
316 } 339 }
317 340
341 async function fetchStudioFiles (options: {
342 jobUUID: string
343 videoUUID: string
344 runnerToken: string
345 jobToken: string
346 studioFile?: string
347 expectedStatus: HttpStatusCode
348 }) {
349 const { jobUUID, expectedStatus, videoUUID, runnerToken, jobToken, studioFile } = options
350
351 const path = `/api/v1/runners/jobs/${jobUUID}/files/videos/${videoUUID}/studio/task-files/${studioFile}`
352
353 await makePostBodyRequest({ url: server.url, path, fields: { runnerToken, jobToken }, expectedStatus })
354 }
355
318 before(async function () { 356 before(async function () {
319 this.timeout(120000) 357 this.timeout(120000)
320 358
@@ -353,6 +391,28 @@ describe('Test managing runners', function () {
353 } 391 }
354 392
355 { 393 {
394 await server.config.disableTranscoding()
395
396 const { uuid } = await server.videos.quickUpload({ name: 'video studio' })
397 videoStudioUUID = uuid
398
399 await server.config.enableTranscoding(true, true)
400 await server.config.enableStudio()
401
402 await server.videoStudio.createEditionTasks({
403 videoId: videoStudioUUID,
404 tasks: VideoStudioCommand.getComplexTask()
405 })
406
407 const { job } = await server.runnerJobs.autoAccept({ runnerToken, type: 'video-edition-transcoding' })
408 studioAcceptedJob = job
409
410 const tasks = (job.payload as RunnerJobVideoEditionTranscodingPayload).tasks
411 const fileUrl = (tasks.find(t => isVideoStudioTaskIntro(t)) as VideoStudioTaskIntro).options.file as string
412 studioFile = basename(fileUrl)
413 }
414
415 {
356 await server.config.enableLive({ 416 await server.config.enableLive({
357 allowReplay: false, 417 allowReplay: false,
358 resolutions: 'max', 418 resolutions: 'max',
@@ -381,8 +441,6 @@ describe('Test managing runners', function () {
381 jobToken: string 441 jobToken: string
382 expectedStatus: HttpStatusCode 442 expectedStatus: HttpStatusCode
383 }) { 443 }) {
384 await fetchFiles({ ...options, videoUUID })
385
386 await server.runnerJobs.abort({ ...options, reason: 'reason' }) 444 await server.runnerJobs.abort({ ...options, reason: 'reason' })
387 await server.runnerJobs.update({ ...options }) 445 await server.runnerJobs.update({ ...options })
388 await server.runnerJobs.error({ ...options, message: 'message' }) 446 await server.runnerJobs.error({ ...options, message: 'message' })
@@ -390,39 +448,95 @@ describe('Test managing runners', function () {
390 } 448 }
391 449
392 it('Should fail with an invalid job uuid', async function () { 450 it('Should fail with an invalid job uuid', async function () {
393 await testEndpoints({ jobUUID: 'a', runnerToken, jobToken, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) 451 const options = { jobUUID: 'a', runnerToken, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }
452
453 await testEndpoints({ ...options, jobToken })
454 await fetchVideoInputFiles({ ...options, videoUUID, jobToken })
455 await fetchStudioFiles({ ...options, videoUUID, jobToken: studioAcceptedJob.jobToken, studioFile })
394 }) 456 })
395 457
396 it('Should fail with an unknown job uuid', async function () { 458 it('Should fail with an unknown job uuid', async function () {
397 const jobUUID = badUUID 459 const options = { jobUUID: badUUID, runnerToken, expectedStatus: HttpStatusCode.NOT_FOUND_404 }
398 await testEndpoints({ jobUUID, runnerToken, jobToken, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) 460
461 await testEndpoints({ ...options, jobToken })
462 await fetchVideoInputFiles({ ...options, videoUUID, jobToken })
463 await fetchStudioFiles({ ...options, jobToken: studioAcceptedJob.jobToken, videoUUID, studioFile })
399 }) 464 })
400 465
401 it('Should fail with an invalid runner token', async function () { 466 it('Should fail with an invalid runner token', async function () {
402 await testEndpoints({ jobUUID, runnerToken: '', jobToken, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) 467 const options = { runnerToken: '', expectedStatus: HttpStatusCode.BAD_REQUEST_400 }
468
469 await testEndpoints({ ...options, jobUUID, jobToken })
470 await fetchVideoInputFiles({ ...options, jobUUID, videoUUID, jobToken })
471 await fetchStudioFiles({
472 ...options,
473 jobToken: studioAcceptedJob.jobToken,
474 jobUUID: studioAcceptedJob.uuid,
475 videoUUID: videoStudioUUID,
476 studioFile
477 })
403 }) 478 })
404 479
405 it('Should fail with an unknown runner token', async function () { 480 it('Should fail with an unknown runner token', async function () {
406 const runnerToken = badUUID 481 const options = { runnerToken: badUUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 }
407 await testEndpoints({ jobUUID, runnerToken, jobToken, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) 482
483 await testEndpoints({ ...options, jobUUID, jobToken })
484 await fetchVideoInputFiles({ ...options, jobUUID, videoUUID, jobToken })
485 await fetchStudioFiles({
486 ...options,
487 jobToken: studioAcceptedJob.jobToken,
488 jobUUID: studioAcceptedJob.uuid,
489 videoUUID: videoStudioUUID,
490 studioFile
491 })
408 }) 492 })
409 493
410 it('Should fail with an invalid job token job uuid', async function () { 494 it('Should fail with an invalid job token job uuid', async function () {
411 await testEndpoints({ jobUUID, runnerToken, jobToken: '', expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) 495 const options = { runnerToken, jobToken: '', expectedStatus: HttpStatusCode.BAD_REQUEST_400 }
496
497 await testEndpoints({ ...options, jobUUID })
498 await fetchVideoInputFiles({ ...options, jobUUID, videoUUID })
499 await fetchStudioFiles({ ...options, jobUUID: studioAcceptedJob.uuid, videoUUID: videoStudioUUID, studioFile })
412 }) 500 })
413 501
414 it('Should fail with an unknown job token job uuid', async function () { 502 it('Should fail with an unknown job token job uuid', async function () {
415 const jobToken = badUUID 503 const options = { runnerToken, jobToken: badUUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 }
416 await testEndpoints({ jobUUID, runnerToken, jobToken, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) 504
505 await testEndpoints({ ...options, jobUUID })
506 await fetchVideoInputFiles({ ...options, jobUUID, videoUUID })
507 await fetchStudioFiles({ ...options, jobUUID: studioAcceptedJob.uuid, videoUUID: videoStudioUUID, studioFile })
417 }) 508 })
418 509
419 it('Should fail with a runner token not associated to this job', async function () { 510 it('Should fail with a runner token not associated to this job', async function () {
420 await testEndpoints({ jobUUID, runnerToken: runnerToken2, jobToken, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) 511 const options = { runnerToken: runnerToken2, expectedStatus: HttpStatusCode.NOT_FOUND_404 }
512
513 await testEndpoints({ ...options, jobUUID, jobToken })
514 await fetchVideoInputFiles({ ...options, jobUUID, videoUUID, jobToken })
515 await fetchStudioFiles({
516 ...options,
517 jobToken: studioAcceptedJob.jobToken,
518 jobUUID: studioAcceptedJob.uuid,
519 videoUUID: videoStudioUUID,
520 studioFile
521 })
421 }) 522 })
422 523
423 it('Should fail with a job uuid not associated to the job token', async function () { 524 it('Should fail with a job uuid not associated to the job token', async function () {
424 await testEndpoints({ jobUUID: jobUUID2, runnerToken, jobToken, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) 525 {
425 await testEndpoints({ jobUUID, runnerToken, jobToken: jobToken2, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) 526 const options = { jobUUID: jobUUID2, runnerToken, expectedStatus: HttpStatusCode.NOT_FOUND_404 }
527
528 await testEndpoints({ ...options, jobToken })
529 await fetchVideoInputFiles({ ...options, jobToken, videoUUID })
530 await fetchStudioFiles({ ...options, jobToken: studioAcceptedJob.jobToken, videoUUID: videoStudioUUID, studioFile })
531 }
532
533 {
534 const options = { runnerToken, jobToken: jobToken2, expectedStatus: HttpStatusCode.NOT_FOUND_404 }
535
536 await testEndpoints({ ...options, jobUUID })
537 await fetchVideoInputFiles({ ...options, jobUUID, videoUUID })
538 await fetchStudioFiles({ ...options, jobUUID: studioAcceptedJob.uuid, videoUUID: videoStudioUUID, studioFile })
539 }
426 }) 540 })
427 }) 541 })
428 542
@@ -670,27 +784,82 @@ describe('Test managing runners', function () {
670 }) 784 })
671 }) 785 })
672 }) 786 })
787
788 describe('Video studio', function () {
789
790 it('Should fail with an invalid video edition transcoding payload', async function () {
791 await server.runnerJobs.success({
792 jobUUID: studioAcceptedJob.uuid,
793 jobToken: studioAcceptedJob.jobToken,
794 payload: { hello: 'video_short.mp4' } as any,
795 runnerToken,
796 expectedStatus: HttpStatusCode.BAD_REQUEST_400
797 })
798 })
799 })
673 }) 800 })
674 801
675 describe('Job files', function () { 802 describe('Job files', function () {
676 803
677 describe('Video files', function () { 804 describe('Check video param for common job file routes', function () {
805
806 async function fetchFiles (options: {
807 videoUUID?: string
808 expectedStatus: HttpStatusCode
809 }) {
810 await fetchVideoInputFiles({ videoUUID, ...options, jobToken, jobUUID, runnerToken })
811
812 await fetchStudioFiles({
813 videoUUID: videoStudioUUID,
814
815 ...options,
816
817 jobToken: studioAcceptedJob.jobToken,
818 jobUUID: studioAcceptedJob.uuid,
819 runnerToken,
820 studioFile
821 })
822 }
678 823
679 it('Should fail with an invalid video id', async function () { 824 it('Should fail with an invalid video id', async function () {
680 await fetchFiles({ videoUUID: 'a', jobUUID, runnerToken, jobToken, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) 825 await fetchFiles({
826 videoUUID: 'a',
827 expectedStatus: HttpStatusCode.BAD_REQUEST_400
828 })
681 }) 829 })
682 830
683 it('Should fail with an unknown video id', async function () { 831 it('Should fail with an unknown video id', async function () {
684 const videoUUID = '910ec12a-d9e6-458b-a274-0abb655f9464' 832 const videoUUID = '910ec12a-d9e6-458b-a274-0abb655f9464'
685 await fetchFiles({ videoUUID, jobUUID, runnerToken, jobToken, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) 833
834 await fetchFiles({
835 videoUUID,
836 expectedStatus: HttpStatusCode.NOT_FOUND_404
837 })
686 }) 838 })
687 839
688 it('Should fail with a video id not associated to this job', async function () { 840 it('Should fail with a video id not associated to this job', async function () {
689 await fetchFiles({ videoUUID: videoUUID2, jobUUID, runnerToken, jobToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) 841 await fetchFiles({
842 videoUUID: videoUUID2,
843 expectedStatus: HttpStatusCode.FORBIDDEN_403
844 })
690 }) 845 })
691 846
692 it('Should succeed with the correct params', async function () { 847 it('Should succeed with the correct params', async function () {
693 await fetchFiles({ videoUUID, jobUUID, runnerToken, jobToken, expectedStatus: HttpStatusCode.OK_200 }) 848 await fetchFiles({ expectedStatus: HttpStatusCode.OK_200 })
849 })
850 })
851
852 describe('Video edition tasks file routes', function () {
853
854 it('Should fail with an invalid studio filename', async function () {
855 await fetchStudioFiles({
856 videoUUID: videoStudioUUID,
857 jobUUID: studioAcceptedJob.uuid,
858 runnerToken,
859 jobToken: studioAcceptedJob.jobToken,
860 studioFile: 'toto',
861 expectedStatus: HttpStatusCode.BAD_REQUEST_400
862 })
694 }) 863 })
695 }) 864 })
696 }) 865 })
diff --git a/server/tests/api/runners/index.ts b/server/tests/api/runners/index.ts
index 7f33ec8dd..642a3a96d 100644
--- a/server/tests/api/runners/index.ts
+++ b/server/tests/api/runners/index.ts
@@ -1,4 +1,5 @@
1export * from './runner-common' 1export * from './runner-common'
2export * from './runner-live-transcoding' 2export * from './runner-live-transcoding'
3export * from './runner-socket' 3export * from './runner-socket'
4export * from './runner-studio-transcoding'
4export * from './runner-vod-transcoding' 5export * from './runner-vod-transcoding'
diff --git a/server/tests/api/runners/runner-common.ts b/server/tests/api/runners/runner-common.ts
index a2204753b..554024190 100644
--- a/server/tests/api/runners/runner-common.ts
+++ b/server/tests/api/runners/runner-common.ts
@@ -2,7 +2,15 @@
2 2
3import { expect } from 'chai' 3import { expect } from 'chai'
4import { wait } from '@shared/core-utils' 4import { wait } from '@shared/core-utils'
5import { HttpStatusCode, Runner, RunnerJob, RunnerJobAdmin, RunnerJobState, RunnerRegistrationToken } from '@shared/models' 5import {
6 HttpStatusCode,
7 Runner,
8 RunnerJob,
9 RunnerJobAdmin,
10 RunnerJobState,
11 RunnerJobVODWebVideoTranscodingPayload,
12 RunnerRegistrationToken
13} from '@shared/models'
6import { 14import {
7 cleanupTests, 15 cleanupTests,
8 createSingleServer, 16 createSingleServer,
@@ -349,7 +357,7 @@ describe('Test runner common actions', function () {
349 for (const job of availableJobs) { 357 for (const job of availableJobs) {
350 expect(job.uuid).to.exist 358 expect(job.uuid).to.exist
351 expect(job.payload.input).to.exist 359 expect(job.payload.input).to.exist
352 expect(job.payload.output).to.exist 360 expect((job.payload as RunnerJobVODWebVideoTranscodingPayload).output).to.exist
353 361
354 expect((job as RunnerJobAdmin).privatePayload).to.not.exist 362 expect((job as RunnerJobAdmin).privatePayload).to.not.exist
355 } 363 }
diff --git a/server/tests/api/runners/runner-studio-transcoding.ts b/server/tests/api/runners/runner-studio-transcoding.ts
new file mode 100644
index 000000000..9ae629be6
--- /dev/null
+++ b/server/tests/api/runners/runner-studio-transcoding.ts
@@ -0,0 +1,168 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import { expect } from 'chai'
4import { readFile } from 'fs-extra'
5import { checkPersistentTmpIsEmpty, checkVideoDuration } from '@server/tests/shared'
6import { buildAbsoluteFixturePath } from '@shared/core-utils'
7import {
8 RunnerJobVideoEditionTranscodingPayload,
9 VideoEditionTranscodingSuccess,
10 VideoState,
11 VideoStudioTask,
12 VideoStudioTaskIntro
13} from '@shared/models'
14import {
15 cleanupTests,
16 createMultipleServers,
17 doubleFollow,
18 PeerTubeServer,
19 setAccessTokensToServers,
20 setDefaultVideoChannel,
21 VideoStudioCommand,
22 waitJobs
23} from '@shared/server-commands'
24
25describe('Test runner video studio transcoding', function () {
26 let servers: PeerTubeServer[] = []
27 let runnerToken: string
28 let videoUUID: string
29 let jobUUID: string
30
31 async function renewStudio (tasks: VideoStudioTask[] = VideoStudioCommand.getComplexTask()) {
32 const { uuid } = await servers[0].videos.quickUpload({ name: 'video' })
33 videoUUID = uuid
34
35 await waitJobs(servers)
36
37 await servers[0].videoStudio.createEditionTasks({ videoId: uuid, tasks })
38 await waitJobs(servers)
39
40 const { availableJobs } = await servers[0].runnerJobs.request({ runnerToken })
41 expect(availableJobs).to.have.lengthOf(1)
42
43 jobUUID = availableJobs[0].uuid
44 }
45
46 before(async function () {
47 this.timeout(120_000)
48
49 servers = await createMultipleServers(2)
50
51 await setAccessTokensToServers(servers)
52 await setDefaultVideoChannel(servers)
53
54 await doubleFollow(servers[0], servers[1])
55
56 await servers[0].config.enableTranscoding(true, true)
57 await servers[0].config.enableStudio()
58 await servers[0].config.enableRemoteStudio()
59
60 runnerToken = await servers[0].runners.autoRegisterRunner()
61 })
62
63 it('Should error a studio transcoding job', async function () {
64 this.timeout(60000)
65
66 await renewStudio()
67
68 for (let i = 0; i < 5; i++) {
69 const { job } = await servers[0].runnerJobs.accept({ runnerToken, jobUUID })
70 const jobToken = job.jobToken
71
72 await servers[0].runnerJobs.error({ runnerToken, jobUUID, jobToken, message: 'Error' })
73 }
74
75 const video = await servers[0].videos.get({ id: videoUUID })
76 expect(video.state.id).to.equal(VideoState.PUBLISHED)
77
78 await checkPersistentTmpIsEmpty(servers[0])
79 })
80
81 it('Should cancel a transcoding job', async function () {
82 this.timeout(60000)
83
84 await renewStudio()
85
86 await servers[0].runnerJobs.cancelByAdmin({ jobUUID })
87
88 const video = await servers[0].videos.get({ id: videoUUID })
89 expect(video.state.id).to.equal(VideoState.PUBLISHED)
90
91 await checkPersistentTmpIsEmpty(servers[0])
92 })
93
94 it('Should execute a remote studio job', async function () {
95 this.timeout(240_000)
96
97 const tasks = [
98 {
99 name: 'add-outro' as 'add-outro',
100 options: {
101 file: 'video_short.webm'
102 }
103 },
104 {
105 name: 'add-watermark' as 'add-watermark',
106 options: {
107 file: 'thumbnail.png'
108 }
109 },
110 {
111 name: 'add-intro' as 'add-intro',
112 options: {
113 file: 'video_very_short_240p.mp4'
114 }
115 }
116 ]
117
118 await renewStudio(tasks)
119
120 for (const server of servers) {
121 await checkVideoDuration(server, videoUUID, 5)
122 }
123
124 const { job } = await servers[0].runnerJobs.accept<RunnerJobVideoEditionTranscodingPayload>({ runnerToken, jobUUID })
125 const jobToken = job.jobToken
126
127 expect(job.type === 'video-edition-transcoding')
128 expect(job.payload.input.videoFileUrl).to.exist
129
130 // Check video input file
131 {
132 await servers[0].runnerJobs.getJobFile({ url: job.payload.input.videoFileUrl, jobToken, runnerToken })
133 }
134
135 // Check task files
136 for (let i = 0; i < tasks.length; i++) {
137 const task = tasks[i]
138 const payloadTask = job.payload.tasks[i]
139
140 expect(payloadTask.name).to.equal(task.name)
141
142 const inputFile = await readFile(buildAbsoluteFixturePath(task.options.file))
143
144 const { body } = await servers[0].runnerJobs.getJobFile({
145 url: (payloadTask as VideoStudioTaskIntro).options.file as string,
146 jobToken,
147 runnerToken
148 })
149
150 expect(body).to.deep.equal(inputFile)
151 }
152
153 const payload: VideoEditionTranscodingSuccess = { videoFile: 'video_very_short_240p.mp4' }
154 await servers[0].runnerJobs.success({ runnerToken, jobUUID, jobToken, payload })
155
156 await waitJobs(servers)
157
158 for (const server of servers) {
159 await checkVideoDuration(server, videoUUID, 2)
160 }
161
162 await checkPersistentTmpIsEmpty(servers[0])
163 })
164
165 after(async function () {
166 await cleanupTests(servers)
167 })
168})
diff --git a/server/tests/api/runners/runner-vod-transcoding.ts b/server/tests/api/runners/runner-vod-transcoding.ts
index 92a47ac3b..b08ee312c 100644
--- a/server/tests/api/runners/runner-vod-transcoding.ts
+++ b/server/tests/api/runners/runner-vod-transcoding.ts
@@ -155,7 +155,7 @@ describe('Test runner VOD transcoding', function () {
155 expect(job.payload.output.resolution).to.equal(720) 155 expect(job.payload.output.resolution).to.equal(720)
156 expect(job.payload.output.fps).to.equal(25) 156 expect(job.payload.output.fps).to.equal(25)
157 157
158 const { body } = await servers[0].runnerJobs.getInputFile({ url: job.payload.input.videoFileUrl, jobToken, runnerToken }) 158 const { body } = await servers[0].runnerJobs.getJobFile({ url: job.payload.input.videoFileUrl, jobToken, runnerToken })
159 const inputFile = await readFile(buildAbsoluteFixturePath('video_short.webm')) 159 const inputFile = await readFile(buildAbsoluteFixturePath('video_short.webm'))
160 160
161 expect(body).to.deep.equal(inputFile) 161 expect(body).to.deep.equal(inputFile)
@@ -200,7 +200,7 @@ describe('Test runner VOD transcoding', function () {
200 const { job } = await servers[0].runnerJobs.accept<RunnerJobVODWebVideoTranscodingPayload>({ runnerToken, jobUUID }) 200 const { job } = await servers[0].runnerJobs.accept<RunnerJobVODWebVideoTranscodingPayload>({ runnerToken, jobUUID })
201 jobToken = job.jobToken 201 jobToken = job.jobToken
202 202
203 const { body } = await servers[0].runnerJobs.getInputFile({ url: job.payload.input.videoFileUrl, jobToken, runnerToken }) 203 const { body } = await servers[0].runnerJobs.getJobFile({ url: job.payload.input.videoFileUrl, jobToken, runnerToken })
204 const inputFile = await readFile(buildAbsoluteFixturePath('video_short.mp4')) 204 const inputFile = await readFile(buildAbsoluteFixturePath('video_short.mp4'))
205 205
206 expect(body).to.deep.equal(inputFile) 206 expect(body).to.deep.equal(inputFile)
@@ -221,7 +221,7 @@ describe('Test runner VOD transcoding', function () {
221 const { job } = await servers[0].runnerJobs.accept<RunnerJobVODWebVideoTranscodingPayload>({ runnerToken, jobUUID }) 221 const { job } = await servers[0].runnerJobs.accept<RunnerJobVODWebVideoTranscodingPayload>({ runnerToken, jobUUID })
222 jobToken = job.jobToken 222 jobToken = job.jobToken
223 223
224 const { body } = await servers[0].runnerJobs.getInputFile({ url: job.payload.input.videoFileUrl, jobToken, runnerToken }) 224 const { body } = await servers[0].runnerJobs.getJobFile({ url: job.payload.input.videoFileUrl, jobToken, runnerToken })
225 const inputFile = await readFile(buildAbsoluteFixturePath('video_short.mp4')) 225 const inputFile = await readFile(buildAbsoluteFixturePath('video_short.mp4'))
226 expect(body).to.deep.equal(inputFile) 226 expect(body).to.deep.equal(inputFile)
227 227
@@ -293,7 +293,7 @@ describe('Test runner VOD transcoding', function () {
293 const { job } = await servers[0].runnerJobs.accept<RunnerJobVODHLSTranscodingPayload>({ runnerToken, jobUUID }) 293 const { job } = await servers[0].runnerJobs.accept<RunnerJobVODHLSTranscodingPayload>({ runnerToken, jobUUID })
294 jobToken = job.jobToken 294 jobToken = job.jobToken
295 295
296 const { body } = await servers[0].runnerJobs.getInputFile({ url: job.payload.input.videoFileUrl, jobToken, runnerToken }) 296 const { body } = await servers[0].runnerJobs.getJobFile({ url: job.payload.input.videoFileUrl, jobToken, runnerToken })
297 const inputFile = await readFile(buildAbsoluteFixturePath('video_short.mp4')) 297 const inputFile = await readFile(buildAbsoluteFixturePath('video_short.mp4'))
298 298
299 expect(body).to.deep.equal(inputFile) 299 expect(body).to.deep.equal(inputFile)
@@ -337,7 +337,7 @@ describe('Test runner VOD transcoding', function () {
337 const { job } = await servers[0].runnerJobs.accept<RunnerJobVODHLSTranscodingPayload>({ runnerToken, jobUUID }) 337 const { job } = await servers[0].runnerJobs.accept<RunnerJobVODHLSTranscodingPayload>({ runnerToken, jobUUID })
338 jobToken = job.jobToken 338 jobToken = job.jobToken
339 339
340 const { body } = await servers[0].runnerJobs.getInputFile({ url: job.payload.input.videoFileUrl, jobToken, runnerToken }) 340 const { body } = await servers[0].runnerJobs.getJobFile({ url: job.payload.input.videoFileUrl, jobToken, runnerToken })
341 const inputFile = await readFile(buildAbsoluteFixturePath(maxQualityFile)) 341 const inputFile = await readFile(buildAbsoluteFixturePath(maxQualityFile))
342 expect(body).to.deep.equal(inputFile) 342 expect(body).to.deep.equal(inputFile)
343 343
@@ -446,13 +446,13 @@ describe('Test runner VOD transcoding', function () {
446 expect(job.payload.output.resolution).to.equal(480) 446 expect(job.payload.output.resolution).to.equal(480)
447 447
448 { 448 {
449 const { body } = await servers[0].runnerJobs.getInputFile({ url: job.payload.input.audioFileUrl, jobToken, runnerToken }) 449 const { body } = await servers[0].runnerJobs.getJobFile({ url: job.payload.input.audioFileUrl, jobToken, runnerToken })
450 const inputFile = await readFile(buildAbsoluteFixturePath('sample.ogg')) 450 const inputFile = await readFile(buildAbsoluteFixturePath('sample.ogg'))
451 expect(body).to.deep.equal(inputFile) 451 expect(body).to.deep.equal(inputFile)
452 } 452 }
453 453
454 { 454 {
455 const { body } = await servers[0].runnerJobs.getInputFile({ url: job.payload.input.previewFileUrl, jobToken, runnerToken }) 455 const { body } = await servers[0].runnerJobs.getJobFile({ url: job.payload.input.previewFileUrl, jobToken, runnerToken })
456 456
457 const video = await servers[0].videos.get({ id: videoUUID }) 457 const video = await servers[0].videos.get({ id: videoUUID })
458 const { body: inputFile } = await makeGetRequest({ 458 const { body: inputFile } = await makeGetRequest({
@@ -503,7 +503,7 @@ describe('Test runner VOD transcoding', function () {
503 const { job } = await servers[0].runnerJobs.accept<RunnerJobVODHLSTranscodingPayload>({ runnerToken, jobUUID }) 503 const { job } = await servers[0].runnerJobs.accept<RunnerJobVODHLSTranscodingPayload>({ runnerToken, jobUUID })
504 jobToken = job.jobToken 504 jobToken = job.jobToken
505 505
506 const { body } = await servers[0].runnerJobs.getInputFile({ url: job.payload.input.videoFileUrl, jobToken, runnerToken }) 506 const { body } = await servers[0].runnerJobs.getJobFile({ url: job.payload.input.videoFileUrl, jobToken, runnerToken })
507 const inputFile = await readFile(buildAbsoluteFixturePath('video_short_480p.mp4')) 507 const inputFile = await readFile(buildAbsoluteFixturePath('video_short_480p.mp4'))
508 expect(body).to.deep.equal(inputFile) 508 expect(body).to.deep.equal(inputFile)
509 509
diff --git a/server/tests/api/server/config.ts b/server/tests/api/server/config.ts
index 54a40b994..011ba268c 100644
--- a/server/tests/api/server/config.ts
+++ b/server/tests/api/server/config.ts
@@ -102,6 +102,7 @@ function checkInitialConfig (server: PeerTubeServer, data: CustomConfig) {
102 expect(data.live.transcoding.alwaysTranscodeOriginalResolution).to.be.true 102 expect(data.live.transcoding.alwaysTranscodeOriginalResolution).to.be.true
103 103
104 expect(data.videoStudio.enabled).to.be.false 104 expect(data.videoStudio.enabled).to.be.false
105 expect(data.videoStudio.remoteRunners.enabled).to.be.false
105 106
106 expect(data.import.videos.concurrency).to.equal(2) 107 expect(data.import.videos.concurrency).to.equal(2)
107 expect(data.import.videos.http.enabled).to.be.true 108 expect(data.import.videos.http.enabled).to.be.true
@@ -211,6 +212,7 @@ function checkUpdatedConfig (data: CustomConfig) {
211 expect(data.live.transcoding.alwaysTranscodeOriginalResolution).to.be.false 212 expect(data.live.transcoding.alwaysTranscodeOriginalResolution).to.be.false
212 213
213 expect(data.videoStudio.enabled).to.be.true 214 expect(data.videoStudio.enabled).to.be.true
215 expect(data.videoStudio.remoteRunners.enabled).to.be.true
214 216
215 expect(data.import.videos.concurrency).to.equal(4) 217 expect(data.import.videos.concurrency).to.equal(4)
216 expect(data.import.videos.http.enabled).to.be.false 218 expect(data.import.videos.http.enabled).to.be.false
@@ -374,7 +376,10 @@ const newCustomConfig: CustomConfig = {
374 } 376 }
375 }, 377 },
376 videoStudio: { 378 videoStudio: {
377 enabled: true 379 enabled: true,
380 remoteRunners: {
381 enabled: true
382 }
378 }, 383 },
379 import: { 384 import: {
380 videos: { 385 videos: {
diff --git a/server/tests/api/transcoding/video-studio.ts b/server/tests/api/transcoding/video-studio.ts
index 30f72e6e9..2f64ef6bd 100644
--- a/server/tests/api/transcoding/video-studio.ts
+++ b/server/tests/api/transcoding/video-studio.ts
@@ -1,5 +1,5 @@
1import { expect } from 'chai' 1import { expect } from 'chai'
2import { checkPersistentTmpIsEmpty, expectStartWith } from '@server/tests/shared' 2import { checkPersistentTmpIsEmpty, checkVideoDuration, expectStartWith } from '@server/tests/shared'
3import { areMockObjectStorageTestsDisabled, getAllFiles } from '@shared/core-utils' 3import { areMockObjectStorageTestsDisabled, getAllFiles } from '@shared/core-utils'
4import { VideoStudioTask } from '@shared/models' 4import { VideoStudioTask } from '@shared/models'
5import { 5import {
@@ -18,20 +18,6 @@ describe('Test video studio', function () {
18 let servers: PeerTubeServer[] = [] 18 let servers: PeerTubeServer[] = []
19 let videoUUID: string 19 let videoUUID: string
20 20
21 async function checkDuration (server: PeerTubeServer, duration: number) {
22 const video = await server.videos.get({ id: videoUUID })
23
24 expect(video.duration).to.be.approximately(duration, 1)
25
26 for (const file of video.files) {
27 const metadata = await server.videos.getFileMetadata({ url: file.metadataUrl })
28
29 for (const stream of metadata.streams) {
30 expect(Math.round(stream.duration)).to.be.approximately(duration, 1)
31 }
32 }
33 }
34
35 async function renewVideo (fixture = 'video_short.webm') { 21 async function renewVideo (fixture = 'video_short.webm') {
36 const video = await servers[0].videos.quickUpload({ name: 'video', fixture }) 22 const video = await servers[0].videos.quickUpload({ name: 'video', fixture })
37 videoUUID = video.uuid 23 videoUUID = video.uuid
@@ -79,7 +65,7 @@ describe('Test video studio', function () {
79 ]) 65 ])
80 66
81 for (const server of servers) { 67 for (const server of servers) {
82 await checkDuration(server, 3) 68 await checkVideoDuration(server, videoUUID, 3)
83 69
84 const video = await server.videos.get({ id: videoUUID }) 70 const video = await server.videos.get({ id: videoUUID })
85 expect(new Date(video.publishedAt)).to.be.below(beforeTasks) 71 expect(new Date(video.publishedAt)).to.be.below(beforeTasks)
@@ -100,7 +86,7 @@ describe('Test video studio', function () {
100 ]) 86 ])
101 87
102 for (const server of servers) { 88 for (const server of servers) {
103 await checkDuration(server, 2) 89 await checkVideoDuration(server, videoUUID, 2)
104 } 90 }
105 }) 91 })
106 92
@@ -119,7 +105,7 @@ describe('Test video studio', function () {
119 ]) 105 ])
120 106
121 for (const server of servers) { 107 for (const server of servers) {
122 await checkDuration(server, 4) 108 await checkVideoDuration(server, videoUUID, 4)
123 } 109 }
124 }) 110 })
125 }) 111 })
@@ -140,7 +126,7 @@ describe('Test video studio', function () {
140 ]) 126 ])
141 127
142 for (const server of servers) { 128 for (const server of servers) {
143 await checkDuration(server, 10) 129 await checkVideoDuration(server, videoUUID, 10)
144 } 130 }
145 }) 131 })
146 132
@@ -158,7 +144,7 @@ describe('Test video studio', function () {
158 ]) 144 ])
159 145
160 for (const server of servers) { 146 for (const server of servers) {
161 await checkDuration(server, 7) 147 await checkVideoDuration(server, videoUUID, 7)
162 } 148 }
163 }) 149 })
164 150
@@ -183,7 +169,7 @@ describe('Test video studio', function () {
183 ]) 169 ])
184 170
185 for (const server of servers) { 171 for (const server of servers) {
186 await checkDuration(server, 12) 172 await checkVideoDuration(server, videoUUID, 12)
187 } 173 }
188 }) 174 })
189 175
@@ -201,7 +187,7 @@ describe('Test video studio', function () {
201 ]) 187 ])
202 188
203 for (const server of servers) { 189 for (const server of servers) {
204 await checkDuration(server, 7) 190 await checkVideoDuration(server, videoUUID, 7)
205 } 191 }
206 }) 192 })
207 193
@@ -219,7 +205,7 @@ describe('Test video studio', function () {
219 ]) 205 ])
220 206
221 for (const server of servers) { 207 for (const server of servers) {
222 await checkDuration(server, 10) 208 await checkVideoDuration(server, videoUUID, 10)
223 } 209 }
224 }) 210 })
225 211
@@ -237,7 +223,7 @@ describe('Test video studio', function () {
237 ]) 223 ])
238 224
239 for (const server of servers) { 225 for (const server of servers) {
240 await checkDuration(server, 10) 226 await checkVideoDuration(server, videoUUID, 10)
241 } 227 }
242 }) 228 })
243 }) 229 })
@@ -279,7 +265,7 @@ describe('Test video studio', function () {
279 await createTasks(VideoStudioCommand.getComplexTask()) 265 await createTasks(VideoStudioCommand.getComplexTask())
280 266
281 for (const server of servers) { 267 for (const server of servers) {
282 await checkDuration(server, 9) 268 await checkVideoDuration(server, videoUUID, 9)
283 } 269 }
284 }) 270 })
285 }) 271 })
@@ -309,7 +295,7 @@ describe('Test video studio', function () {
309 const video = await server.videos.get({ id: videoUUID }) 295 const video = await server.videos.get({ id: videoUUID })
310 expect(video.files).to.have.lengthOf(0) 296 expect(video.files).to.have.lengthOf(0)
311 297
312 await checkDuration(server, 9) 298 await checkVideoDuration(server, videoUUID, 9)
313 } 299 }
314 }) 300 })
315 }) 301 })
@@ -351,7 +337,7 @@ describe('Test video studio', function () {
351 expectStartWith(hlsFile.fileUrl, ObjectStorageCommand.getMockPlaylistBaseUrl()) 337 expectStartWith(hlsFile.fileUrl, ObjectStorageCommand.getMockPlaylistBaseUrl())
352 } 338 }
353 339
354 await checkDuration(server, 9) 340 await checkVideoDuration(server, videoUUID, 9)
355 } 341 }
356 }) 342 })
357 }) 343 })
@@ -370,7 +356,7 @@ describe('Test video studio', function () {
370 await waitJobs(servers) 356 await waitJobs(servers)
371 357
372 for (const server of servers) { 358 for (const server of servers) {
373 await checkDuration(server, 9) 359 await checkVideoDuration(server, videoUUID, 9)
374 } 360 }
375 }) 361 })
376 362
diff --git a/server/tests/peertube-runner/index.ts b/server/tests/peertube-runner/index.ts
index 6258d6eb2..470316417 100644
--- a/server/tests/peertube-runner/index.ts
+++ b/server/tests/peertube-runner/index.ts
@@ -1,3 +1,4 @@
1export * from './client-cli' 1export * from './client-cli'
2export * from './live-transcoding' 2export * from './live-transcoding'
3export * from './studio-transcoding'
3export * from './vod-transcoding' 4export * from './vod-transcoding'
diff --git a/server/tests/peertube-runner/live-transcoding.ts b/server/tests/peertube-runner/live-transcoding.ts
index f58e920ba..1e94eabcd 100644
--- a/server/tests/peertube-runner/live-transcoding.ts
+++ b/server/tests/peertube-runner/live-transcoding.ts
@@ -1,6 +1,12 @@
1import { expect } from 'chai' 1import { expect } from 'chai'
2/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 2/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3import { expectStartWith, PeerTubeRunnerProcess, SQLCommand, testLiveVideoResolutions } from '@server/tests/shared' 3import {
4 checkPeerTubeRunnerCacheIsEmpty,
5 expectStartWith,
6 PeerTubeRunnerProcess,
7 SQLCommand,
8 testLiveVideoResolutions
9} from '@server/tests/shared'
4import { areMockObjectStorageTestsDisabled, wait } from '@shared/core-utils' 10import { areMockObjectStorageTestsDisabled, wait } from '@shared/core-utils'
5import { HttpStatusCode, VideoPrivacy } from '@shared/models' 11import { HttpStatusCode, VideoPrivacy } from '@shared/models'
6import { 12import {
@@ -169,6 +175,13 @@ describe('Test Live transcoding in peertube-runner program', function () {
169 runSuite({ objectStorage: true }) 175 runSuite({ objectStorage: true })
170 }) 176 })
171 177
178 describe('Check cleanup', function () {
179
180 it('Should have an empty cache directory', async function () {
181 await checkPeerTubeRunnerCacheIsEmpty()
182 })
183 })
184
172 after(async function () { 185 after(async function () {
173 await peertubeRunner.unregisterPeerTubeInstance({ server: servers[0] }) 186 await peertubeRunner.unregisterPeerTubeInstance({ server: servers[0] })
174 peertubeRunner.kill() 187 peertubeRunner.kill()
diff --git a/server/tests/peertube-runner/studio-transcoding.ts b/server/tests/peertube-runner/studio-transcoding.ts
new file mode 100644
index 000000000..cca905e2f
--- /dev/null
+++ b/server/tests/peertube-runner/studio-transcoding.ts
@@ -0,0 +1,116 @@
1
2import { expect } from 'chai'
3import { checkPeerTubeRunnerCacheIsEmpty, checkVideoDuration, expectStartWith, PeerTubeRunnerProcess } from '@server/tests/shared'
4import { areMockObjectStorageTestsDisabled, getAllFiles, wait } from '@shared/core-utils'
5import {
6 cleanupTests,
7 createMultipleServers,
8 doubleFollow,
9 ObjectStorageCommand,
10 PeerTubeServer,
11 setAccessTokensToServers,
12 setDefaultVideoChannel,
13 VideoStudioCommand,
14 waitJobs
15} from '@shared/server-commands'
16
17describe('Test studio transcoding in peertube-runner program', function () {
18 let servers: PeerTubeServer[] = []
19 let peertubeRunner: PeerTubeRunnerProcess
20
21 function runSuite (options: {
22 objectStorage: boolean
23 }) {
24 const { objectStorage } = options
25
26 it('Should run a complex studio transcoding', async function () {
27 this.timeout(120000)
28
29 const { uuid } = await servers[0].videos.quickUpload({ name: 'mp4', fixture: 'video_short.mp4' })
30 await waitJobs(servers)
31
32 const video = await servers[0].videos.get({ id: uuid })
33 const oldFileUrls = getAllFiles(video).map(f => f.fileUrl)
34
35 await servers[0].videoStudio.createEditionTasks({ videoId: uuid, tasks: VideoStudioCommand.getComplexTask() })
36 await waitJobs(servers, { runnerJobs: true })
37
38 for (const server of servers) {
39 const video = await server.videos.get({ id: uuid })
40 const files = getAllFiles(video)
41
42 for (const f of files) {
43 expect(oldFileUrls).to.not.include(f.fileUrl)
44 }
45
46 if (objectStorage) {
47 for (const webtorrentFile of video.files) {
48 expectStartWith(webtorrentFile.fileUrl, ObjectStorageCommand.getMockWebTorrentBaseUrl())
49 }
50
51 for (const hlsFile of video.streamingPlaylists[0].files) {
52 expectStartWith(hlsFile.fileUrl, ObjectStorageCommand.getMockPlaylistBaseUrl())
53 }
54 }
55
56 await checkVideoDuration(server, uuid, 9)
57 }
58 })
59 }
60
61 before(async function () {
62 this.timeout(120_000)
63
64 servers = await createMultipleServers(2)
65
66 await setAccessTokensToServers(servers)
67 await setDefaultVideoChannel(servers)
68
69 await doubleFollow(servers[0], servers[1])
70
71 await servers[0].config.enableTranscoding(true, true)
72 await servers[0].config.enableStudio()
73 await servers[0].config.enableRemoteStudio()
74
75 const registrationToken = await servers[0].runnerRegistrationTokens.getFirstRegistrationToken()
76
77 peertubeRunner = new PeerTubeRunnerProcess()
78 await peertubeRunner.runServer({ hideLogs: false })
79 await peertubeRunner.registerPeerTubeInstance({ server: servers[0], registrationToken, runnerName: 'runner' })
80 })
81
82 describe('With videos on local filesystem storage', function () {
83 runSuite({ objectStorage: false })
84 })
85
86 describe('With videos on object storage', function () {
87 if (areMockObjectStorageTestsDisabled()) return
88
89 before(async function () {
90 await ObjectStorageCommand.prepareDefaultMockBuckets()
91
92 await servers[0].kill()
93
94 await servers[0].run(ObjectStorageCommand.getDefaultMockConfig())
95
96 // Wait for peertube runner socket reconnection
97 await wait(1500)
98 })
99
100 runSuite({ objectStorage: true })
101 })
102
103 describe('Check cleanup', function () {
104
105 it('Should have an empty cache directory', async function () {
106 await checkPeerTubeRunnerCacheIsEmpty()
107 })
108 })
109
110 after(async function () {
111 await peertubeRunner.unregisterPeerTubeInstance({ server: servers[0] })
112 peertubeRunner.kill()
113
114 await cleanupTests(servers)
115 })
116})
diff --git a/server/tests/peertube-runner/vod-transcoding.ts b/server/tests/peertube-runner/vod-transcoding.ts
index bdf798379..3a9abba93 100644
--- a/server/tests/peertube-runner/vod-transcoding.ts
+++ b/server/tests/peertube-runner/vod-transcoding.ts
@@ -1,6 +1,11 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2import { expect } from 'chai' 2import { expect } from 'chai'
3import { completeCheckHlsPlaylist, completeWebVideoFilesCheck, PeerTubeRunnerProcess } from '@server/tests/shared' 3import {
4 checkPeerTubeRunnerCacheIsEmpty,
5 completeCheckHlsPlaylist,
6 completeWebVideoFilesCheck,
7 PeerTubeRunnerProcess
8} from '@server/tests/shared'
4import { areMockObjectStorageTestsDisabled, getAllFiles, wait } from '@shared/core-utils' 9import { areMockObjectStorageTestsDisabled, getAllFiles, wait } from '@shared/core-utils'
5import { VideoPrivacy } from '@shared/models' 10import { VideoPrivacy } from '@shared/models'
6import { 11import {
@@ -321,6 +326,13 @@ describe('Test VOD transcoding in peertube-runner program', function () {
321 }) 326 })
322 }) 327 })
323 328
329 describe('Check cleanup', function () {
330
331 it('Should have an empty cache directory', async function () {
332 await checkPeerTubeRunnerCacheIsEmpty()
333 })
334 })
335
324 after(async function () { 336 after(async function () {
325 await peertubeRunner.unregisterPeerTubeInstance({ server: servers[0] }) 337 await peertubeRunner.unregisterPeerTubeInstance({ server: servers[0] })
326 peertubeRunner.kill() 338 peertubeRunner.kill()
diff --git a/server/tests/shared/checks.ts b/server/tests/shared/checks.ts
index d7eb25bb5..feaef37c6 100644
--- a/server/tests/shared/checks.ts
+++ b/server/tests/shared/checks.ts
@@ -130,6 +130,22 @@ function checkBadSortPagination (url: string, path: string, token?: string, quer
130 }) 130 })
131} 131}
132 132
133// ---------------------------------------------------------------------------
134
135async function checkVideoDuration (server: PeerTubeServer, videoUUID: string, duration: number) {
136 const video = await server.videos.get({ id: videoUUID })
137
138 expect(video.duration).to.be.approximately(duration, 1)
139
140 for (const file of video.files) {
141 const metadata = await server.videos.getFileMetadata({ url: file.metadataUrl })
142
143 for (const stream of metadata.streams) {
144 expect(Math.round(stream.duration)).to.be.approximately(duration, 1)
145 }
146 }
147}
148
133export { 149export {
134 dateIsValid, 150 dateIsValid,
135 testImageSize, 151 testImageSize,
@@ -142,5 +158,6 @@ export {
142 checkBadStartPagination, 158 checkBadStartPagination,
143 checkBadCountPagination, 159 checkBadCountPagination,
144 checkBadSortPagination, 160 checkBadSortPagination,
161 checkVideoDuration,
145 expectLogContain 162 expectLogContain
146} 163}
diff --git a/server/tests/shared/directories.ts b/server/tests/shared/directories.ts
index a614cef7c..4f4282554 100644
--- a/server/tests/shared/directories.ts
+++ b/server/tests/shared/directories.ts
@@ -2,9 +2,11 @@
2 2
3import { expect } from 'chai' 3import { expect } from 'chai'
4import { pathExists, readdir } from 'fs-extra' 4import { pathExists, readdir } from 'fs-extra'
5import { homedir } from 'os'
6import { join } from 'path'
5import { PeerTubeServer } from '@shared/server-commands' 7import { PeerTubeServer } from '@shared/server-commands'
6 8
7async function checkTmpIsEmpty (server: PeerTubeServer) { 9export async function checkTmpIsEmpty (server: PeerTubeServer) {
8 await checkDirectoryIsEmpty(server, 'tmp', [ 'plugins-global.css', 'hls', 'resumable-uploads' ]) 10 await checkDirectoryIsEmpty(server, 'tmp', [ 'plugins-global.css', 'hls', 'resumable-uploads' ])
9 11
10 if (await pathExists(server.getDirectoryPath('tmp/hls'))) { 12 if (await pathExists(server.getDirectoryPath('tmp/hls'))) {
@@ -12,11 +14,11 @@ async function checkTmpIsEmpty (server: PeerTubeServer) {
12 } 14 }
13} 15}
14 16
15async function checkPersistentTmpIsEmpty (server: PeerTubeServer) { 17export async function checkPersistentTmpIsEmpty (server: PeerTubeServer) {
16 await checkDirectoryIsEmpty(server, 'tmp-persistent') 18 await checkDirectoryIsEmpty(server, 'tmp-persistent')
17} 19}
18 20
19async function checkDirectoryIsEmpty (server: PeerTubeServer, directory: string, exceptions: string[] = []) { 21export async function checkDirectoryIsEmpty (server: PeerTubeServer, directory: string, exceptions: string[] = []) {
20 const directoryPath = server.getDirectoryPath(directory) 22 const directoryPath = server.getDirectoryPath(directory)
21 23
22 const directoryExists = await pathExists(directoryPath) 24 const directoryExists = await pathExists(directoryPath)
@@ -28,8 +30,13 @@ async function checkDirectoryIsEmpty (server: PeerTubeServer, directory: string,
28 expect(filtered).to.have.lengthOf(0) 30 expect(filtered).to.have.lengthOf(0)
29} 31}
30 32
31export { 33export async function checkPeerTubeRunnerCacheIsEmpty () {
32 checkTmpIsEmpty, 34 const directoryPath = join(homedir(), '.cache', 'peertube-runner-nodejs', 'test', 'transcoding')
33 checkPersistentTmpIsEmpty, 35
34 checkDirectoryIsEmpty 36 const directoryExists = await pathExists(directoryPath)
37 expect(directoryExists).to.be.true
38
39 const files = await readdir(directoryPath)
40
41 expect(files).to.have.lengthOf(0)
35} 42}