forked from mifi/editly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathffmpeg.js
40 lines (32 loc) · 1.34 KB
/
ffmpeg.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
const fs = require('fs-extra');
const execa = require('execa');
const assert = require('assert');
const compareVersions = require('compare-versions');
const getFfmpegCommonArgs = ({ enableFfmpegLog }) => (enableFfmpegLog ? [] : ['-hide_banner', '-loglevel', 'error']);
const getCutFromArgs = ({ cutFrom }) => (cutFrom ? ['-ss', cutFrom] : []);
const getCutToArgs = ({ cutTo, cutFrom, speedFactor }) => (cutTo ? ['-t', (cutTo - cutFrom) * speedFactor] : []);
async function createConcatFile(segments, concatFilePath) {
// https://superuser.com/questions/787064/filename-quoting-in-ffmpeg-concat
await fs.writeFile(concatFilePath, segments.map((seg) => `file '${seg.replace(/'/g, "'\\''")}'`).join('\n'));
}
async function testFf(exePath, name) {
const minRequiredVersion = '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(compareVersions(versionStr, minRequiredVersion, '>='), 'Version is outdated');
} catch (err) {
console.error(`WARNING: ${name}:`, err.message);
}
}
module.exports = {
getFfmpegCommonArgs,
getCutFromArgs,
getCutToArgs,
createConcatFile,
testFf,
};