aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--server/helpers/ffmpeg-utils.ts13
-rw-r--r--server/tests/api/videos/video-transcoder.ts16
-rw-r--r--shared/extra-utils/miscs/miscs.ts2
4 files changed, 20 insertions, 12 deletions
diff --git a/.gitignore b/.gitignore
index 6ef90385c..07b2fb7ef 100644
--- a/.gitignore
+++ b/.gitignore
@@ -12,6 +12,7 @@ yarn-error.log
12/test5/ 12/test5/
13/test6/ 13/test6/
14/server/tests/fixtures/video_high_bitrate_1080p.mp4 14/server/tests/fixtures/video_high_bitrate_1080p.mp4
15/server/tests/fixtures/video_59fps.mp4
15 16
16# Production 17# Production
17/storage/ 18/storage/
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
diff --git a/shared/extra-utils/miscs/miscs.ts b/shared/extra-utils/miscs/miscs.ts
index c957a6abe..d04003988 100644
--- a/shared/extra-utils/miscs/miscs.ts
+++ b/shared/extra-utils/miscs/miscs.ts
@@ -113,7 +113,7 @@ async function generateVideoWithFramerate (fps = 60) {
113 if (!exists) { 113 if (!exists) {
114 return new Promise<string>(async (res, rej) => { 114 return new Promise<string>(async (res, rej) => {
115 ffmpeg() 115 ffmpeg()
116 .outputOptions([ '-f rawvideo', '-video_size 320x240', '-i /dev/urandom' ]) 116 .outputOptions([ '-f rawvideo', '-video_size 1280x720', '-i /dev/urandom' ])
117 .outputOptions([ '-ac 2', '-f s16le', '-i /dev/urandom', '-t 10' ]) 117 .outputOptions([ '-ac 2', '-f s16le', '-i /dev/urandom', '-t 10' ])
118 .outputOptions([ `-r ${fps}` ]) 118 .outputOptions([ `-r ${fps}` ])
119 .output(tempFixturePath) 119 .output(tempFixturePath)