Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FFMPEG Fade in and Fade out for Overlay

I'm trying to add Overlay-Pictures to my video via FFMPEG (on Android). For know I managed to display the Image between a certain time span. But now, additionally, I want to add a fade in and fade out animation. Here is what I have so far:

ArrayList<String> cmd = new ArrayList<String>(); cmd.add("-i"); 
cmd.add("video.mp4");
cmd.add("-i");
cmd.add("../image.png");
cmd.add("-filter_complex");
cmd.add("overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/2:enable='between(n,1,12)'"); 
cmd.add("out.mp4");

How do I need to add the Fade in and Fade Out options.

like image 813
Thommy Avatar asked Oct 23 '15 06:10

Thommy


1 Answers

You fade the image in rgba. Example:

ffmpeg -f lavfi -i color=color=black -loop 1 -i logo.png -filter_complex "\
[1:0] format=rgba,fade=in:st=0:d=3:alpha=1,fade=out:st=6:d=3:alpha=1 [ovr];\
[0:0][ovr] overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/2\
" -t 10 -y out.gif

format=rgba - use RGB format with alpha channel for transparency

fade=in:st=0:d=3:alpha=1,fade=out:st=6:d=3:alpha=1 - fade in starting at 0s for 3s with alpha, fade out starting at 6s for 3s with alpha.

overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/2 - overlay centered on source

enter image description here

like image 142
aergistal Avatar answered Sep 16 '22 22:09

aergistal