Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to apply multiple filters and inputs with ffmpeg

Not only do I have multiple filters, I have multiple inputs that I want to overlay. I usually have to them in 2-3 steps and wonder how to do it all in one command as it should be the most efficient way?

1 and 2 literally identical. For readability, I've cut out the actual filters which are very long and complicated.

  1. image slide in left onto video
  2. Take output of 1, image slide in right
  3. Take output 2, textbox image fade in
  4. Take output3, text fade in (finish)

    1)
    ffmpeg -i input.mp4 -loop 1 -i image.jpg -filter_complex \
          "[1]scale=640:-1[i0]; \
           [i0]drawbox=color=white:t=15[i1]; \
           [i1]format=,fade=[i2]; \
           [i2]rotate=[i3]; \
           [0][i3]overlay= \
    -c:v libx264 -vb 10M output1.mp4
    
    2)
    ffmpeg -i output1.mp4 -loop 1 -i image2.jpg -filter_complex \
          "[1]scale=[i0]; \
           [i0]drawbox=[i1]; \
           [i1]format=,fade=[i2]; \
           [i2]rotate=[i3]; \
           [0][i3]overlay=" \
    -c:v libx264 -vb 10M output2.mp4
    
    3)
    ffmpeg -i output2.mp4 -i image3.jpg -filter_complex \
          "[1]scale=1080:-1 [ovrl], \
           [ovrl]format=fade=[i]; \
           [0][i]overlay=" \
    -c:v libx264 -vb 10M output4.mp4
    
    
    4)
    ffmpeg -i output4.mp4 -filter_complex "drawtext=" -vb 10M finaloutput.mp4
    
like image 219
Jason Avatar asked Jul 24 '17 14:07

Jason


1 Answers

Use

ffmpeg -i input.mp4 -loop 1 -i image.jpg -loop 1 -i image2.jpg -loop 1 -i image3.jpg \
 -filter_complex \
   "[1]scale=640:-1,drawbox=color=white:t=15,format=,fade=,rotate=[i1]; \
    [2]scale=,drawbox=,format=,fade=,rotate=[i2]; \
    [3]scale=1080:-1,format=,fade=[i3]; \
    [0][i1]overlay=shortest=1[o1]; \
    [o1][i2]overlay=shortest=1[o2]; \
    [o2][i3]overlay=shortest=1,drawtext=" \
 -b:v 10M finaloutput.mp4
like image 155
Gyan Avatar answered Nov 01 '22 06:11

Gyan