在电子中,我可以获得MediaStream对象,但是如何将其转换为可读流。 MediaStream没有管道方法,如何读取?
const { desktopCapturer } = require('electron')
desktopCapturer.getSources({ types: ['window', 'screen'] }).then(async sources => {
for (const source of sources) {
if (source.name === 'Electron') {
try {
const stream = await navigator.mediaDevices.getUserMedia({
audio: false,
video: {
mandatory: {
chromeMediaSource: 'desktop',
chromeMediaSourceId: source.id,
}
}
})
handleStream(stream)
} catch (e) {
handleError(e)
}
return
}
}
})
function handleStream (stream) {
// this is the classic usage of MediaStream
//const video = document.querySelector('video')
//video.srcObject = stream
// but I want to do something like this
var fs = require("fs");
var writerStream = fs.createWriteStream('output.mp4');
stream.pipe(writerStream);
}