因此,我使用 FFMPEG 在视频上应用多个覆盖,在 Windows 上,它对于各种大小和数量的覆盖始终能正常工作,但在 MAC 或 Linux 上,它会因重新初始化过滤器而产生错误。
假设我有一个 190MB 的视频和大约 182 个覆盖 PNG,它们将使用 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]';
}
}
我正在使用上述函数创建一个 filter_complex。
然后像这样运行 FFMPEG 命令:
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 () => {
“你可以忽略插座发射”
这在 Windows 上有效。但在 OSX 或 Linux 上处理时,会出现以下错误:
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)