Headless recording
SaadAI2 opened this issue · comments
Is it possible to record audio and video in headless mode? If not, what is the optimal platform for deploying an application that requires a headful browser with audio and video capabilities?
I managed to record video in headless mode with the following script.
Not sure if it records audio.
const { launch, getStream } = require("puppeteer-stream");
const Xvfb = require('xvfb');
const file = fs.createWriteStream(`./example.mp4`);
var xvfb = new Xvfb({
silent: true,
xvfb_args: ["-screen", "0", '1920x1080x30', "-ac"],
});
xvfb.start((err) => { if (err) console.error(err) })
const browser = await launch({
executablePath: 'google-chrome',
headless: false,
defaultViewport: null,
protocolTimeout: 30000,
args: ['--no-sandbox', '--start-fullscreen', '--display=' + xvfb._display,
'--window-size=1920,1080',],
});
const page = await browser.newPage();
const stream = await getStream(page, { audio: true, video: true });
stream.pipe(file);
// ...
await stream.destroy();
file.close();
xvfb.stop();
puppeteer-stream could record audio and video at the same time, even in headless mode. i've already used it in production
did you guys tried it on k8s clusters? i mean in a pod
by adding this cli argument to the browser args, --headless=new
@SamuelScheit okay. I deleted my post to provide the answer.
These settings worked for me:
const browser = await launch({
executablePath: executablePath(),
defaultViewport: {
width: 1080,
height: 1920,
},
args: [
'--headless=new',
'--no-sandbox',
'--window-size=1080,1920',
'--disable-setuid-sandbox',
'--ozone-override-screen-size=1080,1920',
],
});
@xephtar tested in GCP. Worked well.
Minimum instance requirements - 12-16Gib and 2 CPUs.
On 4Gib and 8Gib, the video had cracks and freezes. Haven't tested with 12Gib, though. But I assume it'd be okay. Went with 16Gib to be safe.
I managed to record video in headless mode with the following script. Not sure if it records audio.
const { launch, getStream } = require("puppeteer-stream"); const Xvfb = require('xvfb'); const file = fs.createWriteStream(`./example.mp4`); var xvfb = new Xvfb({ silent: true, xvfb_args: ["-screen", "0", '1920x1080x30', "-ac"], }); xvfb.start((err) => { if (err) console.error(err) }) const browser = await launch({ executablePath: 'google-chrome', headless: false, defaultViewport: null, protocolTimeout: 30000, args: ['--no-sandbox', '--start-fullscreen', '--display=' + xvfb._display, '--window-size=1920,1080',], }); const page = await browser.newPage(); const stream = await getStream(page, { audio: true, video: true }); stream.pipe(file); // ... await stream.destroy(); file.close(); xvfb.stop();
This is working for me on Linux server .
defaultViewport: {
width: 1080,
height: 1920,
},
args: [
'--headless=new',
'--no-sandbox',
'--window-size=1080,1920',
'--disable-setuid-sandbox',
'--ozone-override-screen-size=1080,1920',
],
Worked for me