4

For the life of me I cannot figure out to translate:

-i foo.mp3 -filter_complex aformat=channel_layouts=mono,showwavespic=s=4000x1000 -frames:v 1 foo.png

Into a fluent-ffmpeg command. Can anyone help me out?

I have tried with the most basic command:

var inputStream = fs.createReadStream('C:/Somewhere/foo.mp3')
var outputStream = fs.createWriteStream('C:/Somehere/foo.png')

var proc = ffmpeg()
     .input(inputStream)
     .complexFilter([
         'showwavespic'
     ])
     .on('error', function(err) {
          console.log('an error happened: ' + err.message);
     })
     .save(outputStream);

I get the error thrown from the handler: an error happened: ffmpeg exited with code 1: Cannot find a matching stream for unlabeled input pad 0 on filter Parsed_showwavespic_1

Lutando
  • 4,909
  • 23
  • 42

2 Answers2

2

You need to specify an input for the complexFilter that will be taken for generating the waveform, as well as, you need to set an output which I named waveform.

This is how I do it: (fluent-ffmpeg v2.1.2)

import FFMPEG from 'fluent-ffmpeg';

const ffmpeg = new FFMPEG({
    source: 'path/to/input_file.mp3'
});

ffmpeg
    .complexFilter(
        [
            `[0:a]aformat=channel_layouts=mono,compand=gain=-6,showwavespic=s=4000x1000:colors=#0025ff[waveform]`
        ],
        ['waveform']
    )
    .outputOptions(['-vframes 1'])
    .on('start', () => {
        console.log('FFMPEG started with command:', command);
    })
    .on('progress', () => {
        console.log('progress:', progress);
    })
    .on('error', error => {
        console.log('FFMPEG error:', error);
        reject(error.message);
    })
    .on('end', () => {
        console.log('FFMPEG is done!');
    })
    .saveToFile('path/to/output.png');
parse
  • 1,706
  • 17
  • 27
0

As the error tells you need an input for your the showwavespic filter.

Example on your simple example:

var inputStream = fs.createReadStream('C:/Somewhere/foo.mp3')
var outputStream = fs.createWriteStream('C:/Somehere/foo.png')

var proc = ffmpeg()
     .input(inputStream)
     .complexFilter([
         '[0:a]aformat=channel_layouts=mono,showwavespic=s=4000x1000'
     ])
     .outputOptions(['-vframes 1'])
     .on('error', function(err) {
          console.log('an error happened: ' + err.message);
     })
     .save(outputStream);
Mattstir
  • 272
  • 2
  • 9