aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/initializers
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-11-23 16:23:52 +0100
committerChocobozzz <chocobozzz@cpy.re>2020-11-25 10:07:51 +0100
commit9252a33d115bba85adcfbc18ab3725924642871c (patch)
tree94365b67fc25cb0d9ce046a820d07344742179f6 /server/initializers
parentdaf6e4801052d3ca6be2fafd20bae2323b1ce175 (diff)
downloadPeerTube-9252a33d115bba85adcfbc18ab3725924642871c.tar.gz
PeerTube-9252a33d115bba85adcfbc18ab3725924642871c.tar.zst
PeerTube-9252a33d115bba85adcfbc18ab3725924642871c.zip
Export encoders options in a dedicated struct
Diffstat (limited to 'server/initializers')
-rw-r--r--server/initializers/checker-before-init.ts29
-rw-r--r--server/initializers/constants.ts12
2 files changed, 30 insertions, 11 deletions
diff --git a/server/initializers/checker-before-init.ts b/server/initializers/checker-before-init.ts
index 93b71a242..4ffd6fad9 100644
--- a/server/initializers/checker-before-init.ts
+++ b/server/initializers/checker-before-init.ts
@@ -82,6 +82,8 @@ function checkMissedConfig () {
82async function checkFFmpeg (CONFIG: { TRANSCODING: { ENABLED: boolean } }) { 82async function checkFFmpeg (CONFIG: { TRANSCODING: { ENABLED: boolean } }) {
83 if (CONFIG.TRANSCODING.ENABLED === false) return undefined 83 if (CONFIG.TRANSCODING.ENABLED === false) return undefined
84 84
85 checkFFmpegEncoders()
86
85 const Ffmpeg = require('fluent-ffmpeg') 87 const Ffmpeg = require('fluent-ffmpeg')
86 const getAvailableCodecsPromise = promisify0(Ffmpeg.getAvailableCodecs) 88 const getAvailableCodecsPromise = promisify0(Ffmpeg.getAvailableCodecs)
87 const codecs = await getAvailableCodecsPromise() 89 const codecs = await getAvailableCodecsPromise()
@@ -100,25 +102,30 @@ async function checkFFmpeg (CONFIG: { TRANSCODING: { ENABLED: boolean } }) {
100 return checkFFmpegEncoders() 102 return checkFFmpegEncoders()
101} 103}
102 104
103// Optional encoders, if present, can be used to improve transcoding 105// Detect supported encoders by ffmpeg
104// Here we ask ffmpeg if it detects their presence on the system, so that we can later use them 106let supportedEncoders: Map<string, boolean>
105let supportedOptionalEncoders: Map<string, boolean>
106async function checkFFmpegEncoders (): Promise<Map<string, boolean>> { 107async function checkFFmpegEncoders (): Promise<Map<string, boolean>> {
107 if (supportedOptionalEncoders !== undefined) { 108 if (supportedEncoders !== undefined) {
108 return supportedOptionalEncoders 109 return supportedEncoders
109 } 110 }
110 111
111 const Ffmpeg = require('fluent-ffmpeg') 112 const Ffmpeg = require('fluent-ffmpeg')
112 const getAvailableEncodersPromise = promisify0(Ffmpeg.getAvailableEncoders) 113 const getAvailableEncodersPromise = promisify0(Ffmpeg.getAvailableEncoders)
113 const encoders = await getAvailableEncodersPromise() 114 const availableEncoders = await getAvailableEncodersPromise()
114 const optionalEncoders = [ 'libfdk_aac' ] 115
115 supportedOptionalEncoders = new Map<string, boolean>() 116 const searchEncoders = [
117 'aac',
118 'libfdk_aac',
119 'libx264'
120 ]
121
122 supportedEncoders = new Map<string, boolean>()
116 123
117 for (const encoder of optionalEncoders) { 124 for (const searchEncoder of searchEncoders) {
118 supportedOptionalEncoders.set(encoder, encoders[encoder] !== undefined) 125 supportedEncoders.set(searchEncoder, availableEncoders[searchEncoder] !== undefined)
119 } 126 }
120 127
121 return supportedOptionalEncoders 128 return supportedEncoders
122} 129}
123 130
124function checkNodeVersion () { 131function checkNodeVersion () {
diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts
index 5c6d06077..945185f62 100644
--- a/server/initializers/constants.ts
+++ b/server/initializers/constants.ts
@@ -336,6 +336,17 @@ const VIDEO_TRANSCODING_FPS: VideoTranscodingFPS = {
336 KEEP_ORIGIN_FPS_RESOLUTION_MIN: 720 // We keep the original FPS on high resolutions (720 minimum) 336 KEEP_ORIGIN_FPS_RESOLUTION_MIN: 720 // We keep the original FPS on high resolutions (720 minimum)
337} 337}
338 338
339const VIDEO_TRANSCODING_ENCODERS = {
340 VIDEO: [ 'libx264' ],
341
342 // Try the first one, if not available try the second one etc
343 AUDIO: [
344 // we favor VBR, if a good AAC encoder is available
345 'libfdk_aac',
346 'aac'
347 ]
348}
349
339const DEFAULT_AUDIO_RESOLUTION = VideoResolution.H_480P 350const DEFAULT_AUDIO_RESOLUTION = VideoResolution.H_480P
340 351
341const VIDEO_RATE_TYPES: { [ id: string ]: VideoRateType } = { 352const VIDEO_RATE_TYPES: { [ id: string ]: VideoRateType } = {
@@ -804,6 +815,7 @@ export {
804 ACTOR_FOLLOW_SCORE, 815 ACTOR_FOLLOW_SCORE,
805 PREVIEWS_SIZE, 816 PREVIEWS_SIZE,
806 REMOTE_SCHEME, 817 REMOTE_SCHEME,
818 VIDEO_TRANSCODING_ENCODERS,
807 FOLLOW_STATES, 819 FOLLOW_STATES,
808 DEFAULT_USER_THEME_NAME, 820 DEFAULT_USER_THEME_NAME,
809 SERVER_ACTOR_NAME, 821 SERVER_ACTOR_NAME,