diff options
author | Rigel Kent <sendmemail@rigelk.eu> | 2020-01-14 23:34:03 +0100 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2020-01-29 13:42:15 +0100 |
commit | 06bcfbd9f715055f2f00bb66149b1dba926d007a (patch) | |
tree | 253059fe56f9c1ab818ab60b4871a67a945b229f /server | |
parent | 0539dba824bc3b964faaba358d8e7836e006b899 (diff) | |
download | PeerTube-06bcfbd9f715055f2f00bb66149b1dba926d007a.tar.gz PeerTube-06bcfbd9f715055f2f00bb66149b1dba926d007a.tar.zst PeerTube-06bcfbd9f715055f2f00bb66149b1dba926d007a.zip |
Downsample to the closest divisor standard framerate
Diffstat (limited to 'server')
-rw-r--r-- | server/controllers/api/videos/index.ts | 3 | ||||
-rw-r--r-- | server/helpers/ffmpeg-utils.ts | 11 | ||||
-rw-r--r-- | server/initializers/constants.ts | 2 | ||||
-rw-r--r-- | server/middlewares/validators/videos/videos.ts | 2 |
4 files changed, 12 insertions, 6 deletions
diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts index 8d4ff07eb..a593f7076 100644 --- a/server/controllers/api/videos/index.ts +++ b/server/controllers/api/videos/index.ts | |||
@@ -12,7 +12,8 @@ import { | |||
12 | VIDEO_CATEGORIES, | 12 | VIDEO_CATEGORIES, |
13 | VIDEO_LANGUAGES, | 13 | VIDEO_LANGUAGES, |
14 | VIDEO_LICENCES, | 14 | VIDEO_LICENCES, |
15 | VIDEO_PRIVACIES | 15 | VIDEO_PRIVACIES, |
16 | VIDEO_TRANSCODING_FPS | ||
16 | } from '../../../initializers/constants' | 17 | } from '../../../initializers/constants' |
17 | import { | 18 | import { |
18 | changeVideoChannelShare, | 19 | changeVideoChannelShare, |
diff --git a/server/helpers/ffmpeg-utils.ts b/server/helpers/ffmpeg-utils.ts index 00c32e99a..78f9ba07c 100644 --- a/server/helpers/ffmpeg-utils.ts +++ b/server/helpers/ffmpeg-utils.ts | |||
@@ -286,13 +286,16 @@ export { | |||
286 | 286 | ||
287 | async function buildx264Command (command: ffmpeg.FfmpegCommand, options: TranscodeOptions) { | 287 | async function buildx264Command (command: ffmpeg.FfmpegCommand, options: TranscodeOptions) { |
288 | let fps = await getVideoFileFPS(options.inputPath) | 288 | let fps = await getVideoFileFPS(options.inputPath) |
289 | // On small/medium resolutions, limit FPS | ||
290 | if ( | 289 | if ( |
290 | // On small/medium resolutions, limit FPS | ||
291 | options.resolution !== undefined && | 291 | options.resolution !== undefined && |
292 | options.resolution < VIDEO_TRANSCODING_FPS.KEEP_ORIGIN_FPS_RESOLUTION_MIN && | 292 | options.resolution < VIDEO_TRANSCODING_FPS.KEEP_ORIGIN_FPS_RESOLUTION_MIN && |
293 | fps > VIDEO_TRANSCODING_FPS.AVERAGE | 293 | fps > VIDEO_TRANSCODING_FPS.AVERAGE || |
294 | // If the video is doesn't match had standard | ||
295 | !VIDEO_TRANSCODING_FPS.HD_STANDARD.map(value => fps % value).includes(0) | ||
294 | ) { | 296 | ) { |
295 | fps = VIDEO_TRANSCODING_FPS.AVERAGE | 297 | // Get closest standard framerate by modulo: downsampling has to be done to a divisor of the nominal fps value |
298 | fps = VIDEO_TRANSCODING_FPS.STANDARD.sort((a, b) => fps % a - fps % b)[0] | ||
296 | } | 299 | } |
297 | 300 | ||
298 | command = await presetH264(command, options.inputPath, options.resolution, fps) | 301 | command = await presetH264(command, options.inputPath, options.resolution, fps) |
@@ -305,7 +308,7 @@ async function buildx264Command (command: ffmpeg.FfmpegCommand, options: Transco | |||
305 | 308 | ||
306 | if (fps) { | 309 | if (fps) { |
307 | // Hard FPS limits | 310 | // Hard FPS limits |
308 | if (fps > VIDEO_TRANSCODING_FPS.MAX) fps = VIDEO_TRANSCODING_FPS.MAX | 311 | if (fps > VIDEO_TRANSCODING_FPS.MAX) fps = VIDEO_TRANSCODING_FPS.HD_STANDARD.sort((a, b) => fps % a - fps % b)[0] |
309 | else if (fps < VIDEO_TRANSCODING_FPS.MIN) fps = VIDEO_TRANSCODING_FPS.MIN | 312 | else if (fps < VIDEO_TRANSCODING_FPS.MIN) fps = VIDEO_TRANSCODING_FPS.MIN |
310 | 313 | ||
311 | command = command.withFPS(fps) | 314 | command = command.withFPS(fps) |
diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts index e01ab8943..64803b1db 100644 --- a/server/initializers/constants.ts +++ b/server/initializers/constants.ts | |||
@@ -310,6 +310,8 @@ let CONTACT_FORM_LIFETIME = 60000 * 60 // 1 hour | |||
310 | 310 | ||
311 | const VIDEO_TRANSCODING_FPS: VideoTranscodingFPS = { | 311 | const VIDEO_TRANSCODING_FPS: VideoTranscodingFPS = { |
312 | MIN: 10, | 312 | MIN: 10, |
313 | STANDARD: [24, 25, 30], | ||
314 | HD_STANDARD: [50, 60], | ||
313 | AVERAGE: 30, | 315 | AVERAGE: 30, |
314 | MAX: 60, | 316 | MAX: 60, |
315 | KEEP_ORIGIN_FPS_RESOLUTION_MIN: 720 // We keep the original FPS on high resolutions (720 minimum) | 317 | KEEP_ORIGIN_FPS_RESOLUTION_MIN: 720 // We keep the original FPS on high resolutions (720 minimum) |
diff --git a/server/middlewares/validators/videos/videos.ts b/server/middlewares/validators/videos/videos.ts index 6733d9dec..00ee375cb 100644 --- a/server/middlewares/validators/videos/videos.ts +++ b/server/middlewares/validators/videos/videos.ts | |||
@@ -81,7 +81,7 @@ const videosAddValidator = getCommonVideoEditAttributes().concat([ | |||
81 | duration = await getDurationFromVideoFile(videoFile.path) | 81 | duration = await getDurationFromVideoFile(videoFile.path) |
82 | } catch (err) { | 82 | } catch (err) { |
83 | logger.error('Invalid input file in videosAddValidator.', { err }) | 83 | logger.error('Invalid input file in videosAddValidator.', { err }) |
84 | res.status(400) | 84 | res.status(422) |
85 | .json({ error: 'Invalid input file.' }) | 85 | .json({ error: 'Invalid input file.' }) |
86 | 86 | ||
87 | return cleanUpReqFiles(req) | 87 | return cleanUpReqFiles(req) |