aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/videos
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers/api/videos')
-rw-r--r--server/controllers/api/videos/captions.ts11
-rw-r--r--server/controllers/api/videos/editor.ts118
-rw-r--r--server/controllers/api/videos/import.ts7
-rw-r--r--server/controllers/api/videos/index.ts2
-rw-r--r--server/controllers/api/videos/live.ts10
-rw-r--r--server/controllers/api/videos/transcoding.ts4
-rw-r--r--server/controllers/api/videos/update.ts10
-rw-r--r--server/controllers/api/videos/upload.ts21
8 files changed, 133 insertions, 50 deletions
diff --git a/server/controllers/api/videos/captions.ts b/server/controllers/api/videos/captions.ts
index 2a9a9d233..2b511a398 100644
--- a/server/controllers/api/videos/captions.ts
+++ b/server/controllers/api/videos/captions.ts
@@ -1,26 +1,19 @@
1import express from 'express' 1import express from 'express'
2import { Hooks } from '@server/lib/plugins/hooks'
2import { MVideoCaption } from '@server/types/models' 3import { MVideoCaption } from '@server/types/models'
3import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes' 4import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes'
4import { moveAndProcessCaptionFile } from '../../../helpers/captions-utils' 5import { moveAndProcessCaptionFile } from '../../../helpers/captions-utils'
5import { createReqFiles } from '../../../helpers/express-utils' 6import { createReqFiles } from '../../../helpers/express-utils'
6import { logger } from '../../../helpers/logger' 7import { logger } from '../../../helpers/logger'
7import { getFormattedObjects } from '../../../helpers/utils' 8import { getFormattedObjects } from '../../../helpers/utils'
8import { CONFIG } from '../../../initializers/config'
9import { MIMETYPES } from '../../../initializers/constants' 9import { MIMETYPES } from '../../../initializers/constants'
10import { sequelizeTypescript } from '../../../initializers/database' 10import { sequelizeTypescript } from '../../../initializers/database'
11import { federateVideoIfNeeded } from '../../../lib/activitypub/videos' 11import { federateVideoIfNeeded } from '../../../lib/activitypub/videos'
12import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate } from '../../../middlewares' 12import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate } from '../../../middlewares'
13import { addVideoCaptionValidator, deleteVideoCaptionValidator, listVideoCaptionsValidator } from '../../../middlewares/validators' 13import { addVideoCaptionValidator, deleteVideoCaptionValidator, listVideoCaptionsValidator } from '../../../middlewares/validators'
14import { VideoCaptionModel } from '../../../models/video/video-caption' 14import { VideoCaptionModel } from '../../../models/video/video-caption'
15import { Hooks } from '@server/lib/plugins/hooks'
16 15
17const reqVideoCaptionAdd = createReqFiles( 16const reqVideoCaptionAdd = createReqFiles([ 'captionfile' ], MIMETYPES.VIDEO_CAPTIONS.MIMETYPE_EXT)
18 [ 'captionfile' ],
19 MIMETYPES.VIDEO_CAPTIONS.MIMETYPE_EXT,
20 {
21 captionfile: CONFIG.STORAGE.CAPTIONS_DIR
22 }
23)
24 17
25const videoCaptionsRouter = express.Router() 18const videoCaptionsRouter = express.Router()
26 19
diff --git a/server/controllers/api/videos/editor.ts b/server/controllers/api/videos/editor.ts
new file mode 100644
index 000000000..588cc1a8c
--- /dev/null
+++ b/server/controllers/api/videos/editor.ts
@@ -0,0 +1,118 @@
1import express from 'express'
2import { createAnyReqFiles } from '@server/helpers/express-utils'
3import { MIMETYPES } from '@server/initializers/constants'
4import { JobQueue } from '@server/lib/job-queue'
5import { buildTaskFileFieldname, getTaskFile } from '@server/lib/video-editor'
6import {
7 HttpStatusCode,
8 VideoEditionTaskPayload,
9 VideoEditorCreateEdition,
10 VideoEditorTask,
11 VideoEditorTaskCut,
12 VideoEditorTaskIntro,
13 VideoEditorTaskOutro,
14 VideoEditorTaskWatermark,
15 VideoState
16} from '@shared/models'
17import { asyncMiddleware, authenticate, videosEditorAddEditionValidator } from '../../../middlewares'
18
19const editorRouter = express.Router()
20
21const tasksFiles = createAnyReqFiles(
22 MIMETYPES.VIDEO.MIMETYPE_EXT,
23 (req: express.Request, file: Express.Multer.File, cb: (err: Error, result?: boolean) => void) => {
24 const body = req.body as VideoEditorCreateEdition
25
26 // Fetch array element
27 const matches = file.fieldname.match(/tasks\[(\d+)\]/)
28 if (!matches) return cb(new Error('Cannot find array element indice for ' + file.fieldname))
29
30 const indice = parseInt(matches[1])
31 const task = body.tasks[indice]
32
33 if (!task) return cb(new Error('Cannot find array element of indice ' + indice + ' for ' + file.fieldname))
34
35 if (
36 [ 'add-intro', 'add-outro', 'add-watermark' ].includes(task.name) &&
37 file.fieldname === buildTaskFileFieldname(indice)
38 ) {
39 return cb(null, true)
40 }
41
42 return cb(null, false)
43 }
44)
45
46editorRouter.post('/:videoId/editor/edit',
47 authenticate,
48 tasksFiles,
49 asyncMiddleware(videosEditorAddEditionValidator),
50 asyncMiddleware(createEditionTasks)
51)
52
53// ---------------------------------------------------------------------------
54
55export {
56 editorRouter
57}
58
59// ---------------------------------------------------------------------------
60
61async function createEditionTasks (req: express.Request, res: express.Response) {
62 const files = req.files as Express.Multer.File[]
63 const body = req.body as VideoEditorCreateEdition
64 const video = res.locals.videoAll
65
66 video.state = VideoState.TO_EDIT
67 await video.save()
68
69 const payload = {
70 videoUUID: video.uuid,
71 tasks: body.tasks.map((t, i) => buildTaskPayload(t, i, files))
72 }
73
74 JobQueue.Instance.createJob({ type: 'video-edition', payload })
75
76 return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
77}
78
79const taskPayloadBuilders: {
80 [id in VideoEditorTask['name']]: (task: VideoEditorTask, indice?: number, files?: Express.Multer.File[]) => VideoEditionTaskPayload
81} = {
82 'add-intro': buildIntroOutroTask,
83 'add-outro': buildIntroOutroTask,
84 'cut': buildCutTask,
85 'add-watermark': buildWatermarkTask
86}
87
88function buildTaskPayload (task: VideoEditorTask, indice: number, files: Express.Multer.File[]): VideoEditionTaskPayload {
89 return taskPayloadBuilders[task.name](task, indice, files)
90}
91
92function buildIntroOutroTask (task: VideoEditorTaskIntro | VideoEditorTaskOutro, indice: number, files: Express.Multer.File[]) {
93 return {
94 name: task.name,
95 options: {
96 file: getTaskFile(files, indice).path
97 }
98 }
99}
100
101function buildCutTask (task: VideoEditorTaskCut) {
102 return {
103 name: task.name,
104 options: {
105 start: task.options.start,
106 end: task.options.end
107 }
108 }
109}
110
111function buildWatermarkTask (task: VideoEditorTaskWatermark, indice: number, files: Express.Multer.File[]) {
112 return {
113 name: task.name,
114 options: {
115 file: getTaskFile(files, indice).path
116 }
117 }
118}
diff --git a/server/controllers/api/videos/import.ts b/server/controllers/api/videos/import.ts
index b54fa822c..44283e266 100644
--- a/server/controllers/api/videos/import.ts
+++ b/server/controllers/api/videos/import.ts
@@ -61,12 +61,7 @@ const videoImportsRouter = express.Router()
61 61
62const reqVideoFileImport = createReqFiles( 62const reqVideoFileImport = createReqFiles(
63 [ 'thumbnailfile', 'previewfile', 'torrentfile' ], 63 [ 'thumbnailfile', 'previewfile', 'torrentfile' ],
64 Object.assign({}, MIMETYPES.TORRENT.MIMETYPE_EXT, MIMETYPES.IMAGE.MIMETYPE_EXT), 64 { ...MIMETYPES.TORRENT.MIMETYPE_EXT, ...MIMETYPES.IMAGE.MIMETYPE_EXT }
65 {
66 thumbnailfile: CONFIG.STORAGE.TMP_DIR,
67 previewfile: CONFIG.STORAGE.TMP_DIR,
68 torrentfile: CONFIG.STORAGE.TMP_DIR
69 }
70) 65)
71 66
72videoImportsRouter.post('/imports', 67videoImportsRouter.post('/imports',
diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts
index 61a030ba1..a5ae07d95 100644
--- a/server/controllers/api/videos/index.ts
+++ b/server/controllers/api/videos/index.ts
@@ -35,6 +35,7 @@ import { VideoModel } from '../../../models/video/video'
35import { blacklistRouter } from './blacklist' 35import { blacklistRouter } from './blacklist'
36import { videoCaptionsRouter } from './captions' 36import { videoCaptionsRouter } from './captions'
37import { videoCommentRouter } from './comment' 37import { videoCommentRouter } from './comment'
38import { editorRouter } from './editor'
38import { filesRouter } from './files' 39import { filesRouter } from './files'
39import { videoImportsRouter } from './import' 40import { videoImportsRouter } from './import'
40import { liveRouter } from './live' 41import { liveRouter } from './live'
@@ -51,6 +52,7 @@ const videosRouter = express.Router()
51videosRouter.use('/', blacklistRouter) 52videosRouter.use('/', blacklistRouter)
52videosRouter.use('/', rateVideoRouter) 53videosRouter.use('/', rateVideoRouter)
53videosRouter.use('/', videoCommentRouter) 54videosRouter.use('/', videoCommentRouter)
55videosRouter.use('/', editorRouter)
54videosRouter.use('/', videoCaptionsRouter) 56videosRouter.use('/', videoCaptionsRouter)
55videosRouter.use('/', videoImportsRouter) 57videosRouter.use('/', videoImportsRouter)
56videosRouter.use('/', ownershipVideoRouter) 58videosRouter.use('/', ownershipVideoRouter)
diff --git a/server/controllers/api/videos/live.ts b/server/controllers/api/videos/live.ts
index 8b8cacff9..49cabb6f3 100644
--- a/server/controllers/api/videos/live.ts
+++ b/server/controllers/api/videos/live.ts
@@ -1,6 +1,5 @@
1import express from 'express' 1import express from 'express'
2import { createReqFiles } from '@server/helpers/express-utils' 2import { createReqFiles } from '@server/helpers/express-utils'
3import { CONFIG } from '@server/initializers/config'
4import { ASSETS_PATH, MIMETYPES } from '@server/initializers/constants' 3import { ASSETS_PATH, MIMETYPES } from '@server/initializers/constants'
5import { getLocalVideoActivityPubUrl } from '@server/lib/activitypub/url' 4import { getLocalVideoActivityPubUrl } from '@server/lib/activitypub/url'
6import { federateVideoIfNeeded } from '@server/lib/activitypub/videos' 5import { federateVideoIfNeeded } from '@server/lib/activitypub/videos'
@@ -19,14 +18,7 @@ import { VideoModel } from '../../../models/video/video'
19 18
20const liveRouter = express.Router() 19const liveRouter = express.Router()
21 20
22const reqVideoFileLive = createReqFiles( 21const reqVideoFileLive = createReqFiles([ 'thumbnailfile', 'previewfile' ], MIMETYPES.IMAGE.MIMETYPE_EXT)
23 [ 'thumbnailfile', 'previewfile' ],
24 MIMETYPES.IMAGE.MIMETYPE_EXT,
25 {
26 thumbnailfile: CONFIG.STORAGE.TMP_DIR,
27 previewfile: CONFIG.STORAGE.TMP_DIR
28 }
29)
30 22
31liveRouter.post('/live', 23liveRouter.post('/live',
32 authenticate, 24 authenticate,
diff --git a/server/controllers/api/videos/transcoding.ts b/server/controllers/api/videos/transcoding.ts
index fba4545c2..da3ea3c9c 100644
--- a/server/controllers/api/videos/transcoding.ts
+++ b/server/controllers/api/videos/transcoding.ts
@@ -1,5 +1,5 @@
1import express from 'express' 1import express from 'express'
2import { computeLowerResolutionsToTranscode } from '@server/helpers/ffprobe-utils' 2import { computeLowerResolutionsToTranscode } from '@server/helpers/ffmpeg'
3import { logger, loggerTagsFactory } from '@server/helpers/logger' 3import { logger, loggerTagsFactory } from '@server/helpers/logger'
4import { addTranscodingJob } from '@server/lib/video' 4import { addTranscodingJob } from '@server/lib/video'
5import { HttpStatusCode, UserRight, VideoState, VideoTranscodingCreate } from '@shared/models' 5import { HttpStatusCode, UserRight, VideoState, VideoTranscodingCreate } from '@shared/models'
@@ -29,7 +29,7 @@ async function createTranscoding (req: express.Request, res: express.Response) {
29 29
30 const body: VideoTranscodingCreate = req.body 30 const body: VideoTranscodingCreate = req.body
31 31
32 const { resolution: maxResolution, isPortraitMode, audioStream } = await video.getMaxQualityFileInfo() 32 const { resolution: maxResolution, isPortraitMode, audioStream } = await video.probeMaxQualityFile()
33 const resolutions = computeLowerResolutionsToTranscode(maxResolution, 'vod').concat([ maxResolution ]) 33 const resolutions = computeLowerResolutionsToTranscode(maxResolution, 'vod').concat([ maxResolution ])
34 34
35 video.state = VideoState.TO_TRANSCODE 35 video.state = VideoState.TO_TRANSCODE
diff --git a/server/controllers/api/videos/update.ts b/server/controllers/api/videos/update.ts
index c01d9276a..15899307d 100644
--- a/server/controllers/api/videos/update.ts
+++ b/server/controllers/api/videos/update.ts
@@ -11,7 +11,6 @@ import { auditLoggerFactory, getAuditIdFromRes, VideoAuditView } from '../../../
11import { resetSequelizeInstance } from '../../../helpers/database-utils' 11import { resetSequelizeInstance } from '../../../helpers/database-utils'
12import { createReqFiles } from '../../../helpers/express-utils' 12import { createReqFiles } from '../../../helpers/express-utils'
13import { logger, loggerTagsFactory } from '../../../helpers/logger' 13import { logger, loggerTagsFactory } from '../../../helpers/logger'
14import { CONFIG } from '../../../initializers/config'
15import { MIMETYPES } from '../../../initializers/constants' 14import { MIMETYPES } from '../../../initializers/constants'
16import { sequelizeTypescript } from '../../../initializers/database' 15import { sequelizeTypescript } from '../../../initializers/database'
17import { federateVideoIfNeeded } from '../../../lib/activitypub/videos' 16import { federateVideoIfNeeded } from '../../../lib/activitypub/videos'
@@ -26,14 +25,7 @@ const lTags = loggerTagsFactory('api', 'video')
26const auditLogger = auditLoggerFactory('videos') 25const auditLogger = auditLoggerFactory('videos')
27const updateRouter = express.Router() 26const updateRouter = express.Router()
28 27
29const reqVideoFileUpdate = createReqFiles( 28const reqVideoFileUpdate = createReqFiles([ 'thumbnailfile', 'previewfile' ], MIMETYPES.IMAGE.MIMETYPE_EXT)
30 [ 'thumbnailfile', 'previewfile' ],
31 MIMETYPES.IMAGE.MIMETYPE_EXT,
32 {
33 thumbnailfile: CONFIG.STORAGE.TMP_DIR,
34 previewfile: CONFIG.STORAGE.TMP_DIR
35 }
36)
37 29
38updateRouter.put('/:id', 30updateRouter.put('/:id',
39 openapiOperationDoc({ operationId: 'putVideo' }), 31 openapiOperationDoc({ operationId: 'putVideo' }),
diff --git a/server/controllers/api/videos/upload.ts b/server/controllers/api/videos/upload.ts
index fd90d9915..dd69cf238 100644
--- a/server/controllers/api/videos/upload.ts
+++ b/server/controllers/api/videos/upload.ts
@@ -24,9 +24,8 @@ import { HttpStatusCode, VideoCreate, VideoResolution, VideoState } from '@share
24import { auditLoggerFactory, getAuditIdFromRes, VideoAuditView } from '../../../helpers/audit-logger' 24import { auditLoggerFactory, getAuditIdFromRes, VideoAuditView } from '../../../helpers/audit-logger'
25import { retryTransactionWrapper } from '../../../helpers/database-utils' 25import { retryTransactionWrapper } from '../../../helpers/database-utils'
26import { createReqFiles } from '../../../helpers/express-utils' 26import { createReqFiles } from '../../../helpers/express-utils'
27import { ffprobePromise, getMetadataFromFile, getVideoFileFPS, getVideoFileResolution } from '../../../helpers/ffprobe-utils' 27import { buildFileMetadata, ffprobePromise, getVideoStreamDimensionsInfo, getVideoStreamFPS } from '../../../helpers/ffmpeg'
28import { logger, loggerTagsFactory } from '../../../helpers/logger' 28import { logger, loggerTagsFactory } from '../../../helpers/logger'
29import { CONFIG } from '../../../initializers/config'
30import { MIMETYPES } from '../../../initializers/constants' 29import { MIMETYPES } from '../../../initializers/constants'
31import { sequelizeTypescript } from '../../../initializers/database' 30import { sequelizeTypescript } from '../../../initializers/database'
32import { federateVideoIfNeeded } from '../../../lib/activitypub/videos' 31import { federateVideoIfNeeded } from '../../../lib/activitypub/videos'
@@ -52,21 +51,13 @@ const uploadRouter = express.Router()
52 51
53const reqVideoFileAdd = createReqFiles( 52const reqVideoFileAdd = createReqFiles(
54 [ 'videofile', 'thumbnailfile', 'previewfile' ], 53 [ 'videofile', 'thumbnailfile', 'previewfile' ],
55 Object.assign({}, MIMETYPES.VIDEO.MIMETYPE_EXT, MIMETYPES.IMAGE.MIMETYPE_EXT), 54 { ...MIMETYPES.VIDEO.MIMETYPE_EXT, ...MIMETYPES.IMAGE.MIMETYPE_EXT }
56 {
57 videofile: CONFIG.STORAGE.TMP_DIR,
58 thumbnailfile: CONFIG.STORAGE.TMP_DIR,
59 previewfile: CONFIG.STORAGE.TMP_DIR
60 }
61) 55)
62 56
63const reqVideoFileAddResumable = createReqFiles( 57const reqVideoFileAddResumable = createReqFiles(
64 [ 'thumbnailfile', 'previewfile' ], 58 [ 'thumbnailfile', 'previewfile' ],
65 MIMETYPES.IMAGE.MIMETYPE_EXT, 59 MIMETYPES.IMAGE.MIMETYPE_EXT,
66 { 60 getResumableUploadPath()
67 thumbnailfile: getResumableUploadPath(),
68 previewfile: getResumableUploadPath()
69 }
70) 61)
71 62
72uploadRouter.post('/upload', 63uploadRouter.post('/upload',
@@ -246,7 +237,7 @@ async function buildNewFile (videoPhysicalFile: express.VideoUploadFile) {
246 extname: getLowercaseExtension(videoPhysicalFile.filename), 237 extname: getLowercaseExtension(videoPhysicalFile.filename),
247 size: videoPhysicalFile.size, 238 size: videoPhysicalFile.size,
248 videoStreamingPlaylistId: null, 239 videoStreamingPlaylistId: null,
249 metadata: await getMetadataFromFile(videoPhysicalFile.path) 240 metadata: await buildFileMetadata(videoPhysicalFile.path)
250 }) 241 })
251 242
252 const probe = await ffprobePromise(videoPhysicalFile.path) 243 const probe = await ffprobePromise(videoPhysicalFile.path)
@@ -254,8 +245,8 @@ async function buildNewFile (videoPhysicalFile: express.VideoUploadFile) {
254 if (await isAudioFile(videoPhysicalFile.path, probe)) { 245 if (await isAudioFile(videoPhysicalFile.path, probe)) {
255 videoFile.resolution = VideoResolution.H_NOVIDEO 246 videoFile.resolution = VideoResolution.H_NOVIDEO
256 } else { 247 } else {
257 videoFile.fps = await getVideoFileFPS(videoPhysicalFile.path, probe) 248 videoFile.fps = await getVideoStreamFPS(videoPhysicalFile.path, probe)
258 videoFile.resolution = (await getVideoFileResolution(videoPhysicalFile.path, probe)).resolution 249 videoFile.resolution = (await getVideoStreamDimensionsInfo(videoPhysicalFile.path, probe)).resolution
259 } 250 }
260 251
261 videoFile.filename = generateWebTorrentVideoFilename(videoFile.resolution, videoFile.extname) 252 videoFile.filename = generateWebTorrentVideoFilename(videoFile.resolution, videoFile.extname)