aboutsummaryrefslogtreecommitdiffhomepage
path: root/packages/ffmpeg/src/ffmpeg-version.ts
blob: f737bc2540dba3dbeb4b96f4796410008b824286 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { exec } from 'child_process'
import ffmpeg from 'fluent-ffmpeg'

/**
 * @returns FFmpeg version string. Usually a semver string, but may vary when depending on installation method.
 */
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 )[a-zA-Z\d.-]+/)
        if (!parsed) return rej(new Error(`Could not find ffmpeg version in ${stdout}`))

        res(parsed[0])
      })
    })
  })
}