SamuelScheit / puppeteer-stream

A Library for puppeteer to retrieve audio and/or video streams
MIT License
357 stars 114 forks source link

Unable to increase video quality #162

Open theorchids opened 4 months ago

theorchids commented 4 months ago

Can someone help me with it, video quality is very low & file size is low (< 250 kb) Here is my code

  const file = fs.createWriteStream(`./videos/vid-${new Date().getMilliseconds()}.webm`);
  const browser = await launch({
    executablePath: "C:/Program Files/Google/Chrome/Application/chrome.exe",
    args: ["--autoplay-policy=no-user-gesture-required"],
    defaultViewport: {
      width: 1536,
      height: 703,
    },
    headless: "new",
  });

  const page = await browser.newPage();
  await page.goto("http://localhost:3000?capture=true");
  const stream = await getStream(page, {
    audio: true,
    video: true,
    // bitsPerSecond: 100000000,
    videoConstraints: {
      mandatory: {
        width: 1536,
        height: 703,
        frameRate: 60,
        facingMode: "environment",
        advanced: [{ width: 1920, height: 1280 }, { aspectRatio: 1.333 }],
      },
    },
  });
  const element = await page.waitForSelector(".playBtn");

  element?.click();
  stream.pipe(file);
  setTimeout(async () => {
    await stream.destroy();
    file.close();
    console.log("finished");

    await browser.close();
    (await wss).close();
  }, 1000 * 10);
}
JasonOneYuan commented 3 months ago

Same problem. Is this a bug or somewhere setting problem?

JOEMN96 commented 3 months ago

Same issue, Anyone have any fixes ?

kelly-parrot commented 2 weeks ago

Try passing your constraints directly in video rather than videoConstraints. Just like in getUserMedia (which this ultimately uses).