diff options
author | Chocobozzz <me@florianbigard.com> | 2023-04-21 14:55:10 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2023-05-09 08:57:34 +0200 |
commit | 0c9668f77901e7540e2c7045eb0f2974a4842a69 (patch) | |
tree | 226d3dd1565b0bb56588897af3b8530e6216e96b /server/helpers/ffmpeg/framerate.ts | |
parent | 6bcb854cdea8688a32240bc5719c7d139806e00b (diff) | |
download | PeerTube-0c9668f77901e7540e2c7045eb0f2974a4842a69.tar.gz PeerTube-0c9668f77901e7540e2c7045eb0f2974a4842a69.tar.zst PeerTube-0c9668f77901e7540e2c7045eb0f2974a4842a69.zip |
Implement remote runner jobs in server
Move ffmpeg functions to @shared
Diffstat (limited to 'server/helpers/ffmpeg/framerate.ts')
-rw-r--r-- | server/helpers/ffmpeg/framerate.ts | 44 |
1 files changed, 44 insertions, 0 deletions
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 @@ | |||
1 | import { VIDEO_TRANSCODING_FPS } from '@server/initializers/constants' | ||
2 | import { VideoResolution } from '@shared/models' | ||
3 | |||
4 | export function computeOutputFPS (options: { | ||
5 | inputFPS: number | ||
6 | resolution: VideoResolution | ||
7 | }) { | ||
8 | const { resolution } = options | ||
9 | |||
10 | let fps = options.inputFPS | ||
11 | |||
12 | if ( | ||
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 | ||
17 | ) { | ||
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' }) | ||
20 | } | ||
21 | |||
22 | // Hard FPS limits | ||
23 | if (fps > VIDEO_TRANSCODING_FPS.MAX) fps = getClosestFramerateStandard({ fps, type: 'HD_STANDARD' }) | ||
24 | |||
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}`) | ||
27 | } | ||
28 | |||
29 | return fps | ||
30 | } | ||
31 | |||
32 | // --------------------------------------------------------------------------- | ||
33 | // Private | ||
34 | // --------------------------------------------------------------------------- | ||
35 | |||
36 | function getClosestFramerateStandard (options: { | ||
37 | fps: number | ||
38 | type: 'HD_STANDARD' | 'STANDARD' | ||
39 | }) { | ||
40 | const { fps, type } = options | ||
41 | |||
42 | return VIDEO_TRANSCODING_FPS[type].slice(0) | ||
43 | .sort((a, b) => fps % a - fps % b)[0] | ||
44 | } | ||