我正在尝试在 linux 服务器上构建一个服务来录制带有声音的网络浏览器的视频。
第一步我用下面的源代码(使用xvfb、puppeteer和ffmpeg)成功录制。
但是,当我同时使用不同的进程(不同的网站)进行录制时,音频会在进程之间混淆。我知道这是因为我为所有进程使用了相同的默认音频输出。
问题是:如何录制浏览器的声音不会在不同进程之间混淆?
我的示例代码如下:
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();