title: spawn ffmpeg in nodejs and pipe to express's response
body: <p>i am spawning ffmpeg and pipe it's output (the video stream i want) to express's response object like this:</p>
  
  <pre><code>app.get('/stream', (req, res) =&gt; {
      let _url = req.query.url;
  
      if(_url){   
  
          res.writeHead(200, {
              'Access-Control-Allow-Origin': '*',
              'Connection': 'Keep-Alive',
              'Content-Type': 'video/mp4'
          });
  
          // transcode rtsp input from ip-cam to mp4 file format (video: h.264 | audio: aac)
          let ffmpeg = child_process.spawn("ffmpeg",[
              "-probesize","2147483647",
              "-analyzeduration","2147483647",
              "-i", _url,
              "-vcodec","copy",
              "-f", "mp4",            
              "-movflags","frag_keyframe+empty_moov+faststart",
              "-frag_duration","3600",
              "pipe:1"              
          ]);         
  
  
          // redirect transcoded ip-cam stream to http response
          ffmpeg.stdout.pipe(res);
  
          // error logging
          ffmpeg.stderr.setEncoding('utf8');      
          ffmpeg.stderr.on('data', (data) =&gt; {
              console.log(data);
          });
      }
      else{
          res.end();
      }
  </code></pre>
  
  <p>so far it's working like a charm.
  however somewhere in there seems to be a cap. i can get only 3 streams running at the same time. when a 4th spawn occurs the 4th thread will block one of the cpu cores:</p>
  
  <p><a href="https://i.stack.imgur.com/lXkai.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lXkai.png" alt="htop of my raspberry pi 3"></a></p>
  
  <p>and naturally the 4th stream does not reach the browser.. 
  has somebody any idea of what am i missing?</p>
  
  <p>EDIT: it's not tied to the fact that i am running the nodejs project on the raspberry pi. it also behaves the same way on my windows 10 machine</p>