4

I manage to add a single image to a video starting at a certain time and ending at a certain time, but I cannot find a way to do this for multiple images. I use fluent-ffmpeg.

This is the code I have:

ffmpeg('../videos/testklein.mp4')
     .input('../src/test.png')
     .input('../src/0.png')
     .input('../src/1.png')
     .addOptions([
        "-strict -2"
     ])

     .complexFilter([
        {
          filter: 'overlay',
          options: {
            x: 200,
            y: 200,
            enable: 'between(t,1,3)',

          }}, {
          filter: 'overlay',
          options: {
            x: 200,
            y: 200,
            enable: 'between(t,3,5)',
          }},
           {
          filter: 'overlay',
          options: {
             x: 200,
            y: 200,
            enable: 'between(t,5,7)',
          }
      },

    ])

I suppose I need to explicitly state what filter should take what file, but I am not sure about the syntax for that.

Riël
  • 1,251
  • 1
  • 16
  • 31

2 Answers2

4

This is the right syntax: The first one add inputs [0:v][1:v] and outputs ['tmp'] Then add ['tmp'] as inputs for the next one. For 2 images:

I can add as many images as I want. Pass the 'tmp' as 2nd argument to complexFilter!

(You can ofcourse change tmp to any string)

.complexFilter(
    [
      {
        "filter": "overlay",
        "options": {
          "enable": "between(t,2,4)",
          "x": "810",
          "y": "465"
        },
        "inputs": "[0:v][1:v]",
        "outputs": "tmp"
      },
      {
        "filter": "overlay",
        "options": {
          "enable": "between(t,13,14)",
          "x": "810",
          "y": "465"
        },
        "inputs": "[tmp][2:v]",
        "outputs": "tmp"
      }
    ], 'tmp')
Riël
  • 1,251
  • 1
  • 16
  • 31
  • Hello @Riël: How to preserve the sound? I tested your code and it's works (thank you so much) but the sound was removed. – seikida Oct 08 '21 at 09:34
  • That is strange, it has been quite a while, but I had no issues with the sound being removed. – Riël Oct 08 '21 at 21:58
  • 1
    You should add an outputOption for audio map like this:- .outputOptions(["-map 0:a"]) – hamid saifi May 14 '22 at 17:07
0

i was searching for adding multiple images in a simple complexFilter then i found this code working but after rendering the video the sound was being removed. After making a lot of changes I found a solution for audio.

add an outputOption in your code


.outputOptions(["-map 0:a"])


Sharing this if anyone is having the audio problem.

hamid saifi
  • 184
  • 2
  • 3