aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/helpers/ffmpeg-utils.ts13
-rw-r--r--server/tests/api/videos/video-transcoder.ts16
2 files changed, 18 insertions, 11 deletions
diff --git a/server/helpers/ffmpeg-utils.ts b/server/helpers/ffmpeg-utils.ts
index 63dc5b6a3..7022d3e03 100644
--- a/server/helpers/ffmpeg-utils.ts
+++ b/server/helpers/ffmpeg-utils.ts
@@ -263,8 +263,9 @@ async function canDoQuickTranscode (path: string): Promise<boolean> {
263 return true 263 return true
264} 264}
265 265
266function getClosestFramerateStandard (fps: number, hd = false): number { 266function getClosestFramerateStandard (fps: number, type: 'HD_STANDARD' | 'STANDARD'): number {
267 return VIDEO_TRANSCODING_FPS[hd ? 'HD_STANDARD' : 'STANDARD'].slice(0).sort((a, b) => fps % a - fps % b)[0] 267 return VIDEO_TRANSCODING_FPS[type].slice(0)
268 .sort((a, b) => fps % a - fps % b)[0]
268} 269}
269 270
270// --------------------------------------------------------------------------- 271// ---------------------------------------------------------------------------
@@ -294,12 +295,10 @@ async function buildx264Command (command: ffmpeg.FfmpegCommand, options: Transco
294 // On small/medium resolutions, limit FPS 295 // On small/medium resolutions, limit FPS
295 options.resolution !== undefined && 296 options.resolution !== undefined &&
296 options.resolution < VIDEO_TRANSCODING_FPS.KEEP_ORIGIN_FPS_RESOLUTION_MIN && 297 options.resolution < VIDEO_TRANSCODING_FPS.KEEP_ORIGIN_FPS_RESOLUTION_MIN &&
297 fps > VIDEO_TRANSCODING_FPS.AVERAGE || 298 fps > VIDEO_TRANSCODING_FPS.AVERAGE
298 // If the video is doesn't match hd standard
299 !VIDEO_TRANSCODING_FPS.HD_STANDARD.some(value => fps % value === 0)
300 ) { 299 ) {
301 // Get closest standard framerate by modulo: downsampling has to be done to a divisor of the nominal fps value 300 // Get closest standard framerate by modulo: downsampling has to be done to a divisor of the nominal fps value
302 fps = getClosestFramerateStandard(fps) 301 fps = getClosestFramerateStandard(fps, 'STANDARD')
303 } 302 }
304 303
305 command = await presetH264(command, options.inputPath, options.resolution, fps) 304 command = await presetH264(command, options.inputPath, options.resolution, fps)
@@ -312,7 +311,7 @@ async function buildx264Command (command: ffmpeg.FfmpegCommand, options: Transco
312 311
313 if (fps) { 312 if (fps) {
314 // Hard FPS limits 313 // Hard FPS limits
315 if (fps > VIDEO_TRANSCODING_FPS.MAX) fps = getClosestFramerateStandard(fps, true) 314 if (fps > VIDEO_TRANSCODING_FPS.MAX) fps = getClosestFramerateStandard(fps, 'HD_STANDARD')
316 else if (fps < VIDEO_TRANSCODING_FPS.MIN) fps = VIDEO_TRANSCODING_FPS.MIN 315 else if (fps < VIDEO_TRANSCODING_FPS.MIN) fps = VIDEO_TRANSCODING_FPS.MIN
317 316
318 command = command.withFPS(fps) 317 command = command.withFPS(fps)
diff --git a/server/tests/api/videos/video-transcoder.ts b/server/tests/api/videos/video-transcoder.ts
index 0104c94fc..55eb76b3b 100644
--- a/server/tests/api/videos/video-transcoder.ts
+++ b/server/tests/api/videos/video-transcoder.ts
@@ -423,7 +423,7 @@ describe('Test video transcoding', function () {
423 let tempFixturePath: string 423 let tempFixturePath: string
424 424
425 { 425 {
426 tempFixturePath = await generateVideoWithFramerate() 426 tempFixturePath = await generateVideoWithFramerate(59)
427 427
428 const fps = await getVideoFileFPS(tempFixturePath) 428 const fps = await getVideoFileFPS(tempFixturePath)
429 expect(fps).to.be.equal(59) 429 expect(fps).to.be.equal(59)
@@ -443,10 +443,18 @@ describe('Test video transcoding', function () {
443 const res = await getVideosList(server.url) 443 const res = await getVideosList(server.url)
444 444
445 const video = res.body.data.find(v => v.name === videoAttributes.name) 445 const video = res.body.data.find(v => v.name === videoAttributes.name)
446 const path = join(root(), 'test' + servers[1].internalServerNumber, 'videos', video.uuid + '-240.mp4')
447 const fps = await getVideoFileFPS(path)
448 446
449 expect(fps).to.be.equal(25) 447 {
448 const path = join(root(), 'test' + servers[ 1 ].internalServerNumber, 'videos', video.uuid + '-240.mp4')
449 const fps = await getVideoFileFPS(path)
450 expect(fps).to.be.equal(25)
451 }
452
453 {
454 const path = join(root(), 'test' + servers[ 1 ].internalServerNumber, 'videos', video.uuid + '-720.mp4')
455 const fps = await getVideoFileFPS(path)
456 expect(fps).to.be.equal(59)
457 }
450 } 458 }
451 }) 459 })
452 460