ffmpeg:使用NodeJS从stdin渲染webm

我有一个问题试图转储一些飞行中创build的帧到ffmpeg和NodeJS为了创build一个webmvideo。

脚本试图做这些事情:

  • 在初始化时新build一个ffmpeg进程
  • 渲染一个canvas
  • 一旦更新了canvas中的数据,就从中抓取JPEG数据。
  • 将JPEG数据传送到ffmpeg标准input。
  • ffmpeg负责将其附加到webmvideo文件中。
  • 这永远不会停止,而且ffmpeg永远不会停止

它应该是一个不断增长的video直播给所有连接的客户端,但我得到的结果只是一个单一的框架webm。

这是ffmpeg的叉子

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); 

这是canvas更新和pipe道

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

ffmpeg输出

 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% 

我能做什么?

谢谢,Vinicius

第一帧数据发送后,pipe道正在closures。 我一直有一个类似的问题,这使我的一部分来修复它。 希望这有帮助,我还不迟。

 theCanvas.on('draw', function () { var readStream = self.canvas.jpegStream(); readStream.pipe(self.encoder.stdin, {end:false}); });