+async function canDoQuickTranscode (path: string): Promise<boolean> {
+ // NOTE: This could be optimized by running ffprobe only once (but it runs fast anyway)
+ const videoStream = await getVideoStreamFromFile(path)
+ const parsedAudio = await audio.get(path)
+ const fps = await getVideoFileFPS(path)
+ const bitRate = await getVideoFileBitrate(path)
+ const resolution = await getVideoFileResolution(path)
+
+ // check video params
+ if (videoStream == null) return false
+ if (videoStream['codec_name'] !== 'h264') return false
+ if (videoStream['pix_fmt'] !== 'yuv420p') return false
+ if (fps < VIDEO_TRANSCODING_FPS.MIN || fps > VIDEO_TRANSCODING_FPS.MAX) return false
+ if (bitRate > getMaxBitrate(resolution.videoFileResolution, fps, VIDEO_TRANSCODING_FPS)) return false
+
+ // check audio params (if audio stream exists)
+ if (parsedAudio.audioStream) {
+ if (parsedAudio.audioStream['codec_name'] !== 'aac') return false
+
+ const maxAudioBitrate = audio.bitrate['aac'](parsedAudio.audioStream['bit_rate'])
+ if (maxAudioBitrate !== -1 && parsedAudio.audioStream['bit_rate'] > maxAudioBitrate) return false
+ }
+
+ return true
+}
+
+function getClosestFramerateStandard (fps: number, type: 'HD_STANDARD' | 'STANDARD'): number {
+ return VIDEO_TRANSCODING_FPS[type].slice(0)
+ .sort((a, b) => fps % a - fps % b)[0]
+}
+
+function convertWebPToJPG (path: string, destination: string): Promise<void> {
+ return new Promise<void>(async (res, rej) => {
+ try {
+ const command = ffmpeg(path).output(destination)
+
+ command.on('error', (err, stdout, stderr) => {
+ logger.error('Error in ffmpeg webp convert process.', { stdout, stderr })
+ return rej(err)
+ })
+ .on('end', () => res())
+ .run()
+ } catch (err) {
+ return rej(err)
+ }
+ })
+}
+