Showing pixel value difference between two video streams

Watch on youtube.com
doc

https://ffmpeg.org/ffmpeg-filters.html#lut2_002c-tlut2

When you want to compare two videos, visualization of differences in pixel values instead of arranging the images themselves is sometimes useful.

Note that “representation of pixel value differences” is not necessarily intuitive to humans.

Show differences as values

00:00:20
#! /bin/sh
ifn="Air on the G String (from Orchestral Suite no. 3, BWV 1068).mp3"
ifnb="`basename \"${ifn}\" .mp3`"
pref="`basename $0 .sh`"
#
"/c/Program Files/ffmpeg-4.1-win64-shared/bin/ffmpeg" \
-y -i "${ifn}" -filter_complex "
[0:a]showcqt=s=1920x1080[v1];
[0:a]bandpass=f=312.5:t=o:w=2,showcqt=s=1920x1080[v2];

[v1][v2]
lut2='
abs(x-y):
128+(x-y):
128+(x-y)'
[v]
" -map '[v]' -map '0:a' -c:a copy "${pref}_${ifnb}.mp4"
00:00:50
#! /bin/sh
ifn="Air on the G String (from Orchestral Suite no. 3, BWV 1068).mp3"
ifnb="`basename \"${ifn}\" .mp3`"
pref="`basename $0 .sh`"
#
"/c/Program Files/ffmpeg-4.1-win64-shared/bin/ffmpeg" \
-y -i "${ifn}" -filter_complex "
[0:a]showcqt=s=1920x1080[v1];
[0:a]bandpass=f=312.5:t=o:w=5,showcqt=s=1920x1080[v2];

[v1][v2]
lut2='
abs(x-y):
128+(x-y):
128+(x-y)'
[v]
" -map '[v]' -map '0:a' -c:a copy "${pref}_${ifnb}.mp4"
00:01:20
#! /bin/sh
ifn="Air on the G String (from Orchestral Suite no. 3, BWV 1068).mp3"
ifnb="`basename \"${ifn}\" .mp3`"
pref="`basename $0 .sh`"
#
"/c/Program Files/ffmpeg-4.1-win64-shared/bin/ffmpeg" \
-y -i "${ifn}" -filter_complex "
[0:a]showcqt=s=1920x1080[v1];
[0:a]bandpass=f=312.5:t=o:w=2,showcqt=s=1920x1080[v2];

[v1][v2]
lut2='
128+floor((x-y)/32)*16:
128+floor((x-y)/32)*16:
128+floor((x-y)/32)*16'
[v]
" -map '[v]' -map '0:a' -c:a copy "${pref}_${ifnb}.mp4"
00:01:50
#! /bin/sh
ifn="Air on the G String (from Orchestral Suite no. 3, BWV 1068).mp3"
ifnb="`basename \"${ifn}\" .mp3`"
pref="`basename $0 .sh`"
#
"/c/Program Files/ffmpeg-4.1-win64-shared/bin/ffmpeg" \
-y -i "${ifn}" -filter_complex "
[0:a]showcqt=s=1920x1080[v1];
[0:a]bandpass=f=312.5:t=o:w=5,showcqt=s=1920x1080[v2];

[v1][v2]
lut2='
128+floor((x-y)/32)*16:
128+floor((x-y)/32)*16:
128+floor((x-y)/32)*16'
[v]
" -map '[v]' -map '0:a' -c:a copy "${pref}_${ifnb}.mp4"

Emphasize whether there is a difference

00:02:20
#! /bin/sh
ifn="Air on the G String (from Orchestral Suite no. 3, BWV 1068).mp3"
ifnb="`basename \"${ifn}\" .mp3`"
pref="`basename $0 .sh`"
#
# in this case, bdx is equal to 8 (because input stream is yuv420p),
# so, pow(2,bdx-1) is 128, and pow(2,bdx)-1 is 255.
#
"/c/Program Files/ffmpeg-4.1-win64-shared/bin/ffmpeg" \
-y -i "${ifn}" -filter_complex "
[0:a]showcqt=s=1920x1080[v1];
[0:a]bandpass=f=312.5:t=o:w=2,showcqt=s=1920x1080[v2];

[v1][v2]
lut2='
ifnot(x-y,0,pow(2,bdx)-1):
ifnot(x-y,pow(2,bdx-1),pow(2,bdx)-1):
ifnot(x-y,pow(2,bdx-1),pow(2,bdx)-1)'
[v]
" -map '[v]' -map '0:a' -c:a copy "${pref}_${ifnb}.mp4"
00:02:50
#! /bin/sh
ifn="Air on the G String (from Orchestral Suite no. 3, BWV 1068).mp3"
ifnb="`basename \"${ifn}\" .mp3`"
pref="`basename $0 .sh`"
#
# in this case, bdx is equal to 8 (because input stream is yuv420p),
# so, pow(2,bdx-1) is 128, and pow(2,bdx)-1 is 255.
#
"/c/Program Files/ffmpeg-4.1-win64-shared/bin/ffmpeg" \
-y -i "${ifn}" -filter_complex "
[0:a]showcqt=s=1920x1080[v1];
[0:a]bandpass=f=312.5:t=o:w=5,showcqt=s=1920x1080[v2];

[v1][v2]
lut2='
ifnot(x-y,0,pow(2,bdx)-1):
ifnot(x-y,pow(2,bdx-1),pow(2,bdx)-1):
ifnot(x-y,pow(2,bdx-1),pow(2,bdx)-1)'
[v]
" -map '[v]' -map '0:a' -c:a copy "${pref}_${ifnb}.mp4"