- export namespace bitrate {
- const baseKbitrate = 384
-
- const toBits = (kbits: number) => kbits * 8000
-
- export const aac = (bitrate: number): number => {
- switch (true) {
- case bitrate > toBits(baseKbitrate):
- return baseKbitrate
-
- default:
- return -1 // we interpret it as a signal to copy the audio stream as is
- }
- }
-
- export const mp3 = (bitrate: number): number => {
- /*
- a 192kbit/sec mp3 doesn't hold as much information as a 192kbit/sec aac.
- That's why, when using aac, we can go to lower kbit/sec. The equivalences
- made here are not made to be accurate, especially with good mp3 encoders.
- */
- switch (true) {
- case bitrate <= toBits(192):
- return 128
-
- case bitrate <= toBits(384):
- return 256
-
- default:
- return baseKbitrate
- }
- }
- }
-}
-
-function computeResolutionsToTranscode (videoFileHeight: number) {
- const resolutionsEnabled: number[] = []
- const configResolutions = CONFIG.TRANSCODING.RESOLUTIONS
-
- // Put in the order we want to proceed jobs
- const resolutions = [
- VideoResolution.H_NOVIDEO,
- VideoResolution.H_480P,
- VideoResolution.H_360P,
- VideoResolution.H_720P,
- VideoResolution.H_240P,
- VideoResolution.H_1080P,
- VideoResolution.H_4K
- ]
-
- for (const resolution of resolutions) {
- if (configResolutions[resolution + 'p'] === true && videoFileHeight > resolution) {
- resolutionsEnabled.push(resolution)
- }
- }
-
- return resolutionsEnabled
-}
-
-async function getVideoStreamSize (path: string) {
- const videoStream = await getVideoStreamFromFile(path)
-
- return videoStream === null
- ? { width: 0, height: 0 }
- : { width: videoStream.width, height: videoStream.height }
-}
-
-async function getVideoStreamCodec (path: string) {
- const videoStream = await getVideoStreamFromFile(path)
-
- if (!videoStream) return ''
-
- const videoCodec = videoStream.codec_tag_string