playwright/utils/video_stress.js
Dmitry Gozman eca82eee4a
fix(video): reduce buffering in ffmpeg, avoid overbooking cpu (#8786)
This is an attempt to improve video performance when encoding
does not keep up with frames. This situation can be reproduced
by running multiple encoders at the same time.

Added `utils/video_stress.js` to manually reproduce this issue.

Observing ffmpeg logs, it does not do any encoding initially and
instead does "input analysis / probing" that detects fps and other
parameters. By the time it starts encoding (launches vpx and creates
the video file), we already have many frames in the buffer.
Reducing probing helps:
`-avioflags direct -fpsprobesize 0 -probesize 32 -analyzeduration 0`

Another issue observed is questionable default `-threads` value.
We compile without threads support, so logs say "using emulated threads".
For some reason, setting explicit `-threads 1` (or any other value)
makes it better when cpu is loaded.
2021-09-09 12:41:06 -07:00

25 lines
840 B
JavaScript

const { chromium } = require('..');
const videoDir = require('path').join(__dirname, '..', '.tmp');
async function go(browser) {
console.log(`Creating context`);
const context = await browser.newContext({ recordVideo: { dir: videoDir } });
const page = await context.newPage();
await page.goto('https://webkit.org/blog-files/3d-transforms/poster-circle.html');
await page.waitForTimeout(10000);
const time = Date.now();
await context.close();
console.log(`Closing context for ${Date.now() - time}ms`);
const video = await page.video();
console.log(`Recorded video at ${await video.path()}`);
}
(async () => {
const browser = await chromium.launch({ headless: true });
const promises = [];
for (let i = 0; i < 10; i++)
promises.push(go(browser));
await Promise.all(promises);
await browser.close();
})();