aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/videos/transcoding.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2023-04-21 14:55:10 +0200
committerChocobozzz <chocobozzz@cpy.re>2023-05-09 08:57:34 +0200
commit0c9668f77901e7540e2c7045eb0f2974a4842a69 (patch)
tree226d3dd1565b0bb56588897af3b8530e6216e96b /server/controllers/api/videos/transcoding.ts
parent6bcb854cdea8688a32240bc5719c7d139806e00b (diff)
downloadPeerTube-0c9668f77901e7540e2c7045eb0f2974a4842a69.tar.gz
PeerTube-0c9668f77901e7540e2c7045eb0f2974a4842a69.tar.zst
PeerTube-0c9668f77901e7540e2c7045eb0f2974a4842a69.zip
Implement remote runner jobs in server
Move ffmpeg functions to @shared
Diffstat (limited to 'server/controllers/api/videos/transcoding.ts')
-rw-r--r--server/controllers/api/videos/transcoding.ts87
1 files changed, 8 insertions, 79 deletions
diff --git a/server/controllers/api/videos/transcoding.ts b/server/controllers/api/videos/transcoding.ts
index 8c9a5322b..54f484b2b 100644
--- a/server/controllers/api/videos/transcoding.ts
+++ b/server/controllers/api/videos/transcoding.ts
@@ -1,10 +1,8 @@
1import Bluebird from 'bluebird'
2import express from 'express' 1import express from 'express'
3import { computeResolutionsToTranscode } from '@server/helpers/ffmpeg'
4import { logger, loggerTagsFactory } from '@server/helpers/logger' 2import { logger, loggerTagsFactory } from '@server/helpers/logger'
5import { JobQueue } from '@server/lib/job-queue'
6import { Hooks } from '@server/lib/plugins/hooks' 3import { Hooks } from '@server/lib/plugins/hooks'
7import { buildTranscodingJob } from '@server/lib/video' 4import { createTranscodingJobs } from '@server/lib/transcoding/create-transcoding-job'
5import { computeResolutionsToTranscode } from '@server/lib/transcoding/transcoding-resolutions'
8import { HttpStatusCode, UserRight, VideoState, VideoTranscodingCreate } from '@shared/models' 6import { HttpStatusCode, UserRight, VideoState, VideoTranscodingCreate } from '@shared/models'
9import { asyncMiddleware, authenticate, createTranscodingValidator, ensureUserHasRight } from '../../../middlewares' 7import { asyncMiddleware, authenticate, createTranscodingValidator, ensureUserHasRight } from '../../../middlewares'
10 8
@@ -47,82 +45,13 @@ async function createTranscoding (req: express.Request, res: express.Response) {
47 video.state = VideoState.TO_TRANSCODE 45 video.state = VideoState.TO_TRANSCODE
48 await video.save() 46 await video.save()
49 47
50 const childrenResolutions = resolutions.filter(r => r !== maxResolution) 48 await createTranscodingJobs({
51 49 video,
52 logger.info('Manually creating transcoding jobs for %s.', body.transcodingType, { childrenResolutions, maxResolution }) 50 resolutions,
53 51 transcodingType: body.transcodingType,
54 const children = await Bluebird.mapSeries(childrenResolutions, resolution => {
55 if (body.transcodingType === 'hls') {
56 return buildHLSJobOption({
57 videoUUID: video.uuid,
58 hasAudio,
59 resolution,
60 isMaxQuality: false
61 })
62 }
63
64 if (body.transcodingType === 'webtorrent') {
65 return buildWebTorrentJobOption({
66 videoUUID: video.uuid,
67 hasAudio,
68 resolution
69 })
70 }
71 })
72
73 const parent = body.transcodingType === 'hls'
74 ? await buildHLSJobOption({
75 videoUUID: video.uuid,
76 hasAudio,
77 resolution: maxResolution,
78 isMaxQuality: false
79 })
80 : await buildWebTorrentJobOption({
81 videoUUID: video.uuid,
82 hasAudio,
83 resolution: maxResolution
84 })
85
86 // Porcess the last resolution after the other ones to prevent concurrency issue
87 // Because low resolutions use the biggest one as ffmpeg input
88 await JobQueue.Instance.createJobWithChildren(parent, children)
89
90 return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
91}
92
93function buildHLSJobOption (options: {
94 videoUUID: string
95 hasAudio: boolean
96 resolution: number
97 isMaxQuality: boolean
98}) {
99 const { videoUUID, hasAudio, resolution, isMaxQuality } = options
100
101 return buildTranscodingJob({
102 type: 'new-resolution-to-hls',
103 videoUUID,
104 resolution,
105 hasAudio,
106 copyCodecs: false,
107 isNewVideo: false, 52 isNewVideo: false,
108 autoDeleteWebTorrentIfNeeded: false, 53 user: null // Don't specify priority since these transcoding jobs are fired by the admin
109 isMaxQuality
110 }) 54 })
111}
112 55
113function buildWebTorrentJobOption (options: { 56 return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
114 videoUUID: string
115 hasAudio: boolean
116 resolution: number
117}) {
118 const { videoUUID, hasAudio, resolution } = options
119
120 return buildTranscodingJob({
121 type: 'new-resolution-to-webtorrent',
122 videoUUID,
123 isNewVideo: false,
124 resolution,
125 hasAudio,
126 createHLSIfNeeded: false
127 })
128} 57}