0

I'm trying to create a video from multiple images and a single audio file (different images last for the different duration).

I've got the ffmpeg command

$ ffmpeg \
-loop 1 -t 4 -i image-1.jpg \
-loop 1 -t 4 -i image-2.jpg \
-loop 1 -t 5 -i image-3.jpg \
-loop 1 -t 6 -i image-4.jpg \
-loop 1 -t 4 -i image-5.jpg \
-loop 1 -t 4 -i image-6.jpg \
-i audio.mp3 \
-filter_complex \
"[0:v]fade=t=out:st=4:d=1[v0]; \
 [1:v]fade=t=in:st=0:d=1,fade=t=out:st=4:d=1[v1]; \
 [2:v]fade=t=in:st=0:d=1,fade=t=out:st=4:d=1[v2]; \
 [3:v]fade=t=in:st=0:d=1,fade=t=out:st=4:d=1[v3]; \
 [4:v]fade=t=in:st=0:d=1,fade=t=out:st=4:d=1[v4]; \
 [5:v]fade=t=in:st=0:d=1,fade=t=out:st=4:d=1[v5]; \
 [v0][v1][v2][v3][v4][v5]concat=n=6:v=1:a=0,format=yuv420p[v]" -map "[v]" -map 6:a -shortest output7.mp4

The ffmpeg commands works perfectly, unfortunately I am not able to use only ffmpeg in my production environment, so I have been using fluent-ffmpeg.

I'm having hard time converting the above command to something fluent-ffmpeg understands.

let command = ffmpeg();
    command.input("./public/concat/image-3.jpg");
    command.loop(1);
    command.inputOptions("-t 10");
    command.input("./public/concat/image-2.jpg");
    command.loop(1);
    command.inputOptions("-t 10");
    command.input("./public/concat/audio.mp3");
    command.complexFilter([
      "[0:v]fade=t=out:st=4:d=1[v0]",
      "[1:v]fade=t=in:st=0:d=1,fade=t=out:st=4:d=1[v1]",
      "[v0][v1]concat=n=2:v=1:a=0,format=yuv420p[v]",
    ]);
    command.outputOptions(["-map [v]", "-map 2:a", "-shortest"]);
    command.output("./public/video.mp4").run();
    command.on("error", function (err) {
      console.log("Error: ", err);
    });
    command.on("end", function () {
      console.log("Success 1");
    });

The above code only adds the first image and is not able to concat multiple images. Would be really helpful if anyone can point out what I'm doing wrong.

Thanks for the help :)

Edit: So I have checked the logs and figured that the images start at 0:00 and end at 0:04 so they all overlap and hence only one image is shown. Not sure how I can set the duration of each input other than using "-t x" as the input option.

AbsoluteSith
  • 1,917
  • 25
  • 60

1 Answers1

0

Instead of using multiple input options, I've resorted to using just addOptions command.

So making it

command.addOptions(["- loop 1", "-t 4", "-i ./img-1.jpg"])

Hopefully, this helps out somebody.

AbsoluteSith
  • 1,917
  • 25
  • 60