Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a fade in within overlay with FFMPEG ?

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 !

like image 768
Chris Avatar asked Jul 28 '16 10:07

Chris


1 Answers

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.

like image 139
Gyan Avatar answered Sep 28 '22 06:09

Gyan