diff options
author | Chocobozzz <me@florianbigard.com> | 2023-07-31 14:34:36 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2023-08-11 15:02:33 +0200 |
commit | 3a4992633ee62d5edfbb484d9c6bcb3cf158489d (patch) | |
tree | e4510b39bdac9c318fdb4b47018d08f15368b8f0 /server/lib/transcoding/transcoding-resolutions.ts | |
parent | 04d1da5621d25d59bd5fa1543b725c497bf5d9a8 (diff) | |
download | PeerTube-3a4992633ee62d5edfbb484d9c6bcb3cf158489d.tar.gz PeerTube-3a4992633ee62d5edfbb484d9c6bcb3cf158489d.tar.zst PeerTube-3a4992633ee62d5edfbb484d9c6bcb3cf158489d.zip |
Migrate server to ESM
Sorry for the very big commit that may lead to git log issues and merge
conflicts, but it's a major step forward:
* Server can be faster at startup because imports() are async and we can
easily lazy import big modules
* Angular doesn't seem to support ES import (with .js extension), so we
had to correctly organize peertube into a monorepo:
* Use yarn workspace feature
* Use typescript reference projects for dependencies
* Shared projects have been moved into "packages", each one is now a
node module (with a dedicated package.json/tsconfig.json)
* server/tools have been moved into apps/ and is now a dedicated app
bundled and published on NPM so users don't have to build peertube
cli tools manually
* server/tests have been moved into packages/ so we don't compile
them every time we want to run the server
* Use isolatedModule option:
* Had to move from const enum to const
(https://www.typescriptlang.org/docs/handbook/enums.html#objects-vs-enums)
* Had to explictely specify "type" imports when used in decorators
* Prefer tsx (that uses esbuild under the hood) instead of ts-node to
load typescript files (tests with mocha or scripts):
* To reduce test complexity as esbuild doesn't support decorator
metadata, we only test server files that do not import server
models
* We still build tests files into js files for a faster CI
* Remove unmaintained peertube CLI import script
* Removed some barrels to speed up execution (less imports)
Diffstat (limited to 'server/lib/transcoding/transcoding-resolutions.ts')
-rw-r--r-- | server/lib/transcoding/transcoding-resolutions.ts | 73 |
1 files changed, 0 insertions, 73 deletions
diff --git a/server/lib/transcoding/transcoding-resolutions.ts b/server/lib/transcoding/transcoding-resolutions.ts deleted file mode 100644 index 9a6bf5722..000000000 --- a/server/lib/transcoding/transcoding-resolutions.ts +++ /dev/null | |||
@@ -1,73 +0,0 @@ | |||
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 | } | ||