在Node.js中的两个subprocess之间的pipe道?

我试图用Node.js使用FFmpeg捕捉video,并通过使用MediaSource API播放的websockets将其发送到浏览器。 到目前为止,我在Firefox中工作,但不能在Chrome中正确解码。 显然,从阅读这个问题我需要使用sample_muxer程序来确保每个“集群”以关键帧开始。

以下是我正在使用的代码:

var ffmpeg = child_process.spawn("ffmpeg",[ "-y", "-r", "30", "-f","dshow", "-i","video=FFsource:audio=Stereo Mix (Realtek High Definition Audio)", "-vcodec", "libvpx", "-acodec", "libvorbis", "-threads", "0", "-b:v", "3300k", "-keyint_min", "150", "-g", "150", "-f", "webm", "-" // Output to STDOUT ]); ffmpeg.stdout.on('data', function(data) { //socket.send(data); // Just sending the FFmpeg clusters works with Firefox's // implementation of the MediaSource API. No joy with Chrome. // - - - This is the part that doesn't work - - - var muxer = child_process.spawn("sample_muxer",[ "-i", data, // This isn't correct... "-o", "-" // Output to STDOUT ]); muxer.stdout.on('data', function(muxdata) { socket.send(muxdata); // Send the cluster }); }); ffmpeg.stderr.on('data', function (data) { console.log("" + data); // Output to console }); 

显然我不是正确的pipe道,我不确定我将如何还包括论据。 感谢任何帮助获得这项工作。 谢谢!

sample_muxer程序以-i参数作为文件的名称。 它不能读取video数据作为标准input。 要查看错误,您应该将来自sample_muxer的错误stream发送到错误日志文件。

 var muxer = child_process.spawn("sample_muxer",[ "-i", data, // This isn't correct... "-o", "-" // Output to STDOUT ]); 

此代码将导致错误在https://code.google.com/p/webm/source/browse/sample_muxer.cpp?repo=libwebm#240

您可以尝试从ffmpeg写入文件,然后从sample_muxer读取该文件。 一旦工作,尝试用FIFO文件将数据从ffmpeg传送到sample_muxer。

Interesting Posts