From 0c9668f77901e7540e2c7045eb0f2974a4842a69 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 21 Apr 2023 14:55:10 +0200 Subject: Implement remote runner jobs in server Move ffmpeg functions to @shared --- server/helpers/ffmpeg/framerate.ts | 44 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 server/helpers/ffmpeg/framerate.ts (limited to 'server/helpers/ffmpeg/framerate.ts') diff --git a/server/helpers/ffmpeg/framerate.ts b/server/helpers/ffmpeg/framerate.ts new file mode 100644 index 000000000..18cb0e0e2 --- /dev/null +++ b/server/helpers/ffmpeg/framerate.ts @@ -0,0 +1,44 @@ +import { VIDEO_TRANSCODING_FPS } from '@server/initializers/constants' +import { VideoResolution } from '@shared/models' + +export function computeOutputFPS (options: { + inputFPS: number + resolution: VideoResolution +}) { + const { resolution } = options + + let fps = options.inputFPS + + if ( + // On small/medium resolutions, limit FPS + resolution !== undefined && + resolution < VIDEO_TRANSCODING_FPS.KEEP_ORIGIN_FPS_RESOLUTION_MIN && + fps > VIDEO_TRANSCODING_FPS.AVERAGE + ) { + // Get closest standard framerate by modulo: downsampling has to be done to a divisor of the nominal fps value + fps = getClosestFramerateStandard({ fps, type: 'STANDARD' }) + } + + // Hard FPS limits + if (fps > VIDEO_TRANSCODING_FPS.MAX) fps = getClosestFramerateStandard({ fps, type: 'HD_STANDARD' }) + + if (fps < VIDEO_TRANSCODING_FPS.MIN) { + throw new Error(`Cannot compute FPS because ${fps} is lower than our minimum value ${VIDEO_TRANSCODING_FPS.MIN}`) + } + + return fps +} + +// --------------------------------------------------------------------------- +// Private +// --------------------------------------------------------------------------- + +function getClosestFramerateStandard (options: { + fps: number + type: 'HD_STANDARD' | 'STANDARD' +}) { + const { fps, type } = options + + return VIDEO_TRANSCODING_FPS[type].slice(0) + .sort((a, b) => fps % a - fps % b)[0] +} -- cgit v1.2.3