chrome.desktopCapture - can't record both system audio and microphone?

倖福魔咒の 提交于 2019-12-24 01:37:08

问题


I've built a Chrome extension that captures screen activity and microphone input and outputs a video file. Since chrome.desktopCapture can't record audio input alongside screen capture, I'm getting the mic in its own, separate stream. So:

//get screen stream
chrome.desktopCapture.chooseDesktopMedia(['screen'], null, (stream_id, opts) => {
    let constraints = {video: mandatory: {
        chromeMediaSource: 'desktop',
        chromeMediaSourceId: stream_id
    }};
    navigator.mediaDevices.getUserMedia(constraints).then((stream) => {
        video_stream = stream;
    });
});

//get mic stream
navigator.mediaDevices.getUserMedia({audio: true}).then((stream) => {
    audio_stream = stream;
});

Then, later, when I've got both streams, before I start recording I merge them by creating a master stream and add the respective tracks from the separate video and audio streams to it.

let master_stream = new MediaStream(video_stream);
master_stream.addTrack(audio_stream.getTracks()[0]);

And ultimately, when I end up with a video file, this works GREAT. I get screen and mic.

Question: Why does this technique NOT work if I ask Chrome to ALSO record system sound?

So if I change ['screen'] to ['screen', 'audio'], with everything else the same, I end up with no mic in the resultant video.

If I output getTracks() on master_stream, here's what I get:

Array(3)
    0: MediaStreamTrack {kind: "audio", id: "9ee3ee33-73ee-41e4-957c-d6fd3aaada43", label: "System Audio", enabled: true, muted: false, …}
    1: MediaStreamTrack {kind: "audio", id: "ab2429a1-7f75-48f2-9ee1-6a4bfd7ca942", label: "Default - Microphone (Samson Meteor Mic) (17a0:0310)", enabled: true, muted: false, …}
    2: MediaStreamTrack {kind: "video", id: "4ecb1929-31d0-4a79-8cbc-1a8759323c3b", label: "screen:0:0", enabled: true, muted: false, …}

I can't see an obvious cause as to why adding system audio kills mic audio in the resultant output. Anyone any ideas?

来源:https://stackoverflow.com/questions/51042895/chrome-desktopcapture-cant-record-both-system-audio-and-microphone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!