aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/ffmpeg/ffmpeg-version.ts
blob: 41d9b2d89f4e39c796ccd24aed62c0f333704be9 (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
24
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'
        }
      })
    })
  })
}