8

I want to use fluent-ffmpeg to create a video of last n images of a directory, or database entries.

Which is the correct syntax?

These are my tries:

Mimic shell command

ffmpeg()
  .addInput('ls *png | tail -n 17')
  .inputOptions("-pattern_type glob")
  .output("output.mp4").run()

but it does not accept shell commands;

space - separated paths

ffmpeg()
  .addInput('a*.png b*.png ')
  .inputOptions("-pattern_type glob")
  .output("output.mp4").run()

but it does not accept list of files separated by spaces;

Array of image paths

ffmpeg()
  .addInput(array) // ['aa.png', 'a1.png',,,'bbb.png']
  .inputOptions("-pattern_type glob")
  .output("output.mp4").run()

but it does not accept arrays.

EDIT:

Also, from Merge Multiple Videos using node fluent ffmpeg, I am able to add multiple inputs using an array of files as

var ffmpeg= require('fluent-ffmpeg');
var f=ffmpeg() 
pngarr.forEach(p => f.input(p)) /// pngarr is my array of png paths

But running

f.output("./output.mp4").run()

I obtain just a video of 0 seconds containing the first png of the list.

Community
  • 1
  • 1
leonard vertighel
  • 1,058
  • 1
  • 18
  • 37

1 Answers1

7

The ffmpeg methods are chainable, so you could use a reducer like so:

var chainedInputs = inputlist.reduce((result, inputItem) => result.addInput(inputItem), ffmpeg());

Your last edit nearly did the same thing, but it keeps calling .input() on the same level instead of on top of the previous

Jusmpty
  • 171
  • 1
  • 8
  • But `chainedInputs.output("./output.mp4").run() ` still returns a 0 seonds video containing the first png of the list – leonard vertighel Aug 04 '17 at 14:54
  • 1
    The reduce method works for me, but I have so many input videos that the resulting command was too long and could not be executed. Is there a way to input a text file with a list of video files? https://stackoverflow.com/questions/51034956/inputing-a-list-of-files-for-concatenation-with-node-js-module-fluent-ffmpeg – carpiediem Jun 26 '18 at 04:36