diff options
Diffstat (limited to 'server/lib/video-transcoding-profiles.ts')
-rw-r--r-- | server/lib/video-transcoding-profiles.ts | 85 |
1 files changed, 68 insertions, 17 deletions
diff --git a/server/lib/video-transcoding-profiles.ts b/server/lib/video-transcoding-profiles.ts index 338f4de4a..bbe556e75 100644 --- a/server/lib/video-transcoding-profiles.ts +++ b/server/lib/video-transcoding-profiles.ts | |||
@@ -78,32 +78,83 @@ const defaultLibFDKAACVODOptionsBuilder: EncoderOptionsBuilder = ({ streamNum }) | |||
78 | return { outputOptions: [ buildStreamSuffix('-q:a', streamNum), '5' ] } | 78 | return { outputOptions: [ buildStreamSuffix('-q:a', streamNum), '5' ] } |
79 | } | 79 | } |
80 | 80 | ||
81 | const availableEncoders: AvailableEncoders = { | 81 | // Used to get and update available encoders |
82 | vod: { | 82 | class VideoTranscodingProfilesManager { |
83 | libx264: { | 83 | private static instance: VideoTranscodingProfilesManager |
84 | default: defaultX264VODOptionsBuilder | 84 | |
85 | }, | 85 | // 1 === less priority |
86 | aac: { | 86 | private readonly encodersPriorities = { |
87 | default: defaultAACOptionsBuilder | 87 | video: [ |
88 | { name: 'libx264', priority: 100 } | ||
89 | ], | ||
90 | |||
91 | // Try the first one, if not available try the second one etc | ||
92 | audio: [ | ||
93 | // we favor VBR, if a good AAC encoder is available | ||
94 | { name: 'libfdk_aac', priority: 200 }, | ||
95 | { name: 'aac', priority: 100 } | ||
96 | ] | ||
97 | } | ||
98 | |||
99 | private readonly availableEncoders = { | ||
100 | vod: { | ||
101 | libx264: { | ||
102 | default: defaultX264VODOptionsBuilder | ||
103 | }, | ||
104 | aac: { | ||
105 | default: defaultAACOptionsBuilder | ||
106 | }, | ||
107 | libfdk_aac: { | ||
108 | default: defaultLibFDKAACVODOptionsBuilder | ||
109 | } | ||
88 | }, | 110 | }, |
89 | libfdk_aac: { | 111 | live: { |
90 | default: defaultLibFDKAACVODOptionsBuilder | 112 | libx264: { |
113 | default: defaultX264LiveOptionsBuilder | ||
114 | }, | ||
115 | aac: { | ||
116 | default: defaultAACOptionsBuilder | ||
117 | } | ||
91 | } | 118 | } |
92 | }, | 119 | } |
93 | live: { | 120 | |
94 | libx264: { | 121 | private constructor () { |
95 | default: defaultX264LiveOptionsBuilder | 122 | |
96 | }, | 123 | } |
97 | aac: { | 124 | |
98 | default: defaultAACOptionsBuilder | 125 | getAvailableEncoders (): AvailableEncoders { |
126 | const encodersToTry = { | ||
127 | video: this.getEncodersByPriority('video'), | ||
128 | audio: this.getEncodersByPriority('audio') | ||
99 | } | 129 | } |
130 | |||
131 | return Object.assign({}, this.availableEncoders, { encodersToTry }) | ||
132 | } | ||
133 | |||
134 | getAvailableProfiles (type: 'vod' | 'live') { | ||
135 | return this.availableEncoders[type] | ||
136 | } | ||
137 | |||
138 | private getEncodersByPriority (type: 'video' | 'audio') { | ||
139 | return this.encodersPriorities[type] | ||
140 | .sort((e1, e2) => { | ||
141 | if (e1.priority > e2.priority) return -1 | ||
142 | else if (e1.priority === e2.priority) return 0 | ||
143 | |||
144 | return 1 | ||
145 | }) | ||
146 | .map(e => e.name) | ||
147 | } | ||
148 | |||
149 | static get Instance () { | ||
150 | return this.instance || (this.instance = new this()) | ||
100 | } | 151 | } |
101 | } | 152 | } |
102 | 153 | ||
103 | // --------------------------------------------------------------------------- | 154 | // --------------------------------------------------------------------------- |
104 | 155 | ||
105 | export { | 156 | export { |
106 | availableEncoders | 157 | VideoTranscodingProfilesManager |
107 | } | 158 | } |
108 | 159 | ||
109 | // --------------------------------------------------------------------------- | 160 | // --------------------------------------------------------------------------- |