From 3a6f351b255d21ec42578632600ba699885f350e Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 29 Jun 2018 16:41:29 +0200 Subject: Handle higher FPS for high resolution (test) --- server/helpers/custom-validators/videos.ts | 5 +++++ server/helpers/ffmpeg-utils.ts | 25 ++++++++++++++++++------- 2 files changed, 23 insertions(+), 7 deletions(-) (limited to 'server/helpers') diff --git a/server/helpers/custom-validators/videos.ts b/server/helpers/custom-validators/videos.ts index ae392f8c2..672f06dc0 100644 --- a/server/helpers/custom-validators/videos.ts +++ b/server/helpers/custom-validators/videos.ts @@ -118,6 +118,10 @@ function isVideoFileResolutionValid (value: string) { return exists(value) && validator.isInt(value + '') } +function isVideoFPSResolutionValid (value: string) { + return value === null || validator.isInt(value + '') +} + function isVideoFileSizeValid (value: string) { return exists(value) && validator.isInt(value + '', VIDEOS_CONSTRAINTS_FIELDS.FILE_SIZE) } @@ -182,6 +186,7 @@ export { isVideoFileInfoHashValid, isVideoNameValid, isVideoTagsValid, + isVideoFPSResolutionValid, isScheduleVideoUpdatePrivacyValid, isVideoAbuseReasonValid, isVideoFile, diff --git a/server/helpers/ffmpeg-utils.ts b/server/helpers/ffmpeg-utils.ts index bfc942fa3..4086335d7 100644 --- a/server/helpers/ffmpeg-utils.ts +++ b/server/helpers/ffmpeg-utils.ts @@ -26,7 +26,7 @@ async function getVideoFileFPS (path: string) { if (!frames || !seconds) continue const result = parseInt(frames, 10) / parseInt(seconds, 10) - if (result > 0) return result + if (result > 0) return Math.round(result) } return 0 @@ -83,8 +83,6 @@ type TranscodeOptions = { function transcode (options: TranscodeOptions) { return new Promise(async (res, rej) => { - const fps = await getVideoFileFPS(options.inputPath) - let command = ffmpeg(options.inputPath) .output(options.outputPath) .videoCodec('libx264') @@ -92,14 +90,27 @@ function transcode (options: TranscodeOptions) { .outputOption('-movflags faststart') // .outputOption('-crf 18') - // Our player has some FPS limits - if (fps > VIDEO_TRANSCODING_FPS.MAX) command = command.withFPS(VIDEO_TRANSCODING_FPS.MAX) - else if (fps < VIDEO_TRANSCODING_FPS.MIN) command = command.withFPS(VIDEO_TRANSCODING_FPS.MIN) - + let fps = await getVideoFileFPS(options.inputPath) if (options.resolution !== undefined) { // '?x720' or '720x?' for example const size = options.isPortraitMode === true ? `${options.resolution}x?` : `?x${options.resolution}` command = command.size(size) + + // On small/medium resolutions, limit FPS + if ( + options.resolution < VIDEO_TRANSCODING_FPS.KEEP_ORIGIN_FPS_RESOLUTION_MIN && + fps > VIDEO_TRANSCODING_FPS.AVERAGE + ) { + fps = VIDEO_TRANSCODING_FPS.AVERAGE + } + } + + if (fps) { + // Hard FPS limits + if (fps > VIDEO_TRANSCODING_FPS.MAX) fps = VIDEO_TRANSCODING_FPS.MAX + else if (fps < VIDEO_TRANSCODING_FPS.MIN) fps = VIDEO_TRANSCODING_FPS.MIN + + command = command.withFPS(fps) } command -- cgit v1.2.3