mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-04 18:29:27 +02:00
server/server -> server/core
This commit is contained in:
parent
114327d4ce
commit
5a3d0650c9
838 changed files with 111 additions and 111 deletions
73
server/core/lib/transcoding/transcoding-resolutions.ts
Normal file
73
server/core/lib/transcoding/transcoding-resolutions.ts
Normal file
|
@ -0,0 +1,73 @@
|
|||
import { toEven } from '@peertube/peertube-core-utils'
|
||||
import { VideoResolution, VideoResolutionType } from '@peertube/peertube-models'
|
||||
import { CONFIG } from '@server/initializers/config.js'
|
||||
|
||||
export function buildOriginalFileResolution (inputResolution: number) {
|
||||
if (CONFIG.TRANSCODING.ALWAYS_TRANSCODE_ORIGINAL_RESOLUTION === true) {
|
||||
return toEven(inputResolution)
|
||||
}
|
||||
|
||||
const resolutions = computeResolutionsToTranscode({
|
||||
input: inputResolution,
|
||||
type: 'vod',
|
||||
includeInput: false,
|
||||
strictLower: false,
|
||||
// We don't really care about the audio resolution in this context
|
||||
hasAudio: true
|
||||
})
|
||||
|
||||
if (resolutions.length === 0) {
|
||||
return toEven(inputResolution)
|
||||
}
|
||||
|
||||
return Math.max(...resolutions)
|
||||
}
|
||||
|
||||
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: VideoResolutionType[] = [
|
||||
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)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue