2

我想使用 fluent-ffmpeg 模块从 Electron 调用带有复杂过滤器的 ffmpeg,但没有成功。错误'[AVFilterGraph @ 0xb8.......]没有这样的过滤器“初始化复杂过滤器时出错。无效参数”与此问题相同错误:在Android中运行FFmpeg命令,在数组中拆分命令不起作用,但语境不同。

需要什么? 使用 fluent-ffmpeg 运行这个 ffmpeg 命令:

ffmpeg -i safework-background-0.mp4 -i image1.png -i image2.png -i image3.png -filter_complex "[0:v][1:v] 覆盖=1:1:enable='between(t ,5,8.5)' [tmp]; [tmp][2:v] overlay=1:1:enable='between(t,8.5,12)' [tmp]; [tmp][3:v] overlay= 1:1:enable='between(t,12,15)'" test-video-safework3.mp4

它使用复杂的过滤器将三个图像依次叠加在视频上并导出一个新视频。

什么不起作用? 显然,fluent-ffmpeg 扼流了复杂过滤器所需的引号,这是我的结论(与上面的 Android 变体问题相同)。

在 Electron 中没有 fluent-ffmpeg 有什么用? 你可以猜到我不得不求助于直接调用 ffmpeg。为了帮助其他人,以下命令将输入​​和输出视频文件名参数化,转换为 Electron 为:

  var spawn = require('child_process').spawn
  var fargs = ['-y', '-i', sourceDir.path() + '/' + inVideoName, '-i', tempDir.path() + '/' + 'image1.png',
  '-i', tempDir.path() + '/' + 'image2.png', '-i', tempDir.path() + '/' + 'image3.png',
  '-filter_complex', '[0:v][1:v]overlay=1:1:enable=\'between(t,5,8.5)\'[tmp];' +
  '[tmp][2:v]overlay=1:1:enable=\'between(t,8.5,12)\'[tmp];[tmp][3:v]' +
  'overlay=1:1:enable=\'between(t,12,15)\'', targetDir.path() + '/' + outVideoName]
  var ffmpeg = spawn(ffmpegc, fargs, { cwd:jetpack.cwd(app.getPath('home')).path() })
// some code ommitted
  ffmpeg.on('close', (code) => {
    console.log(`child process exited with code ${code}`)
    webContents.send('notify-user-reply', 'Video processing done.')
  })

上面的命令已经删除了每个图像的各种过滤器(在复杂过滤器中)之间的空格,否则它也会阻塞。

我真的很想在 Electron 中使用 fluent-ffmpeg,不仅是为了方便更优雅地调用 ffmpeg,而且还有一些附加功能,比如简单的进度报告。

4

0 回答 0