Using `alphamerge’

doc

https://ffmpeg.org/ffmpeg-filters.html#alphamerge

Watch on youtube.com Watch on youtube.com

using a non-rectangular division

If you want to arrange the two videos to be compared in a non-rectangular division, you can use `alphamerge’.

Example 1

00:00:15

Whatever you use, you will be able to create “pictures to use as alphaplanes for alphamerge”, for example, MS Paint. If it is simple, it is not difficult to make using only ffmpeg:

#! /bin/sh
ffmpeg -y -filter_complex "
color=black:s=1280x720,geq='lum=if(gt(Y/X,9/16),255,0):cb=128:cr=128'" \
    -r 1 -t 1 _alpha01.png

All you have to do is pass it to alphamerge:

#! /bin/sh
ifn="Drifting with Cars.mp4"
ifnb="`basename \"${ifn}\" .mp4`"
pref="`basename $0 .sh`"

ffmpeg -y -i "${ifn}" -i "_alpha01.png" -filter_complex "
[1:v]loop=-1:size=2,scale=1280:720,setsar=1[alpha];

[0:v]curves=preset=color_negative[vf];
[0:v][alpha]alphamerge[vt];

[vf][vt]overlay=shortest=1
" -an "${pref}_${ifnb}.mp4"

Example 2

00:01:08
#! /bin/sh
ffmpeg -y -filter_complex "
color=black:s=200x720,geq='lum=if(gte(Y/X,720/200),255,0):cb=128:cr=128'[vt];
color=black:s=1280x720,geq='lum=if(gte(X,1280/2),0,255):cb=128:cr=128'[vb];
[vb][vt]overlay=1280/2-200/2:0
" -r 1 -t 1 _alpha02.png
#! /bin/sh
ifn="Drifting with Cars.mp4"
ifnb="`basename \"${ifn}\" .mp4`"
pref="`basename $0 .sh`"

ffmpeg -y -i "${ifn}" -i "_alpha02.png" -filter_complex "
[1:v]loop=-1:size=2,scale=1280:720,setsar=1[alpha];

[0:v]curves=preset=color_negative[vf];
[0:v][alpha]alphamerge[vt];

[vf][vt]overlay=shortest=1
" -an "${pref}_${ifnb}.mp4"

swapping two videos sequentially

To compare two videos, instead of dividing a 2D plane, the idea of dividing by time axis is not bad.

Example 1

00:02:01
#! /bin/sh
ffmpeg -y -filter_complex "
color=black:s=1280x720:d=40,geq='lum=if(gte(X,mod(T*500,1280)),255,0):cb=128:cr=128'
" _alpha03.mp4
#! /bin/sh
ifn="Drifting with Cars.mp4"
ifnb="`basename \"${ifn}\" .mp4`"
pref="`basename $0 .sh`"

ffmpeg -y -i "${ifn}" -i "_alpha03.mp4" -filter_complex "
[1:v]scale=1280:720,setsar=1[alpha];

[0:v]curves=preset=color_negative[vf];
[0:v][alpha]alphamerge[vt];

[vf][vt]overlay=shortest=1
" -an "${pref}_${ifnb}.mp4"

Example 2

00:00:15
#! /bin/sh
ffmpeg -y -filter_complex "
color=black:s=1280x720:d=40,geq='lum=255*mod(floor(T*2),2):cb=128:cr=128'
" _alpha04.mp4
#! /bin/sh
ifn="Drifting with Cars.mp4"
ifnb="`basename \"${ifn}\" .mp4`"
pref="`basename $0 .sh`"

ffmpeg -y -i "${ifn}" -i "_alpha04.mp4" -filter_complex "
[1:v]scale=1280:720,setsar=1[alpha];

[0:v]edgedetect=mode=wires[vf];
[0:v][alpha]alphamerge[vt];

[vf][vt]overlay=shortest=1
" -an "${pref}_${ifnb}.mp4"

Example 3

00:00:47
#! /bin/sh
ffmpeg -y -filter_complex "
color=black:s=1280x720:d=40,geq='lum=255*abs(1-mod(T*2,2)):cb=128:cr=128'
" _alpha05.mp4
#! /bin/sh
ifn="Drifting with Cars.mp4"
ifnb="`basename \"${ifn}\" .mp4`"
pref="`basename $0 .sh`"

ffmpeg -y -i "${ifn}" -i "_alpha05.mp4" -filter_complex "
[1:v]scale=1280:720,setsar=1[alpha];

[0:v]edgedetect=mode=wires[vf];
[0:v][alpha]alphamerge[vt];

[vf][vt]overlay=shortest=1
" -an "${pref}_${ifnb}.mp4"

Example 4

00:01:20
#! /bin/sh
ffmpeg -y -filter_complex "
color=black:s=1280x720:d=40
,geq='
lum=255*if(lte(X,640),mod(floor(T*2),2),1-mod(floor(T*2),2)):
cb=128:
cr=128'
" _alpha06.mp4
#! /bin/sh
ifn="Drifting with Cars.mp4"
ifnb="`basename \"${ifn}\" .mp4`"
pref="`basename $0 .sh`"

ffmpeg -y -i "${ifn}" -i "_alpha06.mp4" -filter_complex "
[1:v]scale=1280:720,setsar=1[alpha];

[0:v]edgedetect=mode=wires[vf];
[0:v][alpha]alphamerge[vt];

[vf][vt]overlay=shortest=1
" -an "${pref}_${ifnb}.mp4"

Example 5

00:01:53
#! /bin/sh
ffmpeg -y -filter_complex "
color=black:s=1280x720:d=40
,geq='
lum=255*if(lte(X,640),abs(1-mod(T*2,2)),1-abs(1-mod(T*2,2))):
cb=128:
cr=128'
" _alpha07.mp4
#! /bin/sh
ifn="Drifting with Cars.mp4"
ifnb="`basename \"${ifn}\" .mp4`"
pref="`basename $0 .sh`"

ffmpeg -y -i "${ifn}" -i "_alpha07.mp4" -filter_complex "
[1:v]scale=1280:720,setsar=1[alpha];

[0:v]edgedetect=mode=wires[vf];
[0:v][alpha]alphamerge[vt];

[vf][vt]overlay=shortest=1
" -an "${pref}_${ifnb}.mp4"