Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

fluent-ffmpeg from an array of input files

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.

like image 517
leonard vertighel Avatar asked Dec 15 '16 02:12

leonard vertighel


People also ask

How does fluent-FFmpeg calculate the percentage of output?

To estimate percentage, fluent-ffmpeg has to guess what the total output duration will be, and uses the first input added to the command to do so. In particular: percentage may be wrong when using multiple inputs with different durations and the first one is not the longest The stderr event is emitted every time FFmpeg outputs a line to stderr.

How do I add inputs to FFmpeg?

Specifying inputs. You can add any number of inputs to an Ffmpeg command. An input can be: a file name (eg. /path/to/file.avi ); an image pattern (eg. /path/to/frame%03d.png ); a readable stream; only one input stream may be used for a command, but you can use both an input stream and one or several file names.

What version of FFmpeg does fluent-FFmpeg support?

fluent-ffmpeg requires ffmpeg >= 0.9 to work. It may work with previous versions but several features won't be available (and the library is not tested with lower versions anylonger). If the FFMPEG_PATH environment variable is set, fluent-ffmpeg will use it as the full path to the ffmpeg executable.

How do I use the constructor in fluent-FFmpeg?

The fluent-ffmpeg module returns a constructor that you can use to instanciate FFmpeg commands. You can also use the constructor without the new operator. You may pass an input file name or readable stream, a configuration object, or both to the constructor.


1 Answers

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

like image 150
Jusmpty Avatar answered Oct 25 '22 10:10

Jusmpty