diff options
Diffstat (limited to 'server/helpers')
-rw-r--r-- | server/helpers/ffmpeg/ffprobe-utils.ts | 22 | ||||
-rw-r--r-- | server/helpers/youtube-dl/youtube-dl-cli.ts | 30 | ||||
-rw-r--r-- | server/helpers/youtube-dl/youtube-dl-wrapper.ts | 10 |
3 files changed, 40 insertions, 22 deletions
diff --git a/server/helpers/ffmpeg/ffprobe-utils.ts b/server/helpers/ffmpeg/ffprobe-utils.ts index 7bcd27665..c45f9ec99 100644 --- a/server/helpers/ffmpeg/ffprobe-utils.ts +++ b/server/helpers/ffmpeg/ffprobe-utils.ts | |||
@@ -91,11 +91,12 @@ async function getAudioStreamCodec (path: string, existingProbe?: FfprobeData) { | |||
91 | // --------------------------------------------------------------------------- | 91 | // --------------------------------------------------------------------------- |
92 | 92 | ||
93 | function computeResolutionsToTranscode (options: { | 93 | function computeResolutionsToTranscode (options: { |
94 | inputResolution: number | 94 | input: number |
95 | type: 'vod' | 'live' | 95 | type: 'vod' | 'live' |
96 | includeInputResolution: boolean | 96 | includeInput: boolean |
97 | strictLower: boolean | ||
97 | }) { | 98 | }) { |
98 | const { inputResolution, type, includeInputResolution } = options | 99 | const { input, type, includeInput, strictLower } = options |
99 | 100 | ||
100 | const configResolutions = type === 'vod' | 101 | const configResolutions = type === 'vod' |
101 | ? CONFIG.TRANSCODING.RESOLUTIONS | 102 | ? CONFIG.TRANSCODING.RESOLUTIONS |
@@ -117,13 +118,18 @@ function computeResolutionsToTranscode (options: { | |||
117 | ] | 118 | ] |
118 | 119 | ||
119 | for (const resolution of availableResolutions) { | 120 | for (const resolution of availableResolutions) { |
120 | if (configResolutions[resolution + 'p'] === true && inputResolution > resolution) { | 121 | // Resolution not enabled |
121 | resolutionsEnabled.add(resolution) | 122 | if (configResolutions[resolution + 'p'] !== true) continue |
122 | } | 123 | // Too big resolution for input file |
124 | if (input < resolution) continue | ||
125 | // We only want lower resolutions than input file | ||
126 | if (strictLower && input === resolution) continue | ||
127 | |||
128 | resolutionsEnabled.add(resolution) | ||
123 | } | 129 | } |
124 | 130 | ||
125 | if (includeInputResolution) { | 131 | if (includeInput) { |
126 | resolutionsEnabled.add(inputResolution) | 132 | resolutionsEnabled.add(input) |
127 | } | 133 | } |
128 | 134 | ||
129 | return Array.from(resolutionsEnabled) | 135 | return Array.from(resolutionsEnabled) |
diff --git a/server/helpers/youtube-dl/youtube-dl-cli.ts b/server/helpers/youtube-dl/youtube-dl-cli.ts index 728f096b5..13c990a1e 100644 --- a/server/helpers/youtube-dl/youtube-dl-cli.ts +++ b/server/helpers/youtube-dl/youtube-dl-cli.ts | |||
@@ -57,7 +57,7 @@ export class YoutubeDLCLI { | |||
57 | } | 57 | } |
58 | } | 58 | } |
59 | 59 | ||
60 | static getYoutubeDLVideoFormat (enabledResolutions: VideoResolution[]) { | 60 | static getYoutubeDLVideoFormat (enabledResolutions: VideoResolution[], useBestFormat: boolean) { |
61 | /** | 61 | /** |
62 | * list of format selectors in order or preference | 62 | * list of format selectors in order or preference |
63 | * see https://github.com/ytdl-org/youtube-dl#format-selection | 63 | * see https://github.com/ytdl-org/youtube-dl#format-selection |
@@ -69,18 +69,26 @@ export class YoutubeDLCLI { | |||
69 | * | 69 | * |
70 | * in any case we avoid AV1, see https://github.com/Chocobozzz/PeerTube/issues/3499 | 70 | * in any case we avoid AV1, see https://github.com/Chocobozzz/PeerTube/issues/3499 |
71 | **/ | 71 | **/ |
72 | const resolution = enabledResolutions.length === 0 | 72 | |
73 | ? VideoResolution.H_720P | 73 | let result: string[] = [] |
74 | : Math.max(...enabledResolutions) | 74 | |
75 | 75 | if (!useBestFormat) { | |
76 | return [ | 76 | const resolution = enabledResolutions.length === 0 |
77 | `bestvideo[vcodec^=avc1][height=${resolution}]+bestaudio[ext=m4a]`, // case #1 | 77 | ? VideoResolution.H_720P |
78 | `bestvideo[vcodec!*=av01][vcodec!*=vp9.2][height=${resolution}]+bestaudio`, // case #2 | 78 | : Math.max(...enabledResolutions) |
79 | `bestvideo[vcodec^=avc1][height<=${resolution}]+bestaudio[ext=m4a]`, // case #3 | 79 | |
80 | `bestvideo[vcodec!*=av01][vcodec!*=vp9.2]+bestaudio`, | 80 | result = [ |
81 | `bestvideo[vcodec^=avc1][height=${resolution}]+bestaudio[ext=m4a]`, // case #1 | ||
82 | `bestvideo[vcodec!*=av01][vcodec!*=vp9.2][height=${resolution}]+bestaudio`, // case #2 | ||
83 | `bestvideo[vcodec^=avc1][height<=${resolution}]+bestaudio[ext=m4a]` // case # | ||
84 | ] | ||
85 | } | ||
86 | |||
87 | return result.concat([ | ||
88 | 'bestvideo[vcodec!*=av01][vcodec!*=vp9.2]+bestaudio', | ||
81 | 'best[vcodec!*=av01][vcodec!*=vp9.2]', // case fallback for known formats | 89 | 'best[vcodec!*=av01][vcodec!*=vp9.2]', // case fallback for known formats |
82 | 'best' // Ultimate fallback | 90 | 'best' // Ultimate fallback |
83 | ].join('/') | 91 | ]).join('/') |
84 | } | 92 | } |
85 | 93 | ||
86 | private constructor () { | 94 | private constructor () { |
diff --git a/server/helpers/youtube-dl/youtube-dl-wrapper.ts b/server/helpers/youtube-dl/youtube-dl-wrapper.ts index d585e9a95..176cf3b69 100644 --- a/server/helpers/youtube-dl/youtube-dl-wrapper.ts +++ b/server/helpers/youtube-dl/youtube-dl-wrapper.ts | |||
@@ -21,7 +21,11 @@ const processOptions = { | |||
21 | 21 | ||
22 | class YoutubeDLWrapper { | 22 | class YoutubeDLWrapper { |
23 | 23 | ||
24 | constructor (private readonly url: string = '', private readonly enabledResolutions: number[] = []) { | 24 | constructor ( |
25 | private readonly url: string, | ||
26 | private readonly enabledResolutions: number[], | ||
27 | private readonly useBestFormat: boolean | ||
28 | ) { | ||
25 | 29 | ||
26 | } | 30 | } |
27 | 31 | ||
@@ -30,7 +34,7 @@ class YoutubeDLWrapper { | |||
30 | 34 | ||
31 | const info = await youtubeDL.getInfo({ | 35 | const info = await youtubeDL.getInfo({ |
32 | url: this.url, | 36 | url: this.url, |
33 | format: YoutubeDLCLI.getYoutubeDLVideoFormat(this.enabledResolutions), | 37 | format: YoutubeDLCLI.getYoutubeDLVideoFormat(this.enabledResolutions, this.useBestFormat), |
34 | additionalYoutubeDLArgs: youtubeDLArgs, | 38 | additionalYoutubeDLArgs: youtubeDLArgs, |
35 | processOptions | 39 | processOptions |
36 | }) | 40 | }) |
@@ -80,7 +84,7 @@ class YoutubeDLWrapper { | |||
80 | try { | 84 | try { |
81 | await youtubeDL.download({ | 85 | await youtubeDL.download({ |
82 | url: this.url, | 86 | url: this.url, |
83 | format: YoutubeDLCLI.getYoutubeDLVideoFormat(this.enabledResolutions), | 87 | format: YoutubeDLCLI.getYoutubeDLVideoFormat(this.enabledResolutions, this.useBestFormat), |
84 | output: pathWithoutExtension, | 88 | output: pathWithoutExtension, |
85 | timeout, | 89 | timeout, |
86 | processOptions | 90 | processOptions |