1 import { CONFIG } from '@server/initializers/config'
2 import { toEven } from '@shared/core-utils'
3 import { VideoResolution } from '@shared/models'
5 export function buildOriginalFileResolution (inputResolution: number) {
6 if (CONFIG.TRANSCODING.ALWAYS_TRANSCODE_ORIGINAL_RESOLUTION === true) {
7 return toEven(inputResolution)
10 const resolutions = computeResolutionsToTranscode({
11 input: inputResolution,
15 // We don't really care about the audio resolution in this context
19 if (resolutions.length === 0) {
20 return toEven(inputResolution)
23 return Math.max(...resolutions)
26 export function computeResolutionsToTranscode (options: {
33 const { input, type, includeInput, strictLower, hasAudio } = options
35 const configResolutions = type === 'vod'
36 ? CONFIG.TRANSCODING.RESOLUTIONS
37 : CONFIG.LIVE.TRANSCODING.RESOLUTIONS
39 const resolutionsEnabled = new Set<number>()
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,
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
64 resolutionsEnabled.add(resolution)
68 // Always use an even resolution to avoid issues with ffmpeg
69 resolutionsEnabled.add(toEven(input))
72 return Array.from(resolutionsEnabled)