View Full Version : Merging two clips framewise
Xaser
14th June 2014, 18:32
Hi guys,
I'm currently working on an encoding project and currently tweaking the sh*t out of the filters I used so far. I don't care much about encoding time, just about quality (and filesize)
It was quite helpful to HorizontalStack the same clip with different filters to see how they compare, but when it comes to tweaking parameters, I'd like to merge the two clips (one with a parameter set to value a and the other with the value set to b) framewise, so I can see the change by rapidly switching between frames.
From what I found out searching on the wiki page, AviSynth doesn't seem to have such a filter build in, does anybody know of a filter out there, that can do this?
Thanks,
Max
creaothceann
14th June 2014, 19:18
# ...
v1 = Filter(a)
v2 = Filter(b)
Interleave(v1, v2)
Btw. for comparing two clips next to each other I use this:
function Show(clip a, clip b, string "text_a", string "text_b") {
text_a = default(text_a, "")
text_b = default(text_b, "")
a = a.ConvertToRGB32
b = b.ConvertToRGB32
c = Subtract(a, b)
x = a.Width / 2
y = a.Height / 2
a1 = a.Crop(0, 0, 0, -y).Crop(1, 1, -1, -1).AddBorders(1, 1, +1, +1, $FF0000).Subtitle(text_a, text_color=$FFFFFF)
a2 = a.Crop(0, +y, 0, 0).Crop(1, 1, -1, -1).AddBorders(1, 1, +1, +1, $0000FF)
b1 = b.Crop(0, 0, 0, -y).Crop(1, 1, -1, -1).AddBorders(1, 1, +1, +1, $FF0000).Subtitle(text_b, text_color=$FFFFFF)
b2 = b.Crop(0, +y, 0, 0).Crop(1, 1, -1, -1).AddBorders(1, 1, +1, +1, $0000FF)
c1 = c.Crop(0, 0, 0, -y).Crop(1, 1, -1, -1).AddBorders(1, 1, +1, +1, $FF0000).Subtitle("top" , text_color=$FFFFFF, halo_color=$FF0000)
c2 = c.Crop(0, +y, 0, 0).Crop(1, 1, -1, -1).AddBorders(1, 1, +1, +1, $0000FF).Subtitle("bottom", text_color=$FFFFFF, halo_color=$0000FF)
a = StackVertical (a1, a2)
b = StackVertical (b1, b2)
c = StackHorizontal(c1, c2)
StackVertical(StackHorizontal(a, b), c)
}
Xaser
14th June 2014, 19:52
Hi,
thanks alot, exactly what I was looking for!
The script looks Handy as well, any particular reason for the convert to RGB? Also I can't quite make out why you are splitting each clip in half and then add them together again, wouldn't it be more useful to do it like
A_top | B_top
B_bot | A_bot
to see the difference along the border?
creaothceann
14th June 2014, 20:05
They are converted because clip b may be in a different colorspace than clip a and to make cropping and adding 1-pixel-wide borders possible.
The function started out as
function Show(clip a, clip b) {
c = Subtract (a, b)
d = BlankClip(a)
StackVertical( StackHorizontal(a, b),
\ StackHorizontal(c, d) )
}
...i.e. the two clips, the subtraction result and a blank area to fill the remaining space. That space is eliminated by separating each top and bottom and arranging them as in the current version. (It also has the nice side effect of turning 4:3 material into a 16:9 frame.)
The only shortcoming imo is that the subtraction result could make small changes a bit more apparent, but I don't know enough to make it so.
Reel.Deel
15th June 2014, 11:41
Here's some other alternatives to showing the difference between 2 clips:
# Return Clip Difference of input clips (amp==true = Amplified, show==true = show background)
Function ClipDelta(clip clip1,clip clip2,bool "amp",bool "show") {
amp=Default(amp,false)
show=Default(show,false)
c2=clip1.levels(128-32,1.0,128+32,128-32,128+32).greyscale()
c1=clip1.subtract(clip2)
c1=(amp)?c1.levels(127,1.0,129,0,255):c1
return (show)?c1.Merge(c2):c1
}
AMP, Amplified, self explanatory.
Show, shows a dimmed representation of the frame, (best used with AMP) so you can see exactly where the differences are.
function DiffAB(clip a, clip b, float "x", float "d") {
# Y8, YV12, YV16, YUY2, YV24, RGB
# Requires: mt_masktools
x = default(x, 0.4)
d = default(d, 0.2)
w = b.width()
h = b.height()
a = (a.width() != w) ? a.Spline36Resize(w, h) : a
w2 = Floor(w*x/2)*2
dx = (x+d > 1.0) ? Floor((1-x)*w) : Floor(d*w)
dx = Floor(dx/2)*2
a2 = a.Crop(w2,0, dx,h)
a2 = a2.IsYUY2() ? a2.ConvertToYV16() : a2.IsRGB() ? a2.ConvertToYV24() : a2
b2 = b.Crop(w2,0, dx,h)
b2 = b2.IsYUY2() ? b2.ConvertToYV16() : b2.IsRGB() ? b2.ConvertToYV24() : b2
dc = mt_lutxy(b2, a2, "x y - 4 * 128 +", u=3,v=3)
b.Overlay(a2, w2-dx,0)
(w2-dx-dx<0) ? last : Overlay(dc, w2-dx-dx,0)
}
Xaser
15th June 2014, 11:49
Reel.Deel beat me to it, thanks for the extra scripts though :thanks:
@creaothceann I just wrote a AviSynth RGB32 contrast filter, to amplify the differences but then again its not that much better than simply using levels as the scripts that Reel.Deel suggested.
Simply put a
c = Subtract(a, b).Levels(128-x, 1, 128+x, 0, 255)
and experiment with the "x". That should do just fine :)
colours
16th June 2014, 22:24
Here's an alternative that doesn't really involve any Avisynth functions/filters at all. Create two scripts with the filters you want to compare and load them in separate tabs in AvsPmod. Comparison is then as easy as switching between the tabs. (This requires that the clips have the same properties, but that's usually true if you're just comparing filters.) Most of the time, I use either this or the already-suggested Interleave.
Taking the difference of two clips is generally not a very useful thing to do; if you can't see the difference between a filtered and unfiltered clip, maybe it's because there is no visible difference and you shouldn't waste your time tweaking it to beyond-placebo-tier perfection.
Xaser
17th June 2014, 08:01
I agree, considering how much time QTGMC already takes to process the video, I definitely want to keep additional processing to a minimum. However sometimes the difference image is very good to see where to look for the changes, e.g. when I used the MSmooth Filter with strengths 3 and 4, I didn't see any difference at first. After checking the difference image however, I saw that a (small) reddish area of the picture got substantially darker after I applied the filter.
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.