Skip to content

Commit

Permalink
Add version check #34
Browse files Browse the repository at this point in the history
  • Loading branch information
mifi committed Oct 29, 2020
1 parent c72b036 commit 21be77c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
20 changes: 20 additions & 0 deletions ffmpeg.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
const fs = require('fs-extra');
const execa = require('execa');
const assert = require('assert');
const gte = require('semver/functions/gte');

const getFfmpegCommonArgs = ({ enableFfmpegLog }) => (enableFfmpegLog ? [] : ['-hide_banner', '-loglevel', 'error']);

Expand All @@ -11,9 +14,26 @@ async function createConcatFile(segments, concatFilePath) {
await fs.writeFile(concatFilePath, segments.map((seg) => `file '${seg.replace(/'/g, "'\\''")}'`).join('\n'));
}

async function testFf(exePath, name) {
const requiredVersion = '4.3.1';

try {
const { stdout } = await execa(exePath, ['-version']);
const firstLine = stdout.split('\n')[0];
const match = firstLine.match(`${name} version ([0-9.]+)`);
assert(match, 'Unknown version string');
const versionStr = match[1];
console.log(`${name} version ${versionStr}`);
assert(gte(versionStr, requiredVersion), 'Version is outdated');
} catch (err) {
console.error(`WARNING: ${name} issue:`, err.message);
}
}

module.exports = {
getFfmpegCommonArgs,
getCutFromArgs,
getCutToArgs,
createConcatFile,
testFf,
};
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const JSON5 = require('json5');
const fs = require('fs-extra');
const { nanoid } = require('nanoid');

const { testFf } = require('./ffmpeg');
const { parseFps, multipleOf2 } = require('./util');
const { createFabricCanvas, rgbaToFabricImage, getNodeCanvasFromFabricCanvas } = require('./sources/fabric');
const { createFrameSource } = require('./sources/frameSource');
Expand Down Expand Up @@ -43,6 +44,9 @@ const Editly = async (config = {}) => {
ffprobePath = 'ffprobe',
} = config;

await testFf(ffmpegPath, 'ffmpeg');
await testFf(ffprobePath, 'ffprobe');

const isGif = outPath.toLowerCase().endsWith('.gif');

if (backgroundAudioPath) await assertFileValid(backgroundAudioPath, allowRemoteRequests);
Expand Down

0 comments on commit 21be77c

Please sign in to comment.