Is it possible to create "diagonal wipe" effect in FFmpeg between two videos? An example: the first video is playing and after some time the second video is replacing the first video starting from the right upper angle. On images below, blue color means the first video, green color means the second video.
Basic syntax is
ffmpeg -i old.mp4 -i new.mp4 -filter_complex "format=yuva444p, geq=lum='p(X,Y)': a='st(1,(1+W/H/TN)*H/D);if(lt(W-X,((ld(1)*T-Y)/(ld(1)*T))*ld(1)*T*TN),p(X,Y),0)': enable='lte(t,D)',setpts=PTS+D/TB[new]; [0:v][new]overlay" wipe.mp4
This will unveil the new video over the old starting from the top-right.
What this basically does is add an alpha plane to the new video and then manipulate transparency so that when overlaid a wipe is effected.
Two of the variables will need to be replaced with numbers by you.
D is the duration or the wipe, in seconds.
TN is the tangent of the acute angle between the wipe frontier and the vertical. This is the ratio of the horizontal wipe speed to the vertical wipe speed. So,
TN = 1 represents a wipe at
45 deg and
TN = 2 represents a wipe at
atan (2) =
Use the xfade filter: specifically the
xfade is newer than FFmpeg 4.2, so use a build from the current git master branch (or FFmpeg 4.3 or newer whenever it becomes available). See FFmpeg Download for links to pre-compiled executables.
Also see FFmpeg Wiki: xfade for more examples.
Video input example
ffmpeg -i input0.mkv -i input1.mkv -filter_complex "xfade=transition=diagbl:duration=1:offset=4.5,format=yuv420p" output.mp4
durationsets the duration of the transition effect. In this example it is 1 second.
offsetsets the time to wait before the transition occurs. In this example it will wait 4.5 seconds before applying the transition. Then
- Note that the second video will start from its beginning. For example, if you want it to start at 3 seconds instead of the very beginning then add the
-ssinput option, such as
… -ss 3 -i input1.mkv …, or alternatively use the setpts filter.
With audio crossfade
Using the acrossfade filter:
ffmpeg -i input0.mkv -i input1.mkv -filter_complex "[0:v][1:v]xfade=transition=diagbl:duration=1:offset=4.5,format=yuv420p[v];[0:a][1:a]acrossfade=duration=1[a]" -map "[v]" -map "[a]" output.mp4
Image input example
ffmpeg -loop 1 -t 5 -i 1.png -loop 1 -t 5 -i 2.png -filter_complex "xfade=transition=diagtr:duration=1:offset=4.5,format=yuv420p" output.mp4