3

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. An example in images

0

2 Answers 2

2

Basic syntax is

ffmpeg -i old.mp4 -i new.mp4 -filter_complex
       "[1]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) = 63.4 deg.

2
  • Also, in my case [old] had to be [0:v]. Thanks for this example. This is great.
    – sr9yar
    Commented Mar 5, 2019 at 18:04
  • This is extremely helpful, thanks Ryan! Is there a way to tell the filter when to start? I have two 10 second mp4s and the transition always seems to start 2 seconds in. It'd be great if I could start it in the middle of the two, or to start at a specific time. Is that possible with this FFmpeg filter?
    – Peck
    Commented Jul 25, 2019 at 22:50
0

Use the xfade filter: specifically the diagtl, diagtr, diagbl, and diagbr transitions.

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.

example of xfade filter transition

Video input example

ffmpeg -i input0.mkv -i input1.mkv -filter_complex "[0][1]xfade=transition=diagbl:duration=1:offset=4.5,format=yuv420p" output.mp4
  • duration sets the duration of the transition effect. In this example it is 1 second.
  • offset sets the time to wait before the transition occurs. In this example it will wait 4.5 seconds before applying the transition. Then input1.mkv will play.
  • 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 -ss input 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 "[0][1]xfade=transition=diagtr:duration=1:offset=4.5,format=yuv420p" output.mp4

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.