1 import { VIDEO_TRANSCODING_FPS } from '@server/initializers/constants'
2 import { VideoResolution } from '@shared/models'
4 export function computeOutputFPS (options: {
6 resolution: VideoResolution
8 const { resolution } = options
10 let fps = options.inputFPS
13 // On small/medium resolutions, limit FPS
14 resolution !== undefined &&
15 resolution < VIDEO_TRANSCODING_FPS.KEEP_ORIGIN_FPS_RESOLUTION_MIN &&
16 fps > VIDEO_TRANSCODING_FPS.AVERAGE
18 // Get closest standard framerate by modulo: downsampling has to be done to a divisor of the nominal fps value
19 fps = getClosestFramerateStandard({ fps, type: 'STANDARD' })
23 if (fps > VIDEO_TRANSCODING_FPS.MAX) fps = getClosestFramerateStandard({ fps, type: 'HD_STANDARD' })
25 if (fps < VIDEO_TRANSCODING_FPS.MIN) {
26 throw new Error(`Cannot compute FPS because ${fps} is lower than our minimum value ${VIDEO_TRANSCODING_FPS.MIN}`)
32 // ---------------------------------------------------------------------------
34 // ---------------------------------------------------------------------------
36 function getClosestFramerateStandard (options: {
38 type: 'HD_STANDARD' | 'STANDARD'
40 const { fps, type } = options
42 return VIDEO_TRANSCODING_FPS[type].slice(0)
43 .sort((a, b) => fps % a - fps % b)[0]