1

我正在尝试使用带有 Node.js 的 FFmpeg 捕获视频,并通过 websockets 将其发送到浏览器以使用 MediaSource API 播放。到目前为止,我在 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
});

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

4

1 回答 1

2

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。

于 2014-05-04T13:25:46.500 回答