节点木偶流不录制音频 [英] Node puppeteer stream not recording audio

查看:52
本文介绍了节点木偶流不录制音频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 puppeteer 流录制视频和音频,但它只将视频写入输出文件:

I'm trying to record video and audio using puppeteer stream, but it's getting written only the video to the output file:

async function videoRecorder() {
  require("puppeteer-stream");
  const puppeteer = require("puppeteer");
  const fs = require("fs");

  const filename = `./recordings/test.mp4`;

  const file = fs.createWriteStream(filename);

  const browser = await puppeteer.launch({
    executablePath:
      "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
    headless: true,
    defaultViewport: null,
    devtools: false,
    args: [
      "--window-size=1920,1080",
      "--window-position=1921,0",
      "--autoplay-policy=no-user-gesture-required",
    ],
    ignoreDefaultArgs: ["--mute-audio"],
  });

  const page = await browser.newPage();

  await page.goto(pathToPageWithVideo, {
    waitUntil: "load",
  });

  const stream = await page.getStream({
    audio: true,
    video: true,
  });

  stream.pipe(file);

  setTimeout(async () => {
    await stream.destroy();
    file.close();
    console.log("finished");
  }, 10000);
}

我尝试了许多其他录制视频和音频的方法,但这是我最接近的一种,因为我的主要目的是只获取音频,所以我愿意接受更多建议.

I've tried many other ways of recording video and audio but this is the one I got closer, since my main purpose is to get the audio only, I'm open to more suggestions.

谢谢

推荐答案

通过另存为 .webm 而不是 .mp4 解决.

Solved by saving as .webm instead of .mp4.

参考:https://github.com/Flam3rboy/puppeteer-stream/issues/1

这篇关于节点木偶流不录制音频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆