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

FFmpeg filter_complex多Overlay滤镜在Windows正常,Linux/macOS执行报错的问题求助

FFmpeg filter_complex多Overlay滤镜在Windows正常,Linux/macOS执行报错的问题求助

各位大佬好,我最近碰到一个跨平台的FFmpeg问题,折腾好久都没解决,来求助大家!

情况是这样的:我用Node.js的fluent-ffmpeg库,通过filter_complex给视频叠加一批带时间范围的PNG(类似动态字幕或水印),这套逻辑在Windows上跑完全没问题——不管视频多大、叠加多少个PNG都能顺利生成输出视频。但到了macOS或者Linux环境下,只要叠加的PNG数量较多(比如这次测试的182个),就会直接报错,提示滤镜重初始化失败。

具体实现逻辑

我先通过循环生成filter_complex的字符串,每个PNG对应一个overlay滤镜,并且通过enable='between(t,${start},${end})'控制它的显示时间段:

for (let i = 0; i < pngPaths.length; i++) {
  const start = Number(transcriptions[i].start).toFixed(2);
  const end = Number(transcriptions[i].end).toFixed(2);
  const overlayX = '0';
  const overlayY = `0`;

  filterComplex += `[${i + 1}:v] overlay=${overlayX}:${overlayY}:enable='between(t,${start},${end})'`;
  if (i < pngPaths.length - 1) {
    filterComplex += '[vout];[vout]';
  }
}

接着构建FFmpeg命令,先添加主视频输入,再逐个添加PNG输入,最后应用复杂滤镜并输出:

const outputPath = path.join(__dirname, '..') + `/projects/${project.originalVideoFile}-output.mp4`;
this.appGateway.sendProgress(JSON.stringify(userId), 'progress', 0);

return new Promise((resolve, reject) => {
  const ffmpegCommand = ffmpeg();
  // 添加视频主输入
  ffmpegCommand.input(videoPath);
  // 添加所有PNG输入
  for (const pngPath of pngPaths) {
    ffmpegCommand.input(pngPath);
  }
  // 如果是免费订阅用户,额外添加水印
  if (project?.user?.subscription?.plan?.id === 1) {
    ffmpegCommand.input('watermark.png');
  }

  ffmpegCommand
    .complexFilter(filterComplex)
    .outputOptions('-c:v', 'libx264')
    .output(outputPath)
    .on('progress', (progress) => {
      this.appGateway.sendProgress(
        JSON.stringify(userId),
        'progress',
        Math.round(progress.percent),
      );
    })
    .on('end', async () => {
      // 这里的socket通知逻辑可以忽略
    })
    .on('error', reject);
});

报错信息(macOS环境下)

执行后FFmpeg会输出一堆流映射信息,然后抛出错误:

Stream #95:0 (png) -> overlay (graph 0)
...(中间省略大量流映射信息)
Stream #182:0 (png) -> overlay (graph 0)
overlay:default (graph 0) -> Stream #0:0 (libx264)
Stream #0:1 -> #0:1 (aac (native) -> aac (native))
Press [q] to stop, [?] for help

[auto_scale_47 @ 0x60000182bbd0] Failed to configure output pad on auto_scale_47
Error reinitializing filters!
Failed to inject frame into filter network: Resource temporarily unavailable
Error while processing the decoded data for stream #182:0
[aac @ 0x13c063f40] Qavg: 325.486
[aac @ 0x13c063f40] 2 frames left in the queue on closing
Conversion failed!

/Users/surajkadam/Desktop/12/subtitleo-server/node_modules/fluent-ffmpeg/lib/processor.js:182
handleExit(new Error('ffmpeg exited with code ' + code));
^
Error: ffmpeg exited with code 1: Conversion failed!
    at ChildProcess.<anonymous> (/Users/surajkadam/Desktop/12/subtitleo-server/node_modules/fluent-ffmpeg/lib/processor.js:182:22)
    at ChildProcess.emit (node:events:513:28)
    at Process.ChildProcess._handle.onexit (node:internal/child_process:291:12)

我怀疑是不是滤镜链的写法有问题?或者Linux/macOS下FFmpeg的资源限制和Windows不同?有没有大佬遇到过类似的问题,或者能给点排查方向?

备注:内容来源于stack exchange,提问作者Hassan Aftab

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.21 08:05:31