]>
Commit | Line | Data |
---|---|---|
ad5db104 C |
1 | import express from 'express' |
2 | import { computeLowerResolutionsToTranscode } from '@server/helpers/ffprobe-utils' | |
3 | import { logger, loggerTagsFactory } from '@server/helpers/logger' | |
4 | import { addTranscodingJob } from '@server/lib/video' | |
5 | import { HttpStatusCode, UserRight, VideoState, VideoTranscodingCreate } from '@shared/models' | |
6 | import { asyncMiddleware, authenticate, createTranscodingValidator, ensureUserHasRight } from '../../../middlewares' | |
7 | ||
8 | const lTags = loggerTagsFactory('api', 'video') | |
9 | const transcodingRouter = express.Router() | |
10 | ||
11 | transcodingRouter.post('/:videoId/transcoding', | |
12 | authenticate, | |
13 | ensureUserHasRight(UserRight.RUN_VIDEO_TRANSCODING), | |
14 | asyncMiddleware(createTranscodingValidator), | |
15 | asyncMiddleware(createTranscoding) | |
16 | ) | |
17 | ||
18 | // --------------------------------------------------------------------------- | |
19 | ||
20 | export { | |
21 | transcodingRouter | |
22 | } | |
23 | ||
24 | // --------------------------------------------------------------------------- | |
25 | ||
26 | async 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 | ||
cbe2f36d | 32 | const { resolution: maxResolution, isPortraitMode, audioStream } = await video.getMaxQualityFileInfo() |
ad5db104 C |
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, | |
cbe2f36d | 45 | hasAudio: !!audioStream, |
ad5db104 C |
46 | copyCodecs: false, |
47 | isNewVideo: false, | |
48 | autoDeleteWebTorrentIfNeeded: false, | |
49 | isMaxQuality: maxResolution === resolution | |
50 | }) | |
51 | } else if (body.transcodingType === 'webtorrent') { | |
52 | await addTranscodingJob({ | |
53 | type: 'new-resolution-to-webtorrent', | |
54 | videoUUID: video.uuid, | |
55 | isNewVideo: false, | |
56 | resolution: resolution, | |
cbe2f36d | 57 | hasAudio: !!audioStream, |
ad5db104 C |
58 | isPortraitMode |
59 | }) | |
60 | } | |
61 | } | |
62 | ||
63 | return res.sendStatus(HttpStatusCode.NO_CONTENT_204) | |
64 | } |