'Record web browser with sound as a service on linux server with puppeteer
I'm trying to build a service on a linux server to record video a web browser with its sound.
The first step I did with the source code below (using xvfb, puppeteer and ffmpeg) to record successfully.
However when I do a recording with different processes at a same time (different websites) the audio gets mixed up between the processes. I know this is happening because I used the same default audio output for all processes.
The question is: how can I record the browser with sound that doesn't get mixed up between different processes?
My sample code below:
var Xvfb = require('xvfb');
var puppeteer = require('puppeteer');
const { spawn, spawnSync } = require('child_process');
async function record() {
var xvfb = new Xvfb({
displayNum: 99,
reuse: false,
xvfb_args: [
"-screen", "0", "1920x1080x24",
"-ac",
"-nolisten", "tcp",
"-dpi", "96",
"+extension", "RANDR"
]
});
xvfb.startSync();
var browser = await puppeteer.launch({
headless: false,
defaultViewport: null,
ignoreDefaultArgs: [
"--mute-audio",
"--enable-automation"
],
args: [
"--use-fake-ui-for-media-stream",
"--window-size=1920,1080",
"--start-fullscreen"
]
});
const page = await browser.newPage();
var url = "http://www.noiseaddicts.com/free-samples-mp3/?id=2544";
await page.goto(url);
await page.click('span.map_play');
var time = new Date().getTime();
var options = [
"-video_size", "1920x1080",
"-framerate", "30",
"-f", "x11grab",
"-draw_mouse", "0",
"-i", ":99",
"-f", "pulse",
"-ac", "2",
"-i", "1",
"./output" + time + ".mkv"
];
var cmd = 'ffmpeg';
var proc = spawn(cmd, options);
proc.stdout.on('data', function (data) {
console.log(data);
});
proc.stderr.setEncoding("utf8")
proc.stderr.on('data', function (data) {
console.log(data);
});
proc.on('close', async function () {
console.log('finished');
xvfb.stopSync();
});
}
record();
Solution 1:[1]
use puppeteer-stream. and run examples/ffmpeg.js with xfvb-run --auto-servernum node ffmpeg.js you will see the captured output.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Murat Cem YALIN |