diff options
Diffstat (limited to 'shared/ffmpeg/ffmpeg-version.ts')
-rw-r--r-- | shared/ffmpeg/ffmpeg-version.ts | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/shared/ffmpeg/ffmpeg-version.ts b/shared/ffmpeg/ffmpeg-version.ts new file mode 100644 index 000000000..41d9b2d89 --- /dev/null +++ b/shared/ffmpeg/ffmpeg-version.ts | |||
@@ -0,0 +1,24 @@ | |||
1 | import { exec } from 'child_process' | ||
2 | import ffmpeg from 'fluent-ffmpeg' | ||
3 | |||
4 | export function getFFmpegVersion () { | ||
5 | return new Promise<string>((res, rej) => { | ||
6 | (ffmpeg() as any)._getFfmpegPath((err, ffmpegPath) => { | ||
7 | if (err) return rej(err) | ||
8 | if (!ffmpegPath) return rej(new Error('Could not find ffmpeg path')) | ||
9 | |||
10 | return exec(`${ffmpegPath} -version`, (err, stdout) => { | ||
11 | if (err) return rej(err) | ||
12 | |||
13 | const parsed = stdout.match(/ffmpeg version .?(\d+\.\d+(\.\d+)?)/) | ||
14 | if (!parsed?.[1]) return rej(new Error(`Could not find ffmpeg version in ${stdout}`)) | ||
15 | |||
16 | // Fix ffmpeg version that does not include patch version (4.4 for example) | ||
17 | let version = parsed[1] | ||
18 | if (version.match(/^\d+\.\d+$/)) { | ||
19 | version += '.0' | ||
20 | } | ||
21 | }) | ||
22 | }) | ||
23 | }) | ||
24 | } | ||