-async function getAudioStreamCodec (path: string) {
- const { audioStream } = await audio.get(path)
-
- if (!audioStream) return ''
-
- const audioCodec = audioStream.codec_name
- if (audioCodec === 'aac') return 'mp4a.40.2'
-
- logger.warn('Cannot get audio codec of %s.', path, { audioStream })
-
- return 'mp4a.40.2' // Fallback
-}
-
-async function getVideoFileResolution (path: string) {
- const size = await getVideoStreamSize(path)
-
- return {
- videoFileResolution: Math.min(size.height, size.width),
- isPortraitMode: size.height > size.width
- }
-}
-
-async function getVideoFileFPS (path: string) {
- const videoStream = await getVideoStreamFromFile(path)
- if (videoStream === null) return 0
-
- 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 getMetadataFromFile <T> (path: string, cb = metadata => metadata) {
- return new Promise<T>((res, rej) => {
- ffmpeg.ffprobe(path, (err, metadata) => {
- if (err) return rej(err)