From ae71acca14e9420646ca7655e64eb9adc13e3006 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 11 Mar 2021 09:51:08 +0100 Subject: Check ffmepg version on startup --- server/helpers/core-utils.ts | 14 +++++++++++++- server/helpers/ffmpeg-utils.ts | 21 ++++++++++++++++++++- 2 files changed, 33 insertions(+), 2 deletions(-) (limited to 'server/helpers') diff --git a/server/helpers/core-utils.ts b/server/helpers/core-utils.ts index 7ba7d865a..ceb6a341d 100644 --- a/server/helpers/core-utils.ts +++ b/server/helpers/core-utils.ts @@ -251,6 +251,16 @@ function promisify2 (func: (arg1: T, arg2: U, cb: (err: any, result: A) } } +function parseSemVersion (s: string) { + const parsed = s.match(/^v?(\d+)\.(\d+)\.(\d+)$/i) + + return { + major: parseInt(parsed[1]), + minor: parseInt(parsed[2]), + patch: parseInt(parsed[3]) + } +} + const randomBytesPromise = promisify1(randomBytes) const createPrivateKey = promisify1(pem.createPrivateKey) const getPublicKey = promisify1(pem.getPublicKey) @@ -288,5 +298,7 @@ export { getPublicKey, execPromise2, execPromise, - pipelinePromise + pipelinePromise, + + parseSemVersion } diff --git a/server/helpers/ffmpeg-utils.ts b/server/helpers/ffmpeg-utils.ts index 620025966..69cd397b9 100644 --- a/server/helpers/ffmpeg-utils.ts +++ b/server/helpers/ffmpeg-utils.ts @@ -5,7 +5,7 @@ import { dirname, join } from 'path' import { FFMPEG_NICE, VIDEO_LIVE } from '@server/initializers/constants' import { AvailableEncoders, EncoderOptionsBuilder, EncoderProfile, VideoResolution } from '../../shared/models/videos' import { CONFIG } from '../initializers/config' -import { promisify0 } from './core-utils' +import { execPromise, promisify0 } from './core-utils' import { computeFPS, getAudioStream, getVideoFileFPS } from './ffprobe-utils' import { processImage } from './image-utils' import { logger } from './logger' @@ -649,6 +649,24 @@ function getFFmpeg (input: string, type: 'live' | 'vod') { return command } +function getFFmpegVersion () { + return new Promise((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 execPromise(`${ffmpegPath} -version`) + .then(stdout => { + const parsed = stdout.match(/ffmpeg version .(\d+\.\d+\.\d+)/) + if (!parsed || !parsed[1]) return rej(new Error(`Could not find ffmpeg version in ${stdout}`)) + + return res(parsed[1]) + }) + .catch(err => rej(err)) + }) + }) +} + async function runCommand (options: { command: ffmpeg.FfmpegCommand silent?: boolean // false @@ -695,6 +713,7 @@ export { TranscodeOptionsType, transcode, runCommand, + getFFmpegVersion, resetSupportedEncoders, -- cgit v1.2.3