2

I'm trying to turn the following complex filter into a Fluent FFMPEG command but I can't figure out how the mapping works.

ffmpeg -i audio.mp3 -filter_complex "[0:a]showfreqs=s=200x100:colors=white|white,format=yuv420p[vid]" -map "[vid]" -map 0:a video.mp4

This is what I have so far but I get an error about the 'vid' stream.

ffmpeg()
    .input("audio.mp3")
    .audioCodec("aac")
    .audioBitrate("320")
    .complexFilter(
      {
        filter: "showfreqs",
        options: { s: "200x100" },
        inputs: "0:a",
      },
      {
        filter: "format",
        options: { pix_fmts: "yuv420p" },
        outputs: ["vid"],
      }
    )
    .outputOptions(['-map "[vid]"', "-map 0:a"])
    .save(spectrumTmp)

Error: ffmpeg exited with code 1: Stream map '"[vid]"' matches no streams. To ignore this, add a trailing '?' to the map.

If I add a trailing '?' in outputOptions I get a file with no video stream.

Dan Weaver
  • 711
  • 8
  • 20
  • 1
    Quoting issue. Try `.outputOptions(["-map '[vid]'", "-map 0:a"])` or `.outputOptions(["-map [vid]", "-map 0:a"])`. – llogan Sep 10 '19 at 20:59

1 Answers1

5

Solved this. There are three things wrong with my original code:

  1. The complexFilter needs to be an array of objects, I was missing the array brackets.
  2. It seems you need to explicitly specify inputs and outputs for chained filters in fluent-ffmpeg.
  3. As @llogan pointed out, I had a quoting issue in the outputOptions

The final working code:

ffmpeg()
    .input("audio.mp3")
    .audioCodec("aac")
    .audioBitrate("320")
    .complexFilter([
      {
        filter: "showfreqs",
        options: { s: "200x100" },
        inputs: "0:a",
        outputs: "[freqs]",
      },
      {
        filter: "format",
        options: { pix_fmts: "yuv420p" },
        inputs: "[freqs]",
        outputs: "[vid]",
      },
    ])
    .outputOptions(["-map [vid]", "-map 0:a"])
    .save(spectrumTmp)
Dan Weaver
  • 711
  • 8
  • 20
  • bro, could you help me with something? [pastebin](https://pastebin.com/di6yFZ62) I'm trying to overlay a video onto a frame/image, i have the overlay working but the video isn't playing. thanks bro – Dean Van Greunen Mar 04 '22 at 13:20
  • 1
    @DeanVanGreunen can't see any obvious problems in your code. You need to make sure the -loop 1 is applied to the specific image input or it won't loop. Not sure if that's happening in your code. – Dan Weaver Mar 07 '22 at 01:07