diff --git a/README.md b/README.md
index 57f8dab..ccc896b 100644
--- a/README.md
+++ b/README.md
@@ -275,6 +275,7 @@ The Node API is structured similarly to the command line options, but there are
* # `headless` <[boolean][]> Runs puppeteer in headless (nonwindowed) mode (default: `true`).
* # `inputOptions` <[Array][] <[string][]>> Extra arguments for ffmpeg input. Example: `['-framerate', '30']`
* # `outputOptions` <[Array][] <[string][]>> Extra arguments for ffmpeg output. Example: `['-vf', 'scale=320:240']`
+ * # `ffmpegProcessOptions` <[Array][] <[string][]>> Extra arguments for ffmpeg process. Example: `{detached: true}`
* # `pixFmt` <[string][]> Pixel format for output video (default: `yuv420p`).
* # `startDelay` <[number][]> Waits `config.loadDelay` real seconds after loading before starting (default: `0`).
* # `keepFrames` <[boolean][]> If set to true, doesn't delete frames after processing them. Doesn't do anything in pipe mode.
@@ -286,6 +287,10 @@ The Node API is structured similarly to the command line options, but there are
* `page` <[Page][]> The puppeteer instance of the page being captured.
* `frameNumber` <[number][]> The current frame number (1 based).
* `totalFrames` <[number][]> The total number of frames.
+ * # `ffmpegCommand` <[function][]([string][])> A callback function that will be called before ffmpeg execution containing the full ffmpeg command.
+ * `command` <[string][]> The ffmpeg command.
+ * # `ffmpegProcess` <[function][]([ChildProcess][])> A callback function that will be called after ffmpeg process spawned and return the ffmpeg child process that later could be used to cancel the execution or to listen to its events.
+ * `process` <[ChildProcess][]> The ffmpeg child process.
* # returns: <[Promise][]> resolves after all the frames have been captured.
## # **timecut** Modes
@@ -312,3 +317,4 @@ This work was inspired by [a talk by Noah Veltman](https://github.com/veltman/d3
[function]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions
[CSS selector]: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors
[Page]: https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#class-page
+[ChildProcess]: https://nodejs.org/api/child_process.html#child_process_class_childprocess
diff --git a/index.js b/index.js
index 26511a3..2b61405 100644
--- a/index.js
+++ b/index.js
@@ -73,6 +73,7 @@ module.exports = function (config) {
var ffmpegArgs;
var inputOptions = config.inputOptions || [];
var outputOptions = config.outputOptions || [];
+ var ffmpegProcessOptions = config.ffmpegProcessOptions || null;
var frameDirectory = config.tempDir || config.frameDir;
var fps;
var frameMode = config.frameCache || !config.pipeMode;
@@ -132,7 +133,15 @@ module.exports = function (config) {
}
// -y writes over existing files
ffmpegArgs = ffmpegArgs.concat(outputOptions).concat(['-y', output]);
- convertProcess = spawn('ffmpeg', ffmpegArgs);
+ if(config.ffmpegCommand && typeof config.ffmpegCommand === 'function') {
+ config.ffmpegCommand('ffmpeg ' + ffmpegArgs.join(' '));
+ }
+
+ convertProcess = spawn('ffmpeg', ffmpegArgs, ffmpegProcessOptions);
+ if(config.ffmpegProcess && typeof config.ffmpegProcess === 'function') {
+ config.ffmpegProcess(convertProcess);
+ }
+
convertProcess.stderr.setEncoding('utf8');
convertProcess.stderr.on('data', function (data) {
log(data);
@@ -158,7 +167,9 @@ module.exports = function (config) {
if (processError) {
throw processError;
}
- convertProcess.stdin.write(buffer);
+ if(!convertProcess.killed) {
+ convertProcess.stdin.write(buffer);
+ }
};
}
diff --git a/package.json b/package.json
index b441ca8..0f86505 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "timecut",
- "version": "0.1.3-prerelease",
+ "version": "0.1.4-prerelease",
"description": "Record smooth movies of web pages",
"repository": {
"type": "git",