]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/controllers/api/videos/transcoding.ts
Update translations
[github/Chocobozzz/PeerTube.git] / server / controllers / api / videos / transcoding.ts
CommitLineData
ad5db104
C
1import express from 'express'
2import { computeLowerResolutionsToTranscode } from '@server/helpers/ffprobe-utils'
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'
7
8const lTags = loggerTagsFactory('api', 'video')
9const transcodingRouter = express.Router()
10
11transcodingRouter.post('/:videoId/transcoding',
12 authenticate,
13 ensureUserHasRight(UserRight.RUN_VIDEO_TRANSCODING),
14 asyncMiddleware(createTranscodingValidator),
15 asyncMiddleware(createTranscoding)
16)
17
18// ---------------------------------------------------------------------------
19
20export {
21 transcodingRouter
22}
23
24// ---------------------------------------------------------------------------
25
26async function createTranscoding (req: express.Request, res: express.Response) {
27 const video = res.locals.videoAll
28 logger.info('Creating %s transcoding job for %s.', req.body.type, video.url, lTags())
29
30 const body: VideoTranscodingCreate = req.body
31
32 const { resolution: maxResolution, isPortraitMode } = await video.getMaxQualityResolution()
33 const resolutions = computeLowerResolutionsToTranscode(maxResolution, 'vod').concat([ maxResolution ])
34
35 video.state = VideoState.TO_TRANSCODE
36 await video.save()
37
38 for (const resolution of resolutions) {
39 if (body.transcodingType === 'hls') {
40 await addTranscodingJob({
41 type: 'new-resolution-to-hls',
42 videoUUID: video.uuid,
43 resolution,
44 isPortraitMode,
45 copyCodecs: false,
46 isNewVideo: false,
47 autoDeleteWebTorrentIfNeeded: false,
48 isMaxQuality: maxResolution === resolution
49 })
50 } else if (body.transcodingType === 'webtorrent') {
51 await addTranscodingJob({
52 type: 'new-resolution-to-webtorrent',
53 videoUUID: video.uuid,
54 isNewVideo: false,
55 resolution: resolution,
56 isPortraitMode
57 })
58 }
59 }
60
61 return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
62}