aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers/api')
-rw-r--r--server/controllers/api/config.ts1
-rw-r--r--server/controllers/api/videos/index.ts38
2 files changed, 27 insertions, 12 deletions
diff --git a/server/controllers/api/config.ts b/server/controllers/api/config.ts
index 40012c03b..d9ce6a153 100644
--- a/server/controllers/api/config.ts
+++ b/server/controllers/api/config.ts
@@ -255,6 +255,7 @@ function customConfig (): CustomConfig {
255 transcoding: { 255 transcoding: {
256 enabled: CONFIG.TRANSCODING.ENABLED, 256 enabled: CONFIG.TRANSCODING.ENABLED,
257 allowAdditionalExtensions: CONFIG.TRANSCODING.ALLOW_ADDITIONAL_EXTENSIONS, 257 allowAdditionalExtensions: CONFIG.TRANSCODING.ALLOW_ADDITIONAL_EXTENSIONS,
258 allowAudioFiles: CONFIG.TRANSCODING.ALLOW_AUDIO_FILES,
258 threads: CONFIG.TRANSCODING.THREADS, 259 threads: CONFIG.TRANSCODING.THREADS,
259 resolutions: { 260 resolutions: {
260 '240p': CONFIG.TRANSCODING.RESOLUTIONS[ '240p' ], 261 '240p': CONFIG.TRANSCODING.RESOLUTIONS[ '240p' ],
diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts
index 1a18a8ae8..a2a615a79 100644
--- a/server/controllers/api/videos/index.ts
+++ b/server/controllers/api/videos/index.ts
@@ -1,12 +1,12 @@
1import * as express from 'express' 1import * as express from 'express'
2import { extname, join } from 'path' 2import { extname, join } from 'path'
3import { VideoCreate, VideoPrivacy, VideoState, VideoUpdate } from '../../../../shared' 3import { VideoCreate, VideoPrivacy, VideoResolution, VideoState, VideoUpdate } from '../../../../shared'
4import { getVideoFileFPS, getVideoFileResolution } from '../../../helpers/ffmpeg-utils' 4import { getVideoFileFPS, getVideoFileResolution } from '../../../helpers/ffmpeg-utils'
5import { logger } from '../../../helpers/logger' 5import { logger } from '../../../helpers/logger'
6import { auditLoggerFactory, getAuditIdFromRes, VideoAuditView } from '../../../helpers/audit-logger' 6import { auditLoggerFactory, getAuditIdFromRes, VideoAuditView } from '../../../helpers/audit-logger'
7import { getFormattedObjects, getServerActor } from '../../../helpers/utils' 7import { getFormattedObjects, getServerActor } from '../../../helpers/utils'
8import { autoBlacklistVideoIfNeeded } from '../../../lib/video-blacklist' 8import { autoBlacklistVideoIfNeeded } from '../../../lib/video-blacklist'
9import { MIMETYPES, VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../../initializers/constants' 9import { MIMETYPES, VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES, DEFAULT_AUDIO_RESOLUTION } from '../../../initializers/constants'
10import { 10import {
11 changeVideoChannelShare, 11 changeVideoChannelShare,
12 federateVideoIfNeeded, 12 federateVideoIfNeeded,
@@ -54,6 +54,7 @@ import { CONFIG } from '../../../initializers/config'
54import { sequelizeTypescript } from '../../../initializers/database' 54import { sequelizeTypescript } from '../../../initializers/database'
55import { createVideoMiniatureFromExisting, generateVideoMiniature } from '../../../lib/thumbnail' 55import { createVideoMiniatureFromExisting, generateVideoMiniature } from '../../../lib/thumbnail'
56import { ThumbnailType } from '../../../../shared/models/videos/thumbnail.type' 56import { ThumbnailType } from '../../../../shared/models/videos/thumbnail.type'
57import { VideoTranscodingPayload } from '../../../lib/job-queue/handlers/video-transcoding'
57 58
58const auditLogger = auditLoggerFactory('videos') 59const auditLogger = auditLoggerFactory('videos')
59const videosRouter = express.Router() 60const videosRouter = express.Router()
@@ -191,18 +192,19 @@ async function addVideo (req: express.Request, res: express.Response) {
191 const video = new VideoModel(videoData) 192 const video = new VideoModel(videoData)
192 video.url = getVideoActivityPubUrl(video) // We use the UUID, so set the URL after building the object 193 video.url = getVideoActivityPubUrl(video) // We use the UUID, so set the URL after building the object
193 194
194 // Build the file object
195 const { videoFileResolution } = await getVideoFileResolution(videoPhysicalFile.path)
196 const fps = await getVideoFileFPS(videoPhysicalFile.path)
197
198 const videoFileData = { 195 const videoFileData = {
199 extname: extname(videoPhysicalFile.filename), 196 extname: extname(videoPhysicalFile.filename),
200 resolution: videoFileResolution, 197 size: videoPhysicalFile.size
201 size: videoPhysicalFile.size,
202 fps
203 } 198 }
204 const videoFile = new VideoFileModel(videoFileData) 199 const videoFile = new VideoFileModel(videoFileData)
205 200
201 if (!videoFile.isAudio()) {
202 videoFile.fps = await getVideoFileFPS(videoPhysicalFile.path)
203 videoFile.resolution = (await getVideoFileResolution(videoPhysicalFile.path)).videoFileResolution
204 } else {
205 videoFile.resolution = DEFAULT_AUDIO_RESOLUTION
206 }
207
206 // Move physical file 208 // Move physical file
207 const videoDir = CONFIG.STORAGE.VIDEOS_DIR 209 const videoDir = CONFIG.STORAGE.VIDEOS_DIR
208 const destination = join(videoDir, video.getVideoFilename(videoFile)) 210 const destination = join(videoDir, video.getVideoFilename(videoFile))
@@ -279,9 +281,21 @@ async function addVideo (req: express.Request, res: express.Response) {
279 281
280 if (video.state === VideoState.TO_TRANSCODE) { 282 if (video.state === VideoState.TO_TRANSCODE) {
281 // Put uuid because we don't have id auto incremented for now 283 // Put uuid because we don't have id auto incremented for now
282 const dataInput = { 284 let dataInput: VideoTranscodingPayload
283 videoUUID: videoCreated.uuid, 285
284 isNewVideo: true 286 if (videoFile.isAudio()) {
287 dataInput = {
288 type: 'merge-audio' as 'merge-audio',
289 resolution: DEFAULT_AUDIO_RESOLUTION,
290 videoUUID: videoCreated.uuid,
291 isNewVideo: true
292 }
293 } else {
294 dataInput = {
295 type: 'optimize' as 'optimize',
296 videoUUID: videoCreated.uuid,
297 isNewVideo: true
298 }
285 } 299 }
286 300
287 await JobQueue.Instance.createJob({ type: 'video-transcoding', payload: dataInput }) 301 await JobQueue.Instance.createJob({ type: 'video-transcoding', payload: dataInput })