mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-04 10:19:35 +02:00
Support transcoding options/encoders by plugins
This commit is contained in:
parent
529b37527c
commit
1896bca09e
32 changed files with 754 additions and 135 deletions
|
@ -1,6 +1,6 @@
|
|||
import { logger } from '@server/helpers/logger'
|
||||
import { getTargetBitrate, VideoResolution } from '../../shared/models/videos'
|
||||
import { AvailableEncoders, buildStreamSuffix, EncoderOptionsBuilder } from '../helpers/ffmpeg-utils'
|
||||
import { AvailableEncoders, EncoderOptionsBuilder, getTargetBitrate, VideoResolution } from '../../shared/models/videos'
|
||||
import { buildStreamSuffix, resetSupportedEncoders } from '../helpers/ffmpeg-utils'
|
||||
import {
|
||||
canDoQuickAudioTranscode,
|
||||
ffprobePromise,
|
||||
|
@ -84,16 +84,8 @@ class VideoTranscodingProfilesManager {
|
|||
|
||||
// 1 === less priority
|
||||
private readonly encodersPriorities = {
|
||||
video: [
|
||||
{ name: 'libx264', priority: 100 }
|
||||
],
|
||||
|
||||
// Try the first one, if not available try the second one etc
|
||||
audio: [
|
||||
// we favor VBR, if a good AAC encoder is available
|
||||
{ name: 'libfdk_aac', priority: 200 },
|
||||
{ name: 'aac', priority: 100 }
|
||||
]
|
||||
vod: this.buildDefaultEncodersPriorities(),
|
||||
live: this.buildDefaultEncodersPriorities()
|
||||
}
|
||||
|
||||
private readonly availableEncoders = {
|
||||
|
@ -118,25 +110,77 @@ class VideoTranscodingProfilesManager {
|
|||
}
|
||||
}
|
||||
|
||||
private constructor () {
|
||||
private availableProfiles = {
|
||||
vod: [] as string[],
|
||||
live: [] as string[]
|
||||
}
|
||||
|
||||
private constructor () {
|
||||
this.buildAvailableProfiles()
|
||||
}
|
||||
|
||||
getAvailableEncoders (): AvailableEncoders {
|
||||
const encodersToTry = {
|
||||
video: this.getEncodersByPriority('video'),
|
||||
audio: this.getEncodersByPriority('audio')
|
||||
return {
|
||||
available: this.availableEncoders,
|
||||
encodersToTry: {
|
||||
vod: {
|
||||
video: this.getEncodersByPriority('vod', 'video'),
|
||||
audio: this.getEncodersByPriority('vod', 'audio')
|
||||
},
|
||||
live: {
|
||||
video: this.getEncodersByPriority('live', 'video'),
|
||||
audio: this.getEncodersByPriority('live', 'audio')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Object.assign({}, this.availableEncoders, { encodersToTry })
|
||||
}
|
||||
|
||||
getAvailableProfiles (type: 'vod' | 'live') {
|
||||
return this.availableEncoders[type]
|
||||
return this.availableProfiles[type]
|
||||
}
|
||||
|
||||
private getEncodersByPriority (type: 'video' | 'audio') {
|
||||
return this.encodersPriorities[type]
|
||||
addProfile (options: {
|
||||
type: 'vod' | 'live'
|
||||
encoder: string
|
||||
profile: string
|
||||
builder: EncoderOptionsBuilder
|
||||
}) {
|
||||
const { type, encoder, profile, builder } = options
|
||||
|
||||
const encoders = this.availableEncoders[type]
|
||||
|
||||
if (!encoders[encoder]) encoders[encoder] = {}
|
||||
encoders[encoder][profile] = builder
|
||||
|
||||
this.buildAvailableProfiles()
|
||||
}
|
||||
|
||||
removeProfile (options: {
|
||||
type: 'vod' | 'live'
|
||||
encoder: string
|
||||
profile: string
|
||||
}) {
|
||||
const { type, encoder, profile } = options
|
||||
|
||||
delete this.availableEncoders[type][encoder][profile]
|
||||
this.buildAvailableProfiles()
|
||||
}
|
||||
|
||||
addEncoderPriority (type: 'vod' | 'live', streamType: 'audio' | 'video', encoder: string, priority: number) {
|
||||
this.encodersPriorities[type][streamType].push({ name: encoder, priority })
|
||||
|
||||
resetSupportedEncoders()
|
||||
}
|
||||
|
||||
removeEncoderPriority (type: 'vod' | 'live', streamType: 'audio' | 'video', encoder: string, priority: number) {
|
||||
this.encodersPriorities[type][streamType] = this.encodersPriorities[type][streamType]
|
||||
.filter(o => o.name !== encoder && o.priority !== priority)
|
||||
|
||||
resetSupportedEncoders()
|
||||
}
|
||||
|
||||
private getEncodersByPriority (type: 'vod' | 'live', streamType: 'audio' | 'video') {
|
||||
return this.encodersPriorities[type][streamType]
|
||||
.sort((e1, e2) => {
|
||||
if (e1.priority > e2.priority) return -1
|
||||
else if (e1.priority === e2.priority) return 0
|
||||
|
@ -146,6 +190,39 @@ class VideoTranscodingProfilesManager {
|
|||
.map(e => e.name)
|
||||
}
|
||||
|
||||
private buildAvailableProfiles () {
|
||||
for (const type of [ 'vod', 'live' ]) {
|
||||
const result = new Set()
|
||||
|
||||
const encoders = this.availableEncoders[type]
|
||||
|
||||
for (const encoderName of Object.keys(encoders)) {
|
||||
for (const profile of Object.keys(encoders[encoderName])) {
|
||||
result.add(profile)
|
||||
}
|
||||
}
|
||||
|
||||
this.availableProfiles[type] = Array.from(result)
|
||||
}
|
||||
|
||||
logger.debug('Available transcoding profiles built.', { availableProfiles: this.availableProfiles })
|
||||
}
|
||||
|
||||
private buildDefaultEncodersPriorities () {
|
||||
return {
|
||||
video: [
|
||||
{ name: 'libx264', priority: 100 }
|
||||
],
|
||||
|
||||
// Try the first one, if not available try the second one etc
|
||||
audio: [
|
||||
// we favor VBR, if a good AAC encoder is available
|
||||
{ name: 'libfdk_aac', priority: 200 },
|
||||
{ name: 'aac', priority: 100 }
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
static get Instance () {
|
||||
return this.instance || (this.instance = new this())
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue