From 19817ddf1f2682c7e009622a5d283b0106a5c931 Mon Sep 17 00:00:00 2001 From: Johnathan Amit-Kanarek Date: Wed, 5 Aug 2020 11:22:50 +0300 Subject: [PATCH 1/2] Expose ffmpeg child-process --- README.md | 5 +++++ index.js | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/README.md b/README.md index 1c3fabd..5d5c2c8 100644 --- a/README.md +++ b/README.md @@ -132,6 +132,9 @@ Edit specs are JavaScript / JSON objects describing the whole edit operation wit enableFfmpegLog: false, verbose: false, fast: false, + + onStart: (cmd) => console.log('Command:', cmd), + onProcessStart: (subprocess) => subprocess.stdout.pipe(process.stdout), } ``` @@ -156,6 +159,8 @@ Edit specs are JavaScript / JSON objects describing the whole edit operation wit | `clips[].transition` | | Specify transition at the **end** of this clip. See `defaults.transition` | `defaults.transition` | | | `clips[].layers[]` | | List of layers within the current clip that will be overlaid in their natural order (last layer on top) | | | | `clips[].layers[].type` | | Layer type, see below | | | +| `onStart` | | Callback function, called before ffmpeg process start with command line as string argument | | | +| `onProcessStart` | | Callback function, called after ffmpeg process start with subprocess argument | | | ### Transition types diff --git a/index.js b/index.js index 075dfe4..d5306e7 100644 --- a/index.js +++ b/index.js @@ -39,8 +39,15 @@ module.exports = async (config = {}) => { ffmpegPath = 'ffmpeg', ffprobePath = 'ffprobe', + + onStart, + onProcessStart, + } = config; + assert(!onStart || typeof onStart === 'function', 'Callback onStart expected to be a function'); + assert(!onProcessStart || typeof onProcessStart === 'function', 'Callback onProcessStart expected to be a function'); + const isGif = outPath.toLowerCase().endsWith('.gif'); const audioFilePath = isGif ? undefined : audioFilePathIn; @@ -314,6 +321,7 @@ module.exports = async (config = {}) => { ...outputArgs, ]; if (verbose) console.log('ffmpeg', args.join(' ')); + if (onStart) onStart(`ffmpeg ${args.join(' ')}`); return execa(ffmpegPath, args, { encoding: null, buffer: false, stdin: 'pipe', stdout: process.stdout, stderr: process.stderr }); } @@ -323,6 +331,7 @@ module.exports = async (config = {}) => { try { outProcess = startFfmpegWriterProcess(); + if (onProcessStart) onProcessStart(outProcess); let outProcessError; // If we don't catch it here, the whole process will crash and we cannot process the error From fecceb87b6bac4ceb62697c2e0003b481638913b Mon Sep 17 00:00:00 2001 From: Johnathan Amit-Kanarek Date: Wed, 5 Aug 2020 11:58:08 +0300 Subject: [PATCH 2/2] Support remote input files over http --- index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index d5306e7..c758686 100644 --- a/index.js +++ b/index.js @@ -19,7 +19,7 @@ const loadedFonts = []; // See #16 const checkTransition = (transition) => assert(transition == null || typeof transition === 'object', 'Transition must be an object'); -const assertFileExists = async (path) => assert(await fs.exists(path), `File does not exist ${path}`); +const assertFileExists = async (path, enableRemote) => assert((enableRemote && path.startsWith('http')) || await fs.exists(path), `File does not exist ${path}`); module.exports = async (config = {}) => { @@ -52,7 +52,7 @@ module.exports = async (config = {}) => { const audioFilePath = isGif ? undefined : audioFilePathIn; - if (audioFilePath) await assertFileExists(audioFilePath); + if (audioFilePath) await assertFileExists(audioFilePath, true); checkTransition(defaultsIn.transition); @@ -76,7 +76,7 @@ module.exports = async (config = {}) => { // https://github.com/mifi/editly/issues/39 if (type === 'image') { - await assertFileExists(restLayer.path); + await assertFileExists(restLayer.path, true); } else if (type === 'gl') { await assertFileExists(restLayer.fragmentPath); }