aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers
diff options
context:
space:
mode:
Diffstat (limited to 'server/helpers')
-rw-r--r--server/helpers/core-utils.ts14
-rw-r--r--server/helpers/ffmpeg-utils.ts25
2 files changed, 21 insertions, 18 deletions
diff --git a/server/helpers/core-utils.ts b/server/helpers/core-utils.ts
index 38b6f63f8..9ff67c43a 100644
--- a/server/helpers/core-utils.ts
+++ b/server/helpers/core-utils.ts
@@ -4,7 +4,7 @@
4*/ 4*/
5 5
6import { createHash, HexBase64Latin1Encoding, pseudoRandomBytes } from 'crypto' 6import { createHash, HexBase64Latin1Encoding, pseudoRandomBytes } from 'crypto'
7import { isAbsolute, join } from 'path' 7import { basename, isAbsolute, join, resolve } from 'path'
8import * as pem from 'pem' 8import * as pem from 'pem'
9import { URL } from 'url' 9import { URL } from 'url'
10import { truncate } from 'lodash' 10import { truncate } from 'lodash'
@@ -136,16 +136,16 @@ function getAppNumber () {
136 return process.env.NODE_APP_INSTANCE 136 return process.env.NODE_APP_INSTANCE
137} 137}
138 138
139let rootPath: string
139function root () { 140function root () {
141 if (rootPath) return rootPath
142
140 // We are in /helpers/utils.js 143 // We are in /helpers/utils.js
141 const paths = [ __dirname, '..', '..' ] 144 rootPath = join(__dirname, '..', '..')
142 145
143 // We are under /dist directory 146 if (basename(rootPath) === 'dist') rootPath = resolve(rootPath, '..')
144 if (process.mainModule && process.mainModule.filename.endsWith('_mocha') === false) {
145 paths.push('..')
146 }
147 147
148 return join.apply(null, paths) 148 return rootPath
149} 149}
150 150
151// Thanks: https://stackoverflow.com/a/12034334 151// Thanks: https://stackoverflow.com/a/12034334
diff --git a/server/helpers/ffmpeg-utils.ts b/server/helpers/ffmpeg-utils.ts
index 8041e7b3b..914ecc51a 100644
--- a/server/helpers/ffmpeg-utils.ts
+++ b/server/helpers/ffmpeg-utils.ts
@@ -387,14 +387,15 @@ namespace audio {
387 export namespace bitrate { 387 export namespace bitrate {
388 const baseKbitrate = 384 388 const baseKbitrate = 384
389 389
390 const toBits = (kbits: number): number => { return kbits * 8000 } 390 const toBits = (kbits: number) => kbits * 8000
391 391
392 export const aac = (bitrate: number): number => { 392 export const aac = (bitrate: number): number => {
393 switch (true) { 393 switch (true) {
394 case bitrate > toBits(baseKbitrate): 394 case bitrate > toBits(baseKbitrate):
395 return baseKbitrate 395 return baseKbitrate
396 default: 396
397 return -1 // we interpret it as a signal to copy the audio stream as is 397 default:
398 return -1 // we interpret it as a signal to copy the audio stream as is
398 } 399 }
399 } 400 }
400 401
@@ -405,12 +406,14 @@ namespace audio {
405 made here are not made to be accurate, especially with good mp3 encoders. 406 made here are not made to be accurate, especially with good mp3 encoders.
406 */ 407 */
407 switch (true) { 408 switch (true) {
408 case bitrate <= toBits(192): 409 case bitrate <= toBits(192):
409 return 128 410 return 128
410 case bitrate <= toBits(384): 411
411 return 256 412 case bitrate <= toBits(384):
412 default: 413 return 256
413 return baseKbitrate 414
415 default:
416 return baseKbitrate
414 } 417 }
415 } 418 }
416 } 419 }