【发布时间】: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