diff options
Diffstat (limited to 'server/lib/transcoding/transcoding-resolutions.ts')
-rw-r--r-- | server/lib/transcoding/transcoding-resolutions.ts | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/server/lib/transcoding/transcoding-resolutions.ts b/server/lib/transcoding/transcoding-resolutions.ts new file mode 100644 index 000000000..91f4d18d8 --- /dev/null +++ b/server/lib/transcoding/transcoding-resolutions.ts | |||
@@ -0,0 +1,52 @@ | |||
1 | import { CONFIG } from '@server/initializers/config' | ||
2 | import { toEven } from '@shared/core-utils' | ||
3 | import { VideoResolution } from '@shared/models' | ||
4 | |||
5 | export function computeResolutionsToTranscode (options: { | ||
6 | input: number | ||
7 | type: 'vod' | 'live' | ||
8 | includeInput: boolean | ||
9 | strictLower: boolean | ||
10 | hasAudio: boolean | ||
11 | }) { | ||
12 | const { input, type, includeInput, strictLower, hasAudio } = options | ||
13 | |||
14 | const configResolutions = type === 'vod' | ||
15 | ? CONFIG.TRANSCODING.RESOLUTIONS | ||
16 | : CONFIG.LIVE.TRANSCODING.RESOLUTIONS | ||
17 | |||
18 | const resolutionsEnabled = new Set<number>() | ||
19 | |||
20 | // Put in the order we want to proceed jobs | ||
21 | const availableResolutions: VideoResolution[] = [ | ||
22 | VideoResolution.H_NOVIDEO, | ||
23 | VideoResolution.H_480P, | ||
24 | VideoResolution.H_360P, | ||
25 | VideoResolution.H_720P, | ||
26 | VideoResolution.H_240P, | ||
27 | VideoResolution.H_144P, | ||
28 | VideoResolution.H_1080P, | ||
29 | VideoResolution.H_1440P, | ||
30 | VideoResolution.H_4K | ||
31 | ] | ||
32 | |||
33 | for (const resolution of availableResolutions) { | ||
34 | // Resolution not enabled | ||
35 | if (configResolutions[resolution + 'p'] !== true) continue | ||
36 | // Too big resolution for input file | ||
37 | if (input < resolution) continue | ||
38 | // We only want lower resolutions than input file | ||
39 | if (strictLower && input === resolution) continue | ||
40 | // Audio resolutio but no audio in the video | ||
41 | if (resolution === VideoResolution.H_NOVIDEO && !hasAudio) continue | ||
42 | |||
43 | resolutionsEnabled.add(resolution) | ||
44 | } | ||
45 | |||
46 | if (includeInput) { | ||
47 | // Always use an even resolution to avoid issues with ffmpeg | ||
48 | resolutionsEnabled.add(toEven(input)) | ||
49 | } | ||
50 | |||
51 | return Array.from(resolutionsEnabled) | ||
52 | } | ||