-
-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_480P,
- VideoResolution.H_360P,
- VideoResolution.H_720P,
- VideoResolution.H_240P,
- VideoResolution.H_1080P
- ]
-
- for (const resolution of resolutions) {
- if (configResolutions[ resolution + 'p' ] === true && videoFileHeight > resolution) {
- resolutionsEnabled.push(resolution)
- }
- }
-
- return resolutionsEnabled
-}
-
-async function getVideoFileSize (path: string) {
- const videoStream = await getVideoStreamFromFile(path)
-
- return {
- width: videoStream.width,
- height: videoStream.height
- }
-}
-
-async function getVideoFileResolution (path: string) {
- const size = await getVideoFileSize(path)
-
- return {
- videoFileResolution: Math.min(size.height, size.width),
- isPortraitMode: size.height > size.width
- }
-}
-
-async function getVideoFileFPS (path: string) {
- const videoStream = await getVideoStreamFromFile(path)
-
- for (const key of [ 'avg_frame_rate', 'r_frame_rate' ]) {
- const valuesText: string = videoStream[key]
- if (!valuesText) continue
-
- const [ frames, seconds ] = valuesText.split('/')
- if (!frames || !seconds) continue
-
- const result = parseInt(frames, 10) / parseInt(seconds, 10)
- if (result > 0) return Math.round(result)
- }
-
- return 0
-}
-
-async function getVideoFileBitrate (path: string) {
- return new Promise<number>((res, rej) => {
- ffmpeg.ffprobe(path, (err, metadata) => {
- if (err) return rej(err)
-
- return res(metadata.format.bit_rate)
- })
- })
-}
-
-function getDurationFromVideoFile (path: string) {
- return new Promise<number>((res, rej) => {
- ffmpeg.ffprobe(path, (err, metadata) => {
- if (err) return rej(err)
-
- return res(Math.floor(metadata.format.duration))
- })
- })
-}