7

I'm wondering how to add the option "fade in" in the -filter_complex 'overlay'.

The basic overlay

ffmpeg -i movie.mp4 -i image.jpg -c:v libx264 -filter_complex 'overlay=x=main_w-overlay_w-100:y=main_h-overlay_h-100' output.mp4

Does the image.jpg fade=in should be in filter_complex like this ?

ffmpeg -i movie.mp4 -i image.jpg -c:v libx264 -filter_complex 'fade=in:st=0:d=5:alpha=1, overlay=x=main_w-overlay_w-100:y=main_h-overlay_h-100' output.mp4

Thanks a lot for your help on the construction of the -filter_complex parameter !

Chris
  • 93
  • 1
  • 6

1 Answers1

14

Use

ffmpeg -i movie.mp4 -loop 1 -i image.jpg -filter_complex
      "[1]format=yuva420p,fade=in:st=0:d=5:alpha=1[i];
       [0][i]overlay=W-w-100:H-h-100:shortest=1"
-c:v libx264 output.mp4

Your fade filter is set to operate on the alpha channel, but JPEGs don't have alpha, so the image needs to be converted to a pixel format that does. Also, FFmpeg is a time-based processor of streams and a single image is treated as one frame at 25 fps, thus lasting 0.04 s, so I added a loop to generate a video stream out of it, which is needed for the fade to take effect.

The overlay filter takes in two inputs, so I assigned all the pads for explicit routing. Since the image is looped indefinitely, the shortest is added to stop the overlay when the main video ends.

Gyan
  • 85,394
  • 9
  • 169
  • 201
  • Hi, what does `alpha=1` mean here? My overlay disappears if I use that, and turns to black if I use `alpha=0`. – Navid Khan Feb 28 '20 at 12:04
  • Are you doing a fade-out? What's your full command and duration of video? – Gyan Feb 28 '20 at 12:42
  • 1
    This is the relevant bit of my code: `[i]format=yuva420p,fade=in:st=0:d=1:alpha=1[i];[0][i]overlay=x=#{artist_profile_image_x}:y='if(gte(t,0.2), if(lte(t,1.0), (H/2-h/2-t*250), (H/2-h/2-250)), NAN)'[v]` and my video is 4 seconds long. – Navid Khan Mar 09 '20 at 07:37