I am using node.js code that converts Axis Ipcamera live stream to mp4 using FFMPEG
var childProcess=require('child_process');
var childArguments = [];
var child=[];
var cmd='ffmpeg -i rtsp://172.24.22.117:554/axis-media/media.amp -vcodec libx264 -pix_fmt yuv420p -profile:v baseline -preset slower -crf 18 -vf "scale=trunc(in_w/2)*2:trunc(in_h/2)*2"'+' '+__dirname+'/uploads/ouput.mp4';
child=childProcess.exec(
cmd,
childArguments,
{
env: process.env,
silent:true
}, function (err, stdout, stderr) {
if (err) {
throw err;
}
console.log(stdout);
});
child.stdout.on('data', function (data) {
console.log("Got data from child: " + data);
});
child.stderr.on('data', function (data) {
console.log('There was an error: ' + data);
});
child.on('exit', function(code) {
console.log('Child process exited with exit code ' + code);
child.stdout.pause();
child.kill();
});
my above code works fine. It gives the result as I want, but I cannot kill (stop) the ffmpeg command. I use the following code to stop the process, but in the background it is still ongoing.
child.kill("SIGTERM");
I also used the following commands: child.kill ('SIGUSR1'); child.kill ("SIGHUP"); child.kill ("SIGINT"); child.kill ('SIGUSR2'); for killing this process, but it does not work.
I am currently forcibly killing the node application in order to stop the ffmpeg command and generate the mp4 file. I do not want this. But I need commands that stop the ffmpeg process and generate the mp4 file without killing the node application.