]>
Commit | Line | Data |
---|---|---|
1 | import { CONFIG } from '@server/initializers/config' | |
2 | import { toEven } from '@shared/core-utils' | |
3 | import { VideoResolution } from '@shared/models' | |
4 | ||
5 | export function buildOriginalFileResolution (inputResolution: number) { | |
6 | if (CONFIG.TRANSCODING.ALWAYS_TRANSCODE_ORIGINAL_RESOLUTION === true) { | |
7 | return toEven(inputResolution) | |
8 | } | |
9 | ||
10 | const resolutions = computeResolutionsToTranscode({ | |
11 | input: inputResolution, | |
12 | type: 'vod', | |
13 | includeInput: false, | |
14 | strictLower: false, | |
15 | // We don't really care about the audio resolution in this context | |
16 | hasAudio: true | |
17 | }) | |
18 | ||
19 | if (resolutions.length === 0) { | |
20 | return toEven(inputResolution) | |
21 | } | |
22 | ||
23 | return Math.max(...resolutions) | |
24 | } | |
25 | ||
26 | export function computeResolutionsToTranscode (options: { | |
27 | input: number | |
28 | type: 'vod' | 'live' | |
29 | includeInput: boolean | |
30 | strictLower: boolean | |
31 | hasAudio: boolean | |
32 | }) { | |
33 | const { input, type, includeInput, strictLower, hasAudio } = options | |
34 | ||
35 | const configResolutions = type === 'vod' | |
36 | ? CONFIG.TRANSCODING.RESOLUTIONS | |
37 | : CONFIG.LIVE.TRANSCODING.RESOLUTIONS | |
38 | ||
39 | const resolutionsEnabled = new Set<number>() | |
40 | ||
41 | // Put in the order we want to proceed jobs | |
42 | const availableResolutions: VideoResolution[] = [ | |
43 | VideoResolution.H_NOVIDEO, | |
44 | VideoResolution.H_480P, | |
45 | VideoResolution.H_360P, | |
46 | VideoResolution.H_720P, | |
47 | VideoResolution.H_240P, | |
48 | VideoResolution.H_144P, | |
49 | VideoResolution.H_1080P, | |
50 | VideoResolution.H_1440P, | |
51 | VideoResolution.H_4K | |
52 | ] | |
53 | ||
54 | for (const resolution of availableResolutions) { | |
55 | // Resolution not enabled | |
56 | if (configResolutions[resolution + 'p'] !== true) continue | |
57 | // Too big resolution for input file | |
58 | if (input < resolution) continue | |
59 | // We only want lower resolutions than input file | |
60 | if (strictLower && input === resolution) continue | |
61 | // Audio resolutio but no audio in the video | |
62 | if (resolution === VideoResolution.H_NOVIDEO && !hasAudio) continue | |
63 | ||
64 | resolutionsEnabled.add(resolution) | |
65 | } | |
66 | ||
67 | if (includeInput) { | |
68 | // Always use an even resolution to avoid issues with ffmpeg | |
69 | resolutionsEnabled.add(toEven(input)) | |
70 | } | |
71 | ||
72 | return Array.from(resolutionsEnabled) | |
73 | } |