SamuelScheit / puppeteer-stream

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

webm is of o bytes after running below code #99

Closed sagarrajput closed 1 year ago

sagarrajput commented 1 year ago

I'm trying to run below code, it runs however returns 0 bytes szie file test_recording.webm @SamuelScheit


const { executablePath } = require('puppeteer')
const fs = require("fs");
const { exec } = require("child_process");
const file = fs.createWriteStream(__dirname + "/test_recording.webm");
async function test() {
    const browser = await launch({
        executablePath: '/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome',
        defaultViewport: {
            width: 1920,
            height: 1080,
        },
});
const page = await browser.newPage();
await page.goto("https://www.youtube.com/watch?v=dQw4w9WgXcQ");
const stream = await getStream(page, { audio: true, video: true, frameSize: 1000 });
console.log("recording");
// this will pipe the stream to ffmpeg and convert the webm to mp4 format
const ffmpeg = exec('ffmpeg -y -i - output.mp4');
ffmpeg.stderr.on("data", (chunk) => {
console.log(chunk.toString());
});
stream.pipe(ffmpeg.stdin);

    setTimeout(async () => {
        await stream.destroy();
        ffmpeg.kill("SIGINT");

        console.log("finished");
    }, 1000 * 10);
}
test();
oleghind commented 1 year ago

You are streaming to ffmpeg file output.mp4 instead of test_recording.webm