Q: ffmpeg: Render webm from stdin using NodeJS 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.
The script attempts to do these things:


*

*Fork a new ffmpeg process on initialization

*Render a canvas

*Once the data in canvas is updated, grab JPEG data from it.

*Pipe the JPEG data into the ffmpeg stdin.

*ffmpeg takes care of appending it on a webm video file.

*and this goes forever and ffmpeg should never stop


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.
Here is the ffmpeg fork
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);

Here is the canvas update and pipe
theCanvas.on('draw', function () {
    var readStream = self.canvas.jpegStream();
    readStream.pipe(self.encoder.stdin);
});

ffmpeg output
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 -> #0:0 (mjpeg -> 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%

What can I do?
Thanks,
Vinicius

A: The pipe is being closed after the first frame of data is sent. I have been having a similar problem and this got me part way to fixing it. Hope this helps and that I'm not too late.   
theCanvas.on('draw', function () {
    var readStream = self.canvas.jpegStream();
    readStream.pipe(self.encoder.stdin, {end:false});
});

