Skip to content

Commit 6e0ac74

Browse files
JonhamDaniel Zahariev
andauthored
Add AbortSignal to ffmpeg/ffprobe spawning (#9)
Co-authored-by: Daniel Zahariev <[email protected]>
1 parent 7a701f5 commit 6e0ac74

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

lib/ffprobe.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ module.exports = function(proto) {
136136
return handleCallback(new Error('Invalid input index'));
137137
}
138138
}
139+
var signal = this.options.signal;
139140

140141
// Find ffprobe
141142
this._getFfprobePath(function(err, path) {
@@ -152,7 +153,7 @@ module.exports = function(proto) {
152153

153154
// Spawn ffprobe
154155
var src = input.isStream ? 'pipe:0' : input.source;
155-
var ffprobe = spawn(path, ['-show_streams', '-show_format'].concat(options, src), {windowsHide: true});
156+
var ffprobe = spawn(path, ['-show_streams', '-show_format'].concat(options, src), {windowsHide: true, signal});
156157

157158
if (input.isStream) {
158159
// Skip errors on stdin. These get thrown when ffprobe is complete and

lib/fluent-ffmpeg.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ var ARGLISTS = ['_global', '_audio', '_audioFilters', '_video', '_videoFilters',
2727
* @param {String} [options.stdoutLines=100] maximum lines of ffmpeg output to keep in memory, use 0 for unlimited
2828
* @param {Number} [options.timeout=<no timeout>] ffmpeg processing timeout in seconds
2929
* @param {String|ReadableStream} [options.source=<no input>] alias for the `input` parameter
30+
* @param {AbortSignal} [options.signal=<no input>] an AbortSignal to cancel the command
3031
*/
3132
function FfmpegCommand(input, options) {
3233
// Make 'new' optional

lib/processor.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,8 @@ module.exports = function(proto) {
438438
captureStdout: !outputStream,
439439
niceness: self.options.niceness,
440440
cwd: self.options.cwd,
441-
windowsHide: true
441+
windowsHide: true,
442+
signal: self.options.signal
442443
},
443444

444445
function processCB(ffmpegProc, stdoutRing, stderrRing) {
@@ -556,7 +557,7 @@ module.exports = function(proto) {
556557
async.each(
557558
flvmeta,
558559
function(output, cb) {
559-
spawn(flvtool, ['-U', output.target], {windowsHide: true})
560+
spawn(flvtool, ['-U', output.target], {windowsHide: true, signal: self.options.signal})
560561
.on('error', function(err) {
561562
cb(new Error('Error running ' + flvtool + ' on ' + output.target + ': ' + err.message));
562563
})
@@ -619,7 +620,7 @@ module.exports = function(proto) {
619620
if (this.ffmpegProc) {
620621
var logger = this.logger;
621622
var pid = this.ffmpegProc.pid;
622-
var renice = spawn('renice', [niceness, '-p', pid], {windowsHide: true});
623+
var renice = spawn('renice', [niceness, '-p', pid], {windowsHide: true, signal: this.options.signal});
623624

624625
renice.on('error', function(err) {
625626
logger.warn('could not renice process ' + pid + ': ' + err.message);

0 commit comments

Comments
 (0)