If a user wants to kill a running ffmpeg process, what is the recommend way to go about that?
killall ffmpeg
should do the trick. If you mean you want to exit it. When you want to programmatically kill it we have to implement it ... (Next Weekend, maybe)
Yes I meant programmatically. For now I'm just exiting the program which does the trick of course, but this seems like a nice feature to have.
I would require this feature as well.
ffmpegProc (https://github.com/schaermu/node-fluent-ffmpeg/blob/master/lib/processor.js#L53)
should be exposed to the client. This can be easily done extending e.g. onStart callback with an extra argument.
Pull request #202 was merged and adds a kill method to FfmpegCommand.
@bencevans you can close this issue.
Disclaimer: Sorry for being a noob but I'm totally new to node.js.
In my API app, after a video file is uploaded, I'm using fluent-ffmpeg to transcode videos. How can I kill a specific transcoding job to cancel it? Users should be able to cancel transcodes that they started. Is there something like a UUID or process ID dedicated to each command? Thanks!
You can simply keep running commands in your node app and call the kill method when requested.
As I said, I'm a newbie in node.js... Below is my code, if you have a few minutes, could you show me what do you mean? Thanks in advence! (btw; you probably would figure out but, I'm using Sails)
module.exports = {
create: function(req, res) {
var form = new formidable.IncomingForm();
form.uploadDir = "/Users/scaryguy/node/test/sources";
form.multiples = true;
form.keepExtensions = true;
form.on('progress', function(bytesReceived, bytesExpected) {
console.log(bytesReceived + " / " + bytesExpected);
})
.parse(req, function(err, fields, files) {
res.send({
fields: fields,
files: files
});
});
form.on('file', function(name, file) {
FFMPEG.ffprobe(file.path, function(err, metadata) {
// console.dir(metadata.streams);
});
var command = FFMPEG(file.path).on('progress', function(progress) {
console.log('Processing: ' + progress.percent + '% done');
}).on('error', function(err) {
console.log('An error occurred: ' + err.message);
}).on('end', function() {
console.log('Processing finished !');
})
.save('/Users/scaryguy/node/test/sources/oh_my_God.mp4');
console.log(command)
});
}
};
A simple solution would be to use a running command store and have a way to generate a unique ID for each command:
var runningCommands = {};
function generateID() {
return someUniqueIdentifier;
}
Then when creating a command, generate an ID, store it, and remove it when it finishes:
var id = generateID();
runningCommands[id] = command;
command.on('end', function() {
delete runningCommands[id];
});
command.on('error', function() {
delete runningCommands[id];
});
And finally, add an action to kill a command by its ID:
kill: function(req, res) {
var id = req.params('id'); // Retrieve ID from request
if (!(id in runningCommands)) {
// 404 for example
}
runningCommands[id].kill();
};
You may want to add a way for the client to retrieve the list of running jobs along with their ID.
Thank you very much for spending time with this great answer Nicolas!
I would love to store running commands in my database. But the thing I'm not clear with is, is it possible to store them in db some way?
At your recommendation seems like you store processes as instances in the memory, right?
I really appreciate your help! Thanks again!
28 Ağu 2014 tarihinde 20:58 saatinde, Nicolas Joyard [email protected] şunları yazdı:
A simple solution would be to use a running command store and have a way to generate a unique ID for each command:
var runningCommands = {};
function generateID() {
return someUniqueIdentifier;
}
Then when creating a command, generate an ID, store it, and remove it when it finishes:var id = generateID();
runningCommands[id] = command;
command.on('end', function() {
delete runningCommands[id];
});
command.on('error', function() {
delete runningCommands[id];
});
And finally, add an action to kill a command by its ID:kill: function(req, res) {
var id = req.params('id'); // Retrieve ID from request
if (!(id in runningCommands)) {
// 404 for example
}runningCommands[id].kill();
};
You may want to add a way for the client to retrieve the list of running jobs along with their ID.—
Reply to this email directly or view it on GitHub.
This is not feasible as commands are complex objects. And it is also useless (node keeps running commands in memory anyway, so no need to store them somewhere else in addition).
Allright! Thank you for tricks! I'll give a try to your recommandations
tomorrow and will get back to you about results (btw, I'm currently using a
github issue out of its purpose but since it's already a closed issue I
don't mind too much. But maybe I'd better move this question to SOF and let
you know the link? So you earn points! :D )
29 AÄŸustos 2014 Cuma tarihinde, Nicolas Joyard [email protected]
yazdı:
This is not feasible as commands are complex objects. And it is also
useless (node keeps running commands in memory anyway, so no need to store
them somewhere else in addition).—
Reply to this email directly or view it on GitHub
https://github.com/fluent-ffmpeg/node-fluent-ffmpeg/issues/138#issuecomment-53807284
.
It worked like charm! Thank you very much taking time to answer my question @njoyard !
This is not feasible as commands are complex objects. And it is also useless (node keeps running commands in memory anyway, so no need to store them somewhere else in addition).
I'm running into Node ENOMEM issues on Node v 12.16.2, calling a bunch of normal FFMPEG commands. Perhaps ENOMEM is a result of Node management and accumulation of ffmpeg commands?? I am passing in file paths rather then readStreams as well, could that be a source of memory leak??
Most helpful comment
killall ffmpegshould do the trick. If you mean you want to exit it. When you want to programmatically kill it we have to implement it ... (Next Weekend, maybe)