You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Node 18/20在Google Cloud Functions中调用ffprobe报错求助

问题:Google Cloud Functions Node.js 18/20下ffprobe获取视频时长失败

我在Google Cloud Functions中使用以下代码获取视频时长,该代码在Node.js 16环境下正常运行,但升级至Node.js 18或20后出现问题:

const ffmpeg = require("fluent-ffmpeg");

// Following is inside a .https.onRequest Google Cloud function with enough memory

try {
  const duration = new Promise((resolve, reject) => {
  ffmpeg.ffprobe(videoUrl, async (err, metadata) => {
    if (err) {
      if (res.headersSent) {
        console.error("Response already sent");
        return;
      } else {
        console.log("Metadata:", metadata);
        console.log("err: " + err);
        res.status(400).send("Error getting video metadata");
        return;
      }
    }
  const duration = metadata.format.duration;
  console.log("video duration in second: " + duration);
  resolve(duration);
  });
});
  videoDuration = await duration;
} catch (err) {
  console.log(err);
  throw err;
}

升级后首先出现ffprobe not found错误,手动设置ffprobe路径后又触发ffprobe was killed with signal SIGSEGV错误。我尝试了多种解决方案:从ffbinaries官网手动下载ffprobe、使用@ffprobe-installer/ffprobe或ffprobe-static包、将ffprobe下载至Google Cloud临时目录并修改权限,但均未解决问题。

由于Google将于2024年1月31日停止支持Node.js 16,我急需完成版本升级,目前未找到有效解决办法。

更新记录

  • 2023年11月26日:GCP Functions Node.js 16运行时基于Ubuntu 18.04且预装FFMpeg,而Node.js 18/20运行时基于Ubuntu 22.04,谷歌未预装FFMpeg。
  • 2024年1月10日:谷歌已在最新版本中重新添加ffmpeg,问题现已解决。

内容的提问来源于stack exchange,提问作者user20206929

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.05 15:17:48