Ahmad Ali Mukashaty
Ahmad Ali Mukashaty

Reputation: 65

Using fade in/out twice on the same image using ffmpeg

I'm using this commands to fade in logo after 5 seconds from the beginning of stream and fade it out after 25 seconds like this

ffmpeg -re -i test.mp4 -ignore_loop 0 -i logo.gif -filter_complex "[1:v]
fade=in:st=5:d=1:alpha=1,fade=out:st=30:d=1:alpha=1 [ov];[0:v][ov]
overlay=30:30" -f mpegts udp://127.0.0.1:port

but I want to repeat this in a different time period on the same logo for example (in the 45th second to 60th second ) when I try to repeat fade syntax like this none of them work

ffmpeg -re -i test.mp4 -ignore_loop 0 -i logo.gif -filter_complex "[1:v]
fade=in:st=5:d=1:alpha=1,fade=out:st=30:d=1:alpha=1,fade=in:st=45:d=1:alpha=1,
fade=out:st=60:d=1:alpha=1 [ov];[0:v][ov]
overlay=30:30" -f mpegts udp://127.0.0.1:port

how can I solve this problem ? and can I use minutes instead of seconds with fade ?

Upvotes: 0

Views: 1004

Answers (1)

Gyan
Gyan

Reputation: 93171

What a fade-in on alpha does is zero out the alpha before the start time and interpolate it to the stored value within the duration. What a fade-out on alpha does is zero out the alpha after start time+duration and interpolates from the stored value within the duration. So, your first set of fade in/out filters zeroed out the alpha before 5s and after 30s. The 2nd fade-in filter zeroed out all alpha before 45s (including 5 to 30s), and the fade-in did not work because all alpha after 30s had been zeroed out, so it was interpolating from alpha=0 to alpha=0.

You'll have to split the streams and use multiple overlay filters.

ffmpeg -re -i test.mp4 -ignore_loop 0 -i logo.gif -filter_complex "[1:v]split=2[wm1][wm2];
[wm1]fade=in:st=5:d=1:alpha=1,fade=out:st=30:d=1:alpha=1[ovr1];
[wm2]fade=in:st=45:d=1:alpha=1,fade=out:st=60:d=1:alpha=1[ovr2];
[0:v][ovr1]overlay=30:30[base];[base][ovr2]overlay=30:30"
-f mpegts udp://127.0.0.1:port

Upvotes: 2

Related Questions