[英]Pipe between two child processes in Node.js?
我正在嘗試使用FFmpeg和Node.js捕獲視頻,並通過websocket將其發送到瀏覽器以使用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
});
顯然,我沒有正確地傳遞它,也不確定要如何包含這些參數。 感謝任何幫助使此工作正常進行。 謝謝!
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。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.