aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers
diff options
context:
space:
mode:
authorRigel Kent <sendmemail@rigelk.eu>2020-01-14 23:34:03 +0100
committerChocobozzz <chocobozzz@cpy.re>2020-01-29 13:42:15 +0100
commit06bcfbd9f715055f2f00bb66149b1dba926d007a (patch)
tree253059fe56f9c1ab818ab60b4871a67a945b229f /server/helpers
parent0539dba824bc3b964faaba358d8e7836e006b899 (diff)
downloadPeerTube-06bcfbd9f715055f2f00bb66149b1dba926d007a.tar.gz
PeerTube-06bcfbd9f715055f2f00bb66149b1dba926d007a.tar.zst
PeerTube-06bcfbd9f715055f2f00bb66149b1dba926d007a.zip
Downsample to the closest divisor standard framerate
Diffstat (limited to 'server/helpers')
-rw-r--r--server/helpers/ffmpeg-utils.ts11
1 files changed, 7 insertions, 4 deletions
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
287async function buildx264Command (command: ffmpeg.FfmpegCommand, options: TranscodeOptions) { 287async 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)