[FFmpeg-user] FFMPEG filter_complex overlays work well on windows but generates error on Linux and OSX

Suraj Kadam suraj at subtitleo.com
Fri Dec 22 10:13:43 EET 2023


So, I am applying multiple overlays on a video using FFMPEG, on windows it
always works fine for every size and number of overlays, but in case of MAC
or Linux, it generates error for reinitializing filters.

Let's say I have a video of 190MB, and about 182 overlay PNGs which will be
overlayed using filter_complex.

   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]';
    }
  }

I am creating a filter_complex using above function.

And then running FFMPEG command like this:

  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();

  // Add video input
  ffmpegCommand.input(videoPath);

  // Add PNG inputs
  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 () => {


"You can ignore the socket emmisions"

This works will on windows. But when processing on OSX or Linux, it
gives the following error:

Stream #95:0 (png) -> overlay (graph 0)
  Stream #96:0 (png) -> overlay (graph 0)
  Stream #97:0 (png) -> overlay (graph 0)
  Stream #98:0 (png) -> overlay (graph 0)
  Stream #99:0 (png) -> overlay (graph 0)
  Stream #100:0 (png) -> overlay (graph 0)
  Stream #101:0 (png) -> overlay (graph 0)
  Stream #102:0 (png) -> overlay (graph 0)
  Stream #103:0 (png) -> overlay (graph 0)
  Stream #104:0 (png) -> overlay (graph 0)
  Stream #105:0 (png) -> overlay (graph 0)
  Stream #106:0 (png) -> overlay (graph 0)
  Stream #107:0 (png) -> overlay (graph 0)
  Stream #108:0 (png) -> overlay (graph 0)
  Stream #109:0 (png) -> overlay (graph 0)
  Stream #110:0 (png) -> overlay (graph 0)
  Stream #111:0 (png) -> overlay (graph 0)
  Stream #112:0 (png) -> overlay (graph 0)
  Stream #113:0 (png) -> overlay (graph 0)
  Stream #114:0 (png) -> overlay (graph 0)
  Stream #115:0 (png) -> overlay (graph 0)
  Stream #116:0 (png) -> overlay (graph 0)
  Stream #117:0 (png) -> overlay (graph 0)
  Stream #118:0 (png) -> overlay (graph 0)
  Stream #119:0 (png) -> overlay (graph 0)
  Stream #120:0 (png) -> overlay (graph 0)
  Stream #121:0 (png) -> overlay (graph 0)
  Stream #122:0 (png) -> overlay (graph 0)
  Stream #123:0 (png) -> overlay (graph 0)
  Stream #124:0 (png) -> overlay (graph 0)
  Stream #125:0 (png) -> overlay (graph 0)
  Stream #126:0 (png) -> overlay (graph 0)
  Stream #127:0 (png) -> overlay (graph 0)
  Stream #128:0 (png) -> overlay (graph 0)
  Stream #129:0 (png) -> overlay (graph 0)
  Stream #130:0 (png) -> overlay (graph 0)
  Stream #131:0 (png) -> overlay (graph 0)
  Stream #132:0 (png) -> overlay (graph 0)
  Stream #133:0 (png) -> overlay (graph 0)
  Stream #134:0 (png) -> overlay (graph 0)
  Stream #135:0 (png) -> overlay (graph 0)
  Stream #136:0 (png) -> overlay (graph 0)
  Stream #137:0 (png) -> overlay (graph 0)
  Stream #138:0 (png) -> overlay (graph 0)
  Stream #139:0 (png) -> overlay (graph 0)
  Stream #140:0 (png) -> overlay (graph 0)
  Stream #141:0 (png) -> overlay (graph 0)
  Stream #142:0 (png) -> overlay (graph 0)
  Stream #143:0 (png) -> overlay (graph 0)
  Stream #144:0 (png) -> overlay (graph 0)
  Stream #145:0 (png) -> overlay (graph 0)
  Stream #146:0 (png) -> overlay (graph 0)
  Stream #147:0 (png) -> overlay (graph 0)
  Stream #148:0 (png) -> overlay (graph 0)
  Stream #149:0 (png) -> overlay (graph 0)
  Stream #150:0 (png) -> overlay (graph 0)
  Stream #151:0 (png) -> overlay (graph 0)
  Stream #152:0 (png) -> overlay (graph 0)
  Stream #153:0 (png) -> overlay (graph 0)
  Stream #154:0 (png) -> overlay (graph 0)
  Stream #155:0 (png) -> overlay (graph 0)
  Stream #156:0 (png) -> overlay (graph 0)
  Stream #157:0 (png) -> overlay (graph 0)
  Stream #158:0 (png) -> overlay (graph 0)
  Stream #159:0 (png) -> overlay (graph 0)
  Stream #160:0 (png) -> overlay (graph 0)
  Stream #161:0 (png) -> overlay (graph 0)
  Stream #162:0 (png) -> overlay (graph 0)
  Stream #163:0 (png) -> overlay (graph 0)
  Stream #164:0 (png) -> overlay (graph 0)
  Stream #165:0 (png) -> overlay (graph 0)
  Stream #166:0 (png) -> overlay (graph 0)
  Stream #167:0 (png) -> overlay (graph 0)
  Stream #168:0 (png) -> overlay (graph 0)
  Stream #169:0 (png) -> overlay (graph 0)
  Stream #170:0 (png) -> overlay (graph 0)
  Stream #171:0 (png) -> overlay (graph 0)
  Stream #172:0 (png) -> overlay (graph 0)
  Stream #173:0 (png) -> overlay (graph 0)
  Stream #174:0 (png) -> overlay (graph 0)
  Stream #175:0 (png) -> overlay (graph 0)
  Stream #176:0 (png) -> overlay (graph 0)
  Stream #177:0 (png) -> overlay (graph 0)
  Stream #178:0 (png) -> overlay (graph 0)
  Stream #179:0 (png) -> overlay (graph 0)
  Stream #180:0 (png) -> overlay (graph 0)
  Stream #181: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)



I am generating inputs dynamically using node-canvas, those are
typically same (i.e a PNG). This is how we are generating PNG from a
canvas: const buffer = canvas.toBuffer('image/png'); , so as for other
videos its parsing only foe heavy videos, like the one I am using,
it's giving the error. It also says Failed to configure output pad on
auto_scale_47 Error reinitializing filters! Failed to inject frame
into filter network: Resource temporarily unavailable. It maybe a
permission or limit issue? How can I allow FFMPEG to use all
permissions? in MAC and Linux.


More information about the ffmpeg-user mailing list