title: How to Kill ffmpeg process in node.js
body: <p><strong>I am using node.js code that convert Axis Ipcamera live stream into mp4 using FFMPEG</strong></p>
  
  <pre><code> 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);
  
          });     
  
          //    here generate events for listen child process (works properly)
      // Listen for incoming(stdout) data
      child.stdout.on('data', function (data) {
          console.log("Got data from child: " + data);
      });
  
      // Listen for any errors:
      child.stderr.on('data', function (data) {
          console.log('There was an error: ' + data);
      });
  
      // Listen for exit event
      child.on('exit', function(code) {
          console.log('Child process exited with exit code ' + code);
          child.stdout.pause();
          child.kill();
      });
  </code></pre>
  
  <p>my above code works perfectly. It gives the output as I want, but I am not able to kill(stop) the ffmpeg command. I am using the code below for stopping the process, but in background it still continues.</p>
  
  <pre><code>child.kill("SIGTERM"); 
  </code></pre>
  
  <p>I also used following commands :  child.kill('SIGUSR1'); child.kill("SIGHUP"); child.kill("SIGINT");child.kill('SIGUSR2'); for killing this process but it not works.</p>
  
  <p>Currently I forcefully kill the node application to stop ffmpeg command and generate mp4 file. I do not want this.
  But I want commands that stop ffmpeg process and generate mp4 file, without killing the node application.</p>