When I try to capture a window in Electron I get a very laggy (around 15fps) and high latency result, but when I capture the entire screen it works just fine.
Maybe it is because I'm running getSource()
under createWindow()
, but again screen capture works just fine.
I'm using basically the same code in https://www.electronjs.org/docs/latest/api/desktop-capturer
function createWindow() {
...
function getSource() {
desktopCapturer.getSources({ types: ["window", "screen"] }).then(async (sources) => {
for (const source of sources) {
if (source.name.toLowerCase().includes("screen 1")) {
// if (source.name === "Screen 1") {
mainWindow.webContents.send("SET_SOURCE", source.id);
return;
}
console.log(source.name);
}
});
}
getSource();
}
I already tried adding frame rate limitations:
...
video: {
mandatory: {
chromeMediaSource: "desktop",
chromeMediaSourceId: sourceId,
minFrameRate: 30, // here
maxFrameRate: 60,
minWidth: 1280,
maxWidth: 1280,
minHeight: 720,
maxHeight: 720,
},
...