title: NodeJS - piping multiple FFMPEG processes
body: <p>I am trying to programm an converter which can take any video source and convert it to mp3. The mp3 should be saved on my hard drive, or in an buffer to send it via telegram.</p>
  
  <p>It works good so far, the only problem I am facing is that it can only take one video at a time, and I don't know why.</p>
  
  <pre><code>// IMPORTS
  var fs = require('fs');
  var https = require('https');
  var child_process = require('child_process');
  
  // EVENTEMITER (Not used so far)
  var util = require('util');
  var EventEmitter = require('events').EventEmitter;
  
  
  // STREAMHANDLER
  var StreamHandler = function(url, name){
  
      // VARIABLES
      self = this;
      this.url = url;
      this.name = name;
  
      // CREATE FFMPEG PROCESS
      var spawn = child_process.spawn;
      var args = ['-i', 'pipe:0', '-f', 'mp3', '-ac', '2', '-ab', '128k', '-acodec', 'libmp3lame', 'pipe:1'];
      this.ffmpeg = spawn('ffmpeg', args);
  
      // GRAB STREAM
      https.get(url, function(res) {
          res.pipe(self.ffmpeg.stdin);
      });
  
      // WRITE TO FILE
      this.ffmpeg.stdout.pipe(fs.createWriteStream(name));
  
      //DEBUG
      this.ffmpeg.stdout.on("data", function (data) {
         console.error(self.name);
      });
  }
  
  util.inherits(StreamHandler, EventEmitter);
  
  
  // TESTING
  var test1 = new StreamHandler(vidUrl, "test1.mp3");
  test1.ffmpeg.on("exit", function (code, name, signal) {
      console.log("Finished: " + test1.name);
  });
  
  var test2 = new StreamHandler(vidUrl, "test2.mp3");
  test2.ffmpeg.on("exit", function (code, name, signal) {
      console.log("Finished: " + test2.name);
  });
  </code></pre>
  
  <p>It skips test1.mp3 and only converts test2.mp3, but 2 ffmpeg processes were created:
  <a href="https://i.stack.imgur.com/29Rcd.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/29Rcd.png" alt="enter image description here"></a></p>
  
  <p>After test2.mp3 is converted the other ffmpeg thread stays open, but does nothing, and the node program gets stuck waiting (i guess so) for it to send something.</p>
  
  <p>I hope someone can help me :)</p>