title: node.js ffmpeg spawn child_process unexpected data output
body: <p><br />
  I'm rather new to backend stuff, so please excuse, if my question is trivial.<br />
  For an Intranet project, I want to present a video element in a webpage (React, HLS.js Player).<br />
  The video sources are mpeg-ts streams delivered as udp multicast.<br />
  A small node.js / express server should handle the ffmpeg commands, to transcode the multicast to hls to display them in a browser.<br />
  <br />
  Problem is the Output:<br />
  The output is emitted on stderr... even the process is working as expected.<br />
  Here is the respective code I wrote for transcoding so far:</p>
  <pre><code>const express = require(&quot;express&quot;);
  const { spawn, exec } = require(&quot;child_process&quot;);
  const process = require(&quot;process&quot;)
  
  let ls;
  
  const app = express();
  
  app.get('/cam/:source', (body) =&gt; {
      const cam = body.params.source;
      console.log(cam);
  
      let source = &quot;udp://239.1.1.1:4444&quot;;
      let stream = &quot;/var/www/html/streams/tmp/cam1.m3u8&quot;
  
  
      stream = spawn(&quot;ffmpeg&quot;, [&quot;-re&quot;, &quot;-i&quot;, source, &quot;-c:v&quot;, &quot;libx264&quot;, &quot;-crf&quot;, &quot;21&quot;, &quot;-preset&quot;, &quot;veryfast&quot;, &quot;-c:a&quot;, &quot;aac&quot;, &quot;-b:a&quot;, &quot;128k&quot;, &quot;-ac&quot;, &quot;2&quot;, &quot;-f&quot;, &quot;hls&quot;, &quot;-hls_list_size&quot;, &quot;5&quot;, &quot;-hls_flags&quot;, &quot;delete_segments&quot;, stream], {detached: true});
  
      stream.stdout.on(&quot;data&quot;, data =&gt; {
          console.log(`stdout: ${data}`);
      });
  
      stream.stderr.on(&quot;data&quot;, data =&gt; {
          console.log(`stderr: ${data}`);
      });
  
      stream.on(&quot;error&quot;, error =&gt; {
          console.log(`error: ${error.message}`);
      });
  
      stream.on(&quot;close&quot;, code =&gt; {
          console.log(`child process exited with code ${code}`);
      });
  })
  
  app.listen(5000, ()=&gt; {
      console.log('Listening');
  })
  </code></pre>
  <p>This is maybe only cosmetics, but it makes me wondering.<br />
  Here is the terminal output:</p>
  <pre><code>[nodemon] starting `node server.js`
  Listening
  camera stream reloaded
  stderr: ffmpeg version 4.3.2-0+deb11u1ubuntu1 Copyright (c) 2000-2021 the FFmpeg developers
    built with gcc 10 (Ubuntu 10.2.1-20ubuntu1)
  
    --shortend--
  
  
  pid:  4206
  stderr: frame=    8 fps=0.0 q=0.0 size=N/A time=00:00:00.46 bitrate=N/A speed=0.931x    
  pid:  4206
  stderr: frame=   21 fps= 21 q=26.0 size=N/A time=00:00:00.96 bitrate=N/A speed=0.95x    
  pid:  4206
  stderr: frame=   33 fps= 22 q=26.0 size=N/A time=00:00:01.49 bitrate=N/A speed=0.982x    
  pid:  4206
  stderr: frame=   46 fps= 23 q=26.0 size=N/A time=00:00:02.00 bitrate=N/A speed=0.989x    
  pid:  4206
  stderr: frame=   58 fps= 23 q=26.0 size=N/A time=00:00:02.49 bitrate=N/A speed=0.986x    
  pid:  4206
  </code></pre>
  <p>and so on...<br />
  <br />
  Any helpful information would be highly appreciated!<br />
  Many thanks in advance</p>