Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add AbortSignal to ffmpeg/ffprobe spawning #1288

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/ffprobe.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ module.exports = function(proto) {
return handleCallback(new Error('Invalid input index'));
}
}
var signal = this.options.signal;

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

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

if (input.isStream) {
// Skip errors on stdin. These get thrown when ffprobe is complete and
Expand Down
1 change: 1 addition & 0 deletions lib/fluent-ffmpeg.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ var ARGLISTS = ['_global', '_audio', '_audioFilters', '_video', '_videoFilters',
* @param {String} [options.stdoutLines=100] maximum lines of ffmpeg output to keep in memory, use 0 for unlimited
* @param {Number} [options.timeout=<no timeout>] ffmpeg processing timeout in seconds
* @param {String|ReadableStream} [options.source=<no input>] alias for the `input` parameter
* @param {AbortSignal} [options.signal=<no input>] an AbortSignal to cancel the command
*/
function FfmpegCommand(input, options) {
// Make 'new' optional
Expand Down
7 changes: 4 additions & 3 deletions lib/processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,8 @@ module.exports = function(proto) {
captureStdout: !outputStream,
niceness: self.options.niceness,
cwd: self.options.cwd,
windowsHide: true
windowsHide: true,
signal: self.options.signal
},

function processCB(ffmpegProc, stdoutRing, stderrRing) {
Expand Down Expand Up @@ -556,7 +557,7 @@ module.exports = function(proto) {
async.each(
flvmeta,
function(output, cb) {
spawn(flvtool, ['-U', output.target], {windowsHide: true})
spawn(flvtool, ['-U', output.target], {windowsHide: true, signal: self.options.signal})
.on('error', function(err) {
cb(new Error('Error running ' + flvtool + ' on ' + output.target + ': ' + err.message));
})
Expand Down Expand Up @@ -619,7 +620,7 @@ module.exports = function(proto) {
if (this.ffmpegProc) {
var logger = this.logger;
var pid = this.ffmpegProc.pid;
var renice = spawn('renice', [niceness, '-p', pid], {windowsHide: true});
var renice = spawn('renice', [niceness, '-p', pid], {windowsHide: true, signal: this.options.signal});

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