aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers
diff options
context:
space:
mode:
authorRigel Kent <sendmemail@rigelk.eu>2020-01-20 20:40:30 +0100
committerChocobozzz <chocobozzz@cpy.re>2020-01-29 13:42:15 +0100
commit837666fe48f9ed786db75c96e2025cbcf20a1e3b (patch)
tree3c67248ea0669b18b6861f9630a2070d5d423eb1 /server/helpers
parent06bcfbd9f715055f2f00bb66149b1dba926d007a (diff)
downloadPeerTube-837666fe48f9ed786db75c96e2025cbcf20a1e3b.tar.gz
PeerTube-837666fe48f9ed786db75c96e2025cbcf20a1e3b.tar.zst
PeerTube-837666fe48f9ed786db75c96e2025cbcf20a1e3b.zip
Add tests for video downscale framerate matching
Diffstat (limited to 'server/helpers')
-rw-r--r--server/helpers/ffmpeg-utils.ts12
-rw-r--r--server/helpers/logger.ts2
2 files changed, 9 insertions, 5 deletions
diff --git a/server/helpers/ffmpeg-utils.ts b/server/helpers/ffmpeg-utils.ts
index 78f9ba07c..63dc5b6a3 100644
--- a/server/helpers/ffmpeg-utils.ts
+++ b/server/helpers/ffmpeg-utils.ts
@@ -263,6 +263,10 @@ async function canDoQuickTranscode (path: string): Promise<boolean> {
263 return true 263 return true
264} 264}
265 265
266function getClosestFramerateStandard (fps: number, hd = false): number {
267 return VIDEO_TRANSCODING_FPS[hd ? 'HD_STANDARD' : 'STANDARD'].slice(0).sort((a, b) => fps % a - fps % b)[0]
268}
269
266// --------------------------------------------------------------------------- 270// ---------------------------------------------------------------------------
267 271
268export { 272export {
@@ -291,11 +295,11 @@ async function buildx264Command (command: ffmpeg.FfmpegCommand, options: Transco
291 options.resolution !== undefined && 295 options.resolution !== undefined &&
292 options.resolution < VIDEO_TRANSCODING_FPS.KEEP_ORIGIN_FPS_RESOLUTION_MIN && 296 options.resolution < VIDEO_TRANSCODING_FPS.KEEP_ORIGIN_FPS_RESOLUTION_MIN &&
293 fps > VIDEO_TRANSCODING_FPS.AVERAGE || 297 fps > VIDEO_TRANSCODING_FPS.AVERAGE ||
294 // If the video is doesn't match had standard 298 // If the video is doesn't match hd standard
295 !VIDEO_TRANSCODING_FPS.HD_STANDARD.map(value => fps % value).includes(0) 299 !VIDEO_TRANSCODING_FPS.HD_STANDARD.some(value => fps % value === 0)
296 ) { 300 ) {
297 // Get closest standard framerate by modulo: downsampling has to be done to a divisor of the nominal fps value 301 // 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] 302 fps = getClosestFramerateStandard(fps)
299 } 303 }
300 304
301 command = await presetH264(command, options.inputPath, options.resolution, fps) 305 command = await presetH264(command, options.inputPath, options.resolution, fps)
@@ -308,7 +312,7 @@ async function buildx264Command (command: ffmpeg.FfmpegCommand, options: Transco
308 312
309 if (fps) { 313 if (fps) {
310 // Hard FPS limits 314 // Hard FPS limits
311 if (fps > VIDEO_TRANSCODING_FPS.MAX) fps = VIDEO_TRANSCODING_FPS.HD_STANDARD.sort((a, b) => fps % a - fps % b)[0] 315 if (fps > VIDEO_TRANSCODING_FPS.MAX) fps = getClosestFramerateStandard(fps, true)
312 else if (fps < VIDEO_TRANSCODING_FPS.MIN) fps = VIDEO_TRANSCODING_FPS.MIN 316 else if (fps < VIDEO_TRANSCODING_FPS.MIN) fps = VIDEO_TRANSCODING_FPS.MIN
313 317
314 command = command.withFPS(fps) 318 command = command.withFPS(fps)
diff --git a/server/helpers/logger.ts b/server/helpers/logger.ts
index 395417612..fd2988ad0 100644
--- a/server/helpers/logger.ts
+++ b/server/helpers/logger.ts
@@ -5,7 +5,7 @@ import * as winston from 'winston'
5import { FileTransportOptions } from 'winston/lib/winston/transports' 5import { FileTransportOptions } from 'winston/lib/winston/transports'
6import { CONFIG } from '../initializers/config' 6import { CONFIG } from '../initializers/config'
7import { omit } from 'lodash' 7import { omit } from 'lodash'
8import { LOG_FILENAME } from '@server/initializers/constants' 8import { LOG_FILENAME } from '../initializers/constants'
9 9
10const label = CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT 10const label = CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT
11 11