<p>Basic syntax is</p>

<pre><code>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
</code></pre>

<p>This will unveil the new video over the old starting from the top-right.</p>

<p>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.</p>

<p>Two of the variables will need to be replaced with numbers by you.</p>

<p>D is the duration or the wipe, in seconds.</p>

<p>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, <code>TN = 1</code> represents a wipe at <code>45 deg</code> and <code>TN = 2</code> represents a wipe at <code>atan (2)</code> = <code>63.4 deg</code>.</p>

CC BY-SA 4.0
2019-03-05T18:04:02.243Z
Also, in my case [old] had to be [0:v]. Thanks for this example. This is great.
sr9yar
CC BY-SA 4.0
2019-07-25T22:50:58.230Z
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
CC BY-SA 4.0
2018-08-04T12:21:25.143Z
2019-03-05T18:08:42.227Z
2019-03-05T18:08:42.227Z
Gyan
<p>Use the <a href="https://ffmpeg.org/ffmpeg-filters.html#xfade" rel="nofollow noreferrer">xfade filter</a>: specifically the <code>diagtl</code>, <code>diagtr</code>, <code>diagbl</code>, and <code>diagbr</code> transitions.</p>

<p>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 <a href="https://ffmpeg.org/download.html" rel="nofollow noreferrer">FFmpeg Download</a> for links to pre-compiled executables.</p>

<p>Also see <a href="https://trac.ffmpeg.org/wiki/Xfade" rel="nofollow noreferrer">FFmpeg Wiki: xfade</a> for more examples.</p>

<p><a href="https://i.sstatic.net/OvXOf.gif" rel="nofollow noreferrer"><img src="https://i.sstatic.net/OvXOf.gif" alt="example of xfade filter transition"></a></p>

<h1>Video input example</h1>

<pre><code>ffmpeg -i input0.mkv -i input1.mkv -filter_complex "[0][1]xfade=transition=diagbl:duration=1:offset=4.5,format=yuv420p" output.mp4
</code></pre>

<ul>
<li><code>duration</code> sets the duration of the transition effect. In this example it is 1 second.</li>
<li><code>offset</code> sets the time to wait before the transition occurs. In this example it will wait 4.5 seconds before applying the transition. Then <code>input1.mkv</code> will play.</li>
<li>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 <code>-ss</code> input option, such as <code>… -ss 3 -i input1.mkv …</code>, or alternatively use the <a href="https://ffmpeg.org/ffmpeg-filters.html#setpts_002c-asetpts" rel="nofollow noreferrer">setpts filter</a>.</li>
</ul>

<h1>With audio crossfade</h1>

<p>Using the <a href="https://ffmpeg.org/ffmpeg-filters.html#acrossfade" rel="nofollow noreferrer">acrossfade filter</a>:</p>

<pre><code>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
</code></pre>

<h1>Image input example</h1>

<pre><code>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
</code></pre>

CC BY-SA 4.0
2020-04-20T21:19:00.547Z
2020-04-20T21:19:00.547Z
llogan
<p>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.
<a href="https://i.sstatic.net/s4P2x.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/s4P2x.png" alt="An example in images"></a></p>

<ffmpeg>
How to create “diagonal wipe” effect in FFmpeg?
Shchipunov
# How to create “diagonal wipe” effect in FFmpeg?

(Asked by: username_0 on 2018-08-03)

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](https://i.sstatic.net/s4P2x.png)](https://i.sstatic.net/s4P2x.png)

**Tags:** ffmpeg


---

## 2 answers

### Answer by username_1 on 2018-08-04. Score: 2 | Accepted answer

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.

> **Comments:**
> **username_2**: Also, in my case [old] had to be [0:v]. Thanks for this example. This is great.  
> **username_3**: 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?  

---

### Answer by username_4 on 2020-04-20. Score: 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.

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


---

