]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/controllers/api/videos/transcoding.ts
Fix resolution to transcode hook name
[github/Chocobozzz/PeerTube.git] / server / controllers / api / videos / transcoding.ts
CommitLineData
ad5db104 1import express from 'express'
84cae54e 2import { computeResolutionsToTranscode } from '@server/helpers/ffmpeg'
ad5db104
C
3import { logger, loggerTagsFactory } from '@server/helpers/logger'
4import { addTranscodingJob } from '@server/lib/video'
5import { HttpStatusCode, UserRight, VideoState, VideoTranscodingCreate } from '@shared/models'
6import { asyncMiddleware, authenticate, createTranscodingValidator, ensureUserHasRight } from '../../../middlewares'
ebb9e53a 7import { Hooks } from '@server/lib/plugins/hooks'
ad5db104
C
8
9const lTags = loggerTagsFactory('api', 'video')
10const transcodingRouter = express.Router()
11
12transcodingRouter.post('/:videoId/transcoding',
13 authenticate,
14 ensureUserHasRight(UserRight.RUN_VIDEO_TRANSCODING),
15 asyncMiddleware(createTranscodingValidator),
16 asyncMiddleware(createTranscoding)
17)
18
19// ---------------------------------------------------------------------------
20
21export {
22 transcodingRouter
23}
24
25// ---------------------------------------------------------------------------
26
27async function createTranscoding (req: express.Request, res: express.Response) {
28 const video = res.locals.videoAll
0f11ec8d 29 logger.info('Creating %s transcoding job for %s.', req.body.transcodingType, video.url, lTags())
ad5db104
C
30
31 const body: VideoTranscodingCreate = req.body
32
84cae54e 33 const { resolution: maxResolution, audioStream } = await video.probeMaxQualityFile()
ebb9e53a 34 const resolutions = await Hooks.wrapObject(
84cae54e 35 computeResolutionsToTranscode({ inputResolution: maxResolution, type: 'vod', includeInputResolution: true }),
64fd6158 36 'filter:transcoding.manual.resolutions-to-transcode.result',
ebb9e53a
C
37 body
38 )
39
40 if (resolutions.length === 0) {
41 return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
42 }
ad5db104
C
43
44 video.state = VideoState.TO_TRANSCODE
45 await video.save()
46
47 for (const resolution of resolutions) {
48 if (body.transcodingType === 'hls') {
49 await addTranscodingJob({
50 type: 'new-resolution-to-hls',
51 videoUUID: video.uuid,
52 resolution,
cbe2f36d 53 hasAudio: !!audioStream,
ad5db104
C
54 copyCodecs: false,
55 isNewVideo: false,
56 autoDeleteWebTorrentIfNeeded: false,
57 isMaxQuality: maxResolution === resolution
58 })
59 } else if (body.transcodingType === 'webtorrent') {
60 await addTranscodingJob({
61 type: 'new-resolution-to-webtorrent',
62 videoUUID: video.uuid,
63 isNewVideo: false,
0f11ec8d 64 resolution,
cbe2f36d 65 hasAudio: !!audioStream,
84cae54e 66 createHLSIfNeeded: false
ad5db104
C
67 })
68 }
69 }
70
71 return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
72}