【问题标题】:Pipe between two child processes in Node.js?Node.js 中两个子进程之间的管道?
【发布时间】:2014-06-20 18:54:47
【问题描述】:

我正在尝试使用带有 Node.js 的 FFmpeg 捕获视频,并通过 websockets 将其发送到浏览器以使用 MediaSource API 播放。到目前为止,我在 Firefox 中有效,但在 Chrome 中无法正确解码。显然,从阅读this question 开始,我需要使用 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
});

显然我没有正确地管道它,我不确定我会如何同时包括参数。感谢任何帮助使其正常工作。谢谢!

【问题讨论】:

  • Firefox 中的 MediaSourceAPI 仍处于试验阶段,默认情况下仍未提供。我很惊讶它直接在 Firefox 中工作。

标签: javascript node.js ffmpeg child-process media-source


【解决方案1】:

sample_muxer 程序将 -i 参数作为文件名。它无法将视频数据作为标准输入读取。要查看错误,您应该将错误流从 sample_muxer 发送到错误日志文件。

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。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-06-18
    • 1970-01-01
    • 1970-01-01
    • 2011-10-16
    • 1970-01-01
    • 2011-05-17
    相关资源
    最近更新 更多