fluent-ffmpeg / node-fluent-ffmpeg

A fluent API to FFMPEG (http://www.ffmpeg.org)
MIT License
7.83k stars 875 forks source link

Gif creation with -lavfi fails in fluent, but copying command to terminal works fine #588

Closed johndanek closed 8 years ago

johndanek commented 8 years ago

Here is what I'm trying to do in fluent-ffmpeg:

ffmpeg()
    .addInput(this.tmpDirNameInput+"/trimmedFile.mp4")
    .addInput(paletteFileName)
    .addOutputOption('-lavfi "fps='+that.instructions.params.fps+' [x]; [x][1:v] paletteuse"')
    .on('start', function(ffmpegCommand){
      console.log("Beginning gif creation:\n\t"+ffmpegCommand);
    })
    .on('end', function() {
      console.log("GIF created: "+that.instructions.params.filename+" complete! Check "+that.tmpDirNameOutput);
      //self.cleanupTmpDirs();
    })
    .on('error', function(error) {
      console.log("ERROR creating gif: "+error);
    })
    .output(this.tmpDirNameOutput+"/"+this.instructions.params.filename)
    .run();

This fails with the following error: ERROR creating gif: Error: ffmpeg exited with code 1: Unrecognized option 'lavfi "fps=10 [x]; [x][1:v] paletteuse"'. Error splitting the argument list: Option not found

This is the ffmpeg command being used (according to the .on('start') callback): ffmpeg -i tmp0/input/trimmedFile.mp4 -i tmp0/input/palette.png -y -lavfi "fps=10 [x]; [x][1:v] paletteuse" tmp0/output/test.gif

If I copy and paste that to the command line, it works fine. How can I get this to work in fluent-ffmpeg?

njoyard commented 8 years ago

You have to separate the flag from the option string in addOutputOption. fluent-ffmpeg automatically splits them when the string you pass contains only one space (ie addOutputOption('-flag option')) but not when there are 2 or more : addOutputOption('-flag', '"Option with spaces"')

johndanek commented 8 years ago

Thanks for the tip, but now I get the less helpful error of "Invalid argument".

ERROR creating gif: Error: ffmpeg exited with code 1: Error initializing complex filters. Invalid argument

The outputted command is still: ffmpeg -i ./tmp4/input/trimmedFile.mp4 -i ./tmp4/input/palette.png -y -lavfi "fps=10 [x]; [x][1:v] paletteuse" ./tmp4/output/test.gif