Search code examples
videoffmpegoverlayvideo-processing

FFmpeg: Adding multiple overlays to the video with the fade in/out effect. Command works but the images ( overlays ) doesn't show in the video


I'm trying to add multiple overlays to the video and fade in/out them separately. So, the command works without any issue but in the video, I can't see the overlay images

Here is the command with which I'm trying to do it

ffmpeg -y -i video.mp4 -loop 1 -i text1.png -loop 1 -i text2.png -loop 1 -i text3.png -loop 1 -i text4.png -loop 1 -i text5.png -filter_complex "
[1]fade=st=0:d=4:alpha=1,fade=out:st=2:d=1:alpha=1,trim=0:3,setpts=PTS+5/TB[ovr1];
[2]fade=st=0:d=4:alpha=1,fade=out:st=2:d=1:alpha=1,trim=0:3,setpts=PTS+10/TB[ovr2];
[3]fade=st=0:d=4:alpha=1,fade=out:st=2:d=1:alpha=1,trim=0:3,setpts=PTS+15/TB[ovr3];
[4]fade=st=0:d=4:alpha=1,fade=out:st=2:d=1:alpha=1,trim=0:3,setpts=PTS+20/TB[ovr4];
[5]fade=st=0:d=4:alpha=1,fade=out:st=2:d=1:alpha=1,trim=0:3,setpts=PTS+25/TB[ovr5];
[0:v][ovr1]overlay=0:0:enable='between(t,0,5)'[base1];
[base1][ovr2]overlay=0:(main_h-overlay_h)/2:enable='between(t,5,10)'[base2];
[base2][ovr3]overlay=0:(main_h-overlay_h)/2:enable='between(t,10,15)'[base3];
[base3][ovr4]overlay=0:(main_h-overlay_h)/2:enable='between(t,15,20)'[base4];
[base4][ovr5]overlay=0:(main_h-overlay_h)/2:enable='between(t,20,25)'[out]" -map "[out]" -c:v libx264 -c:a copy -flags +global_header -shortest with_overlays.mp4

Can you please help me to find what am I doing wrong?


Solution

  • Your timestamps are offset wrong, e.g.

    [1]...setpts=PTS+5/TB[ovr1]; but [0:v][ovr1]overlay=0:0:enable='between(t,0,5)'[base1];, so the stream starts after the overlay enabled range. It should be setpts=PTS+0/TB. Reduce all offsets by 5, similarly.