title: ffmpeg: Render webm from stdin using NodeJS
body: <p>I'm having an issue trying to dump some jpeg frames created on the fly to ffmpeg and NodeJS in order to create a webm video.</p>
  
  <p>The script attempts to do these things:</p>
  
  <ul>
  <li>Fork a new ffmpeg process on initialization</li>
  <li>Render a canvas</li>
  <li>Once the data in canvas is updated, grab JPEG data from it.</li>
  <li>Pipe the JPEG data into the ffmpeg stdin.</li>
  <li>ffmpeg takes care of appending it on a webm video file.</li>
  <li>and this goes forever and ffmpeg should never stop</li>
  </ul>
  
  <p>It should be an always growing video to be broadcast live to all connected clients, but the result that I get is just a single frame webm.</p>
  
  <p><strong>Here is the ffmpeg fork</strong></p>
  
  <pre><code>var args = '-f image2pipe -r 15 -vcodec mjpeg -s 160x144 -i - -f webm -r 15 test.webm'.split(' ');
  var encoder = spawn('ffmpeg', args);
  encoder.stderr.pipe(process.stdout);
  </code></pre>
  
  <p><strong>Here is the canvas update and pipe</strong></p>
  
  <pre><code>theCanvas.on('draw', function () {
      var readStream = self.canvas.jpegStream();
      readStream.pipe(self.encoder.stdin);
  });
  </code></pre>
  
  <p><strong>ffmpeg output</strong></p>
  
  <pre><code>ffmpeg version 1.2.6-7:1.2.6-1~trusty1 Copyright (c) 2000-2014 the FFmpeg developers
    built on Apr 26 2014 18:52:58 with gcc 4.8 (Ubuntu 4.8.2-19ubuntu1)
    configuration: --arch=amd64 --disable-stripping --enable-avresample --enable-pthreads --enable-runtime-cpudetect --extra-version='7:1.2.6-1~trusty1' --libdir=/usr/lib/x86_64-linux-gnu --prefix=/usr --enable-bzlib --enable-libdc1394 --enable-libfreetype --enable-frei0r --enable-gnutls --enable-libgsm --enable-libmp3lame --enable-librtmp --enable-libopencv --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-vaapi --enable-vdpau --enable-libvorbis --enable-libvpx --enable-zlib --enable-gpl --enable-postproc --enable-libcdio --enable-x11grab --enable-libx264 --shlibdir=/usr/lib/x86_64-linux-gnu --enable-shared --disable-static
    libavutil      52. 18.100 / 52. 18.100
    libavcodec     54. 92.100 / 54. 92.100
    libavformat    54. 63.104 / 54. 63.104
    libavdevice    53.  5.103 / 53.  5.103
    libavfilter     3. 42.103 /  3. 42.103
    libswscale      2.  2.100 /  2.  2.100
    libswresample   0. 17.102 /  0. 17.102
    libpostproc    52.  2.100 / 52.  2.100
  [image2pipe @ 0xee0740] Estimating duration from bitrate, this may be inaccurate
  Input #0, image2pipe, from 'pipe:':
    Duration: N/A, bitrate: N/A
      Stream #0:0: Video: mjpeg, yuvj420p, 160x144 [SAR 1:1 DAR 10:9], 15 tbr, 15 tbn, 15 tbc
  [libvpx @ 0xec5d00] v1.3.0
  Output #0, webm, to 'test.webm':
    Metadata:
      encoder         : Lavf54.63.104
      Stream #0:0: Video: vp8, yuv420p, 160x144 [SAR 1:1 DAR 10:9], q=-1--1, 200 kb/s, 1k tbn, 15 tbc
  Stream mapping:
    Stream #0:0 -&gt; #0:0 (mjpeg -&gt; libvpx)
  pipe:: Input/output error
  frame=    1 fps=0.0 q=0.0 Lsize=      12kB time=00:00:00.06 bitrate=1441.1kbits/s    
  video:11kB audio:0kB subtitle:0 global headers:0kB muxing overhead 4.195804%
  </code></pre>
  
  <p>What can I do?</p>
  
  <p>Thanks,
  Vinicius</p>