1
0
Fork 0
peertube/shared/ffmpeg/ffmpeg-version.ts
Chocobozzz 0c9668f779 Implement remote runner jobs in server
Move ffmpeg functions to @shared
2023-05-09 08:57:34 +02:00

24 lines
808 B
TypeScript

import { exec } from 'child_process'
import ffmpeg from 'fluent-ffmpeg'
export function getFFmpegVersion () {
return new Promise<string>((res, rej) => {
(ffmpeg() as any)._getFfmpegPath((err, ffmpegPath) => {
if (err) return rej(err)
if (!ffmpegPath) return rej(new Error('Could not find ffmpeg path'))
return exec(`${ffmpegPath} -version`, (err, stdout) => {
if (err) return rej(err)
const parsed = stdout.match(/ffmpeg version .?(\d+\.\d+(\.\d+)?)/)
if (!parsed?.[1]) return rej(new Error(`Could not find ffmpeg version in ${stdout}`))
// Fix ffmpeg version that does not include patch version (4.4 for example)
let version = parsed[1]
if (version.match(/^\d+\.\d+$/)) {
version += '.0'
}
})
})
})
}