alpecca
alpecca

Reputation: 1

The System Audio not included when recording screen using tab capture api

I am working on a chrome extension that let user record their current tab video + the current system audio for example playing a music on the tab. I read the docs on the web about preserve audio on tab capture api and the audio constraint to set to be true

chrome.tabCapture.capture({
        video: true,
        audio: true,
const stream = await new Promise<MediaStream | null>((resolve, reject) => {
    chrome.tabCapture.capture({
        video: true,
        audio: true,
        videoConstraints: {
            
            mandatory: {
                minFrameRate: 60,
                maxFrameRate: 60,
                minWidth: 1920, 
                minHeight: 1080, 
                maxWidth: 1920,
                maxHeight: 1080,
            }
        }
    }, (stream: MediaStream | null) => {
        if (chrome.runtime.lastError) {
            return reject(new Error(chrome.runtime.lastError.message));
        }
        resolve(stream);
    });
});

In the above code, when I set the audio to be true and try to record the screen, the final output doesn't contain any audio.

Here is the Media Recorder values :-

const recorder = new MediaRecorder(stream, {
            mimeType: 'video/webm;codecs=H264',
            videoBitsPerSecond: 8000000
        });

        recorder.ondataavailable = (e: BlobEvent) => {
            socketRef.send(e.data)
           
        }
  
        recorder.start(2000);

And also my ffmpeg in the backend to handle the incoming stream :-

command = [
        'ffmpeg', 
        '-y',
        '-i', 
        '-', 
        '-codec:v', 
        'copy', 
        '-codec:a', 
        'copy', 
        '-y',
        '-f', 'mp4',
        recordingFile,
        # "-"
        # f'output{queueNumber}.mp4',
    ]

Any help would be greatly appreciated :)

Upvotes: 0

Views: 52

Answers (0)

Related Questions