View Full Version : Compare two videos & find frames that are different between them?
Stereodude
5th April 2020, 17:12
Is there a way with some Avisynth commands or plugins to compare two videos and automatically find frames that are different between the two?
I know I can use subtract, but that's a visual check. Is there a way to get metrics or something that will give me frame numbers for frames that are different that I can then manually review (visually)?
poisondeathray
5th April 2020, 17:20
psnr (compare() ) , or ssim external plugin
Visual overlay, or write a log file to examine in spreadsheet or text editor . (Just run script with avsr or vdub2 analysis pass)
http://avisynth.nl/index.php/Compare
http://avisynth.nl/index.php/SSIM
Not sure what you mean about the "automatic" part . You still have to examine in a spreadsheet. Maybe run a macro to return only the different frames
poisondeathray
5th April 2020, 17:26
Or maybe using writefileif() and the runtime functions such as LumaDifference(clip 1, clip2) , and/or ChromaUDifference(clip 1, clip2), ChromaVDifference(clip 1, clip2) . If you want to check all 3
So if diff >0, write file . And it will list the frame numbers. But you still have to look at the frame numbers in the text file
StainlessS
5th April 2020, 17:39
If you could write a script using writeFileIf [as per PDR post] (or some RT_Stats script for same) to output frame numbers,
then could load two sets of frames (one for each clip) with FrameSel() plug selecting suspect frames,
and eg StackHorizontal for inspection of both frames that differ.
StainlessS
5th April 2020, 18:29
Demo to show frames from frames.txt
Make demo clips
Colorbars(Pixel_type="YV12").Trim(0,-100)
ShowFrameNumber
#return last # clip1.avi
SSS="""
n=current_frame
if(n % 10 == 5) {
Subtitle("BONG !",Size=48,Align=5)
}
"""
Scriptclip(SSS)
Return Last # clip2.avi
Show with good(BAD1) on top bad(BAD2) on bottom in middle, and left and right prev and post frames.
V1 = AviSource("D:\clip1.avi")
V2 = AviSource("D:\clip2.avi")
CMD = "D:\Frames.txt"
SHOW = TRUE
REJECT = FALSE # True, shows non different frames (good ones)
EXTRACT = 3 # 1 <= 11 (Odd Only) # 1=Single frames, 3 = Prev+Curr+Post frames, etc
STRIP_W = 480 * 3 # If Extract==3 Only
STRIP_H = 360 # Ditto
Assert(EXTRACT==1 || EXTRACT==3,"EXTRACT 1 or 3 ONLY")
BAD1 = V1.FrameSel(cmd=CMD,show=SHOW,reject=REJECT,Extract=EXTRACT)
BAD2 = V2.FrameSel(cmd=CMD,show=SHOW,reject=REJECT,Extract=EXTRACT)
A = (EXTRACT==3) ? StackHorizontal(BAD1.SelectEvery(EXTRACT,0),BAD1.SelectEvery(EXTRACT,1),BAD1.SelectEvery(EXTRACT,2)).Spline36Resize(STRIP_W,STRIP_H) : BAD1
B = (EXTRACT==3) ? StackHorizontal(BAD2.SelectEvery(EXTRACT,0),BAD2.SelectEvery(EXTRACT,1),BAD2.SelectEvery(EXTRACT,2)).Spline36Resize(STRIP_W,STRIP_H) : BAD2
StackVertical(A,B)
Frames.txt
5
15
25
35
45
55 # This one shows BONG!
65
75
85
95
Result @ bad frame 55, EXTRACT==3
https://i.postimg.cc/py1bxg0d/frame-Sel-00.jpg (https://postimg.cc/py1bxg0d)
Just shows mddle two frames when EXTRACT==1
Stereodude
5th April 2020, 19:02
Or maybe using writefileif() and the runtime functions such as LumaDifference(clip 1, clip2) , and/or ChromaUDifference(clip 1, clip2), ChromaVDifference(clip 1, clip2) . If you want to check all 3
So if diff >0, write file . And it will list the frame numbers. But you still have to look at the frame numbers in the text file
Looking at a log file is fine. I just don't want to have to sit and intently watch a video and hope I don't glance away at the wrong time.
Using compare with a log file looks like it will do what I want.
Thanks for the help guys! :thanks:
Edit: As a side question, are VC1 decoders supposed to be bit exact like H264 decoders?
johnmeyer
6th April 2020, 00:15
The usual way to compare two frames, whether from different videos, or adjacent frames from the same video, is to use one of the built-in AVISynth "YDifference" functions.
From the AVISynth Wiki:
This group of functions return the absolute difference of pixel value between the current and previous frame of clip – either the combined RGB difference or the Luma, U-chroma or V-chroma differences, respectively
If you have absolutely identical frames, you get zero, but if there is even a slight difference, you get a reasonably big value (i.e., it doesn't take much to make the number go up).
I use YDifferenceFromPrevious and YDifferenceToNext all the time. You can use it to create your own scene detection function; you can find single blank frames; you can detect a photographer's flash; etc. You can sometimes also find a dropped frame. You do this by looking at the YDifference values between adjacent frames that are 1, 2, 3 (or more) frames away from the current frame. You create a local moving average and then compare the current YDifferenceToNext value to that average. If it is a LOT higher, then you may have a big jump caused by a dropped frame.
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.