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