aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/transcoding/transcoding-resolutions.ts
blob: 91f4d18d89e549eea0ed99c72950e9a48fbfd0c3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { CONFIG } from '@server/initializers/config'
import { toEven } from '@shared/core-utils'
import { VideoResolution } from '@shared/models'

export function computeResolutionsToTranscode (options: {
  input: number
  type: 'vod' | 'live'
  includeInput: boolean
  strictLower: boolean
  hasAudio: boolean
}) {
  const { input, type, includeInput, strictLower, hasAudio } = options

  const configResolutions = type === 'vod'
    ? CONFIG.TRANSCODING.RESOLUTIONS
    : CONFIG.LIVE.TRANSCODING.RESOLUTIONS

  const resolutionsEnabled = new Set<number>()

  // Put in the order we want to proceed jobs
  const availableResolutions: VideoResolution[] = [
    VideoResolution.H_NOVIDEO,
    VideoResolution.H_480P,
    VideoResolution.H_360P,
    VideoResolution.H_720P,
    VideoResolution.H_240P,
    VideoResolution.H_144P,
    VideoResolution.H_1080P,
    VideoResolution.H_1440P,
    VideoResolution.H_4K
  ]

  for (const resolution of availableResolutions) {
    // Resolution not enabled
    if (configResolutions[resolution + 'p'] !== true) continue
    // Too big resolution for input file
    if (input < resolution) continue
    // We only want lower resolutions than input file
    if (strictLower && input === resolution) continue
    // Audio resolutio but no audio in the video
    if (resolution === VideoResolution.H_NOVIDEO && !hasAudio) continue

    resolutionsEnabled.add(resolution)
  }

  if (includeInput) {
    // Always use an even resolution to avoid issues with ffmpeg
    resolutionsEnabled.add(toEven(input))
  }

  return Array.from(resolutionsEnabled)
}