aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib')
-rw-r--r--server/lib/live-manager.ts4
-rw-r--r--server/lib/video-transcoding-profiles.ts85
-rw-r--r--server/lib/video-transcoding.ts12
3 files changed, 76 insertions, 25 deletions
diff --git a/server/lib/live-manager.ts b/server/lib/live-manager.ts
index d968f05da..c8e5bcb77 100644
--- a/server/lib/live-manager.ts
+++ b/server/lib/live-manager.ts
@@ -25,7 +25,7 @@ import { cleanupLive } from './job-queue/handlers/video-live-ending'
25import { PeerTubeSocket } from './peertube-socket' 25import { PeerTubeSocket } from './peertube-socket'
26import { isAbleToUploadVideo } from './user' 26import { isAbleToUploadVideo } from './user'
27import { getHLSDirectory } from './video-paths' 27import { getHLSDirectory } from './video-paths'
28import { availableEncoders } from './video-transcoding-profiles' 28import { VideoTranscodingProfilesManager } from './video-transcoding-profiles'
29 29
30import memoizee = require('memoizee') 30import memoizee = require('memoizee')
31const NodeRtmpSession = require('node-media-server/node_rtmp_session') 31const NodeRtmpSession = require('node-media-server/node_rtmp_session')
@@ -337,7 +337,7 @@ class LiveManager {
337 outPath, 337 outPath,
338 resolutions: allResolutions, 338 resolutions: allResolutions,
339 fps, 339 fps,
340 availableEncoders, 340 availableEncoders: VideoTranscodingProfilesManager.Instance.getAvailableEncoders(),
341 profile: 'default' 341 profile: 'default'
342 }) 342 })
343 : getLiveMuxingCommand(rtmpUrl, outPath) 343 : getLiveMuxingCommand(rtmpUrl, outPath)
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
81const availableEncoders: AvailableEncoders = { 81// Used to get and update available encoders
82 vod: { 82class 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
105export { 156export {
106 availableEncoders 157 VideoTranscodingProfilesManager
107} 158}
108 159
109// --------------------------------------------------------------------------- 160// ---------------------------------------------------------------------------
diff --git a/server/lib/video-transcoding.ts b/server/lib/video-transcoding.ts
index 7af7a481c..c4b3425d1 100644
--- a/server/lib/video-transcoding.ts
+++ b/server/lib/video-transcoding.ts
@@ -14,7 +14,7 @@ import { VideoFileModel } from '../models/video/video-file'
14import { VideoStreamingPlaylistModel } from '../models/video/video-streaming-playlist' 14import { VideoStreamingPlaylistModel } from '../models/video/video-streaming-playlist'
15import { updateMasterHLSPlaylist, updateSha256VODSegments } from './hls' 15import { updateMasterHLSPlaylist, updateSha256VODSegments } from './hls'
16import { generateVideoStreamingPlaylistName, getVideoFilename, getVideoFilePath } from './video-paths' 16import { generateVideoStreamingPlaylistName, getVideoFilename, getVideoFilePath } from './video-paths'
17import { availableEncoders } from './video-transcoding-profiles' 17import { VideoTranscodingProfilesManager } from './video-transcoding-profiles'
18 18
19/** 19/**
20 * 20 *
@@ -41,7 +41,7 @@ async function optimizeOriginalVideofile (video: MVideoWithFile, inputVideoFile:
41 inputPath: videoInputPath, 41 inputPath: videoInputPath,
42 outputPath: videoTranscodedPath, 42 outputPath: videoTranscodedPath,
43 43
44 availableEncoders, 44 availableEncoders: VideoTranscodingProfilesManager.Instance.getAvailableEncoders(),
45 profile: 'default', 45 profile: 'default',
46 46
47 resolution: inputVideoFile.resolution, 47 resolution: inputVideoFile.resolution,
@@ -95,7 +95,7 @@ async function transcodeNewWebTorrentResolution (video: MVideoWithFile, resoluti
95 inputPath: videoInputPath, 95 inputPath: videoInputPath,
96 outputPath: videoTranscodedPath, 96 outputPath: videoTranscodedPath,
97 97
98 availableEncoders, 98 availableEncoders: VideoTranscodingProfilesManager.Instance.getAvailableEncoders(),
99 profile: 'default', 99 profile: 'default',
100 100
101 resolution, 101 resolution,
@@ -107,7 +107,7 @@ async function transcodeNewWebTorrentResolution (video: MVideoWithFile, resoluti
107 inputPath: videoInputPath, 107 inputPath: videoInputPath,
108 outputPath: videoTranscodedPath, 108 outputPath: videoTranscodedPath,
109 109
110 availableEncoders, 110 availableEncoders: VideoTranscodingProfilesManager.Instance.getAvailableEncoders(),
111 profile: 'default', 111 profile: 'default',
112 112
113 resolution, 113 resolution,
@@ -142,7 +142,7 @@ async function mergeAudioVideofile (video: MVideoWithAllFiles, resolution: Video
142 inputPath: tmpPreviewPath, 142 inputPath: tmpPreviewPath,
143 outputPath: videoTranscodedPath, 143 outputPath: videoTranscodedPath,
144 144
145 availableEncoders, 145 availableEncoders: VideoTranscodingProfilesManager.Instance.getAvailableEncoders(),
146 profile: 'default', 146 profile: 'default',
147 147
148 audioPath: audioInputPath, 148 audioPath: audioInputPath,
@@ -283,7 +283,7 @@ async function generateHlsPlaylistCommon (options: {
283 inputPath, 283 inputPath,
284 outputPath, 284 outputPath,
285 285
286 availableEncoders, 286 availableEncoders: VideoTranscodingProfilesManager.Instance.getAvailableEncoders(),
287 profile: 'default', 287 profile: 'default',
288 288
289 resolution, 289 resolution,