我正在尝试使用带有 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
});
显然我没有正确地管道它,我不确定在包括论点的同时我会如何。感谢任何帮助使其正常工作。谢谢!