diff --git a/README.md b/README.md index b63448bf..189b72ef 100644 --- a/README.md +++ b/README.md @@ -1402,6 +1402,21 @@ command.clone() command.save('/path/to/output-original-size.mp4'); ``` +### Child Process Options + +You can pass child-process options to the spawn method. +See [child_process.spawn](https://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options). + +```js +// Create a detached process command to convert source.avi to MP4 +var command = ffmpeg('/path/to/source.avi') + .withProcessOptions({ + detached: true + }) + .format('mp4') + .save('/path/to/output.mp4'); +``` + ## Contributing diff --git a/lib/processor.js b/lib/processor.js index 36d980ad..3233a514 100644 --- a/lib/processor.js +++ b/lib/processor.js @@ -431,16 +431,18 @@ module.exports = function(proto) { return emitEnd(err); } + var options = Object.assign({ + captureStdout: !outputStream, + niceness: self.options.niceness, + cwd: self.options.cwd, + windowsHide: true + }, self.options.processOptions || {}); + // Run ffmpeg self._spawnFfmpeg( args, - { - captureStdout: !outputStream, - niceness: self.options.niceness, - cwd: self.options.cwd, - windowsHide: true - }, - + options, + function processCB(ffmpegProc, stdoutRing, stderrRing) { self.ffmpegProc = ffmpegProc; self.emit('start', 'ffmpeg ' + args.join(' ')); @@ -641,6 +643,21 @@ module.exports = function(proto) { }; + /** + * Add process options to spawn + * + * @method FfmpegCommand#withProcessOptions + * @category Processing + * + * @see [child_process.spawn](https://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options) + * @return FfmpegCommand + */ + proto.withProcessOptions = function(options) { + options = options || {}; + this.options.processOptions = options; + return this; + }; + /** * Kill current ffmpeg process, if any *