Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Capturing and Editing Video > Avisynth Usage

Reply
 
Thread Tools Search this Thread Display Modes
Old 30th May 2015, 10:59   #1  |  Link
thescrapyard
Registered User
 
thescrapyard's Avatar
 
Join Date: Feb 2008
Posts: 59
Looking for BeforeDiff function

I'm trying different split screen side-by-side comparisons and settled on the functions I found beforeafter and beforeline suit my needs better than a simple stackhorizontal(clip1,clip2)

There was also another function called beforediff that displays what was changed to see exactly whats happening if doing line darkening or more extreme filtering but the AMVWiki.org has been down for years and all links I found point to that as the source for the functions, or the one below that is also unavailable


Does anybody have the original BeforeDiff functions so I can add it to the original

This was the original topic I started hunting from, but this website is coming back as unavailable or may not exist:

http://www.animemusicvideos.org/foru...p?f=11&t=45223


For those that are interested, here is what I eventually tracked down and put in one script. beforeafter was easy to find but beforeline I found in another topic while hunting for all 3 functions

Thanks


##################################################################
# BeforeAfter by Absolute Destiny and Corran #
# e.g. #
# beforeafter(clip, placement, filters) or #
# #
# beforeafterline(clip, placement,filters) for a lined split #
# #
# 1 for vertical splitscreen, 0 for horizontal splitscreen #
# #
# Does not work on filters that use strings like deen("a3d",1) #
##################################################################

function beforeafter(clip a, int "placement", string "filters"){

placement = default(placement, 1)

Assert((float(width(a))/16)==round(width(a)/16), "Source image width must be a multiple of 16")

b=Eval("a."+filters)
c = (placement==1) ? stackhorizontal(a.crop(0,0,-((ceil(float(width(a))/32))*16),0).subtitle("before"),b.crop(((floor(float(width(a))/32))*16),0,0,0).subtitle("after")) :Stackvertical(a.crop(0,0,0,-height(a)/2).subtitle("Before"),b.crop(0,height(a)/2,0,0).subtitle("After"))

return c
}


function beforeafterline(clip a, int "placement", string "filters"){

placement = default(placement, 1)

Assert((float(width(a))/16)==round(width(a)/16), "Source image width must be a multiple of 16")

b=Eval("a."+filters)
c = (placement==1) ? stackhorizontal(a.crop(0,0,-((ceil(float(width(a))/32))*16),0).subtitle("before"),b.crop(((floor(float(width(a))/32))*16),0,0,0).subtitle("after")) :Stackvertical(a.crop(0,0,0,-height(a)/2).subtitle("Before"),b.crop(0,height(a)/2,0,0).subtitle("After"))
line = (placement!=1) ? blankclip(a,color=$FFFFFF).crop(0,0,(width(a)),4) : blankclip(a,color=$FFFFFF).crop(0,0,4,(height(a)))
d = (placement==1) ? overlay(c,line,x=width(a)-((ceil(float(width(a))/32))*16)-2) : overlay(c,line,y=height(a)-((floor(float(height(a))/32))*16)-2)

return d
}


As mentioned in the script that it won't work with filters that uses strings, it DOES work with all filters that use strings as I found that suggested in another topic. Just add """ to calling the function call and it will work without any issues

Example :

beforeline(clip,1,"""deen("a3d",1)""")

Last edited by thescrapyard; 30th May 2015 at 11:06.
thescrapyard is offline   Reply With Quote
Old 30th May 2015, 13:30   #2  |  Link
creaothceann
Registered User
 
Join Date: Jul 2010
Location: Germany
Posts: 357
Quote:
Originally Posted by thescrapyard View Post
AMVWiki.org has been down for years and all links I found point to that as the source for the functions, or the one below that is also unavailable
Have you tried archive.org's WayBack Machine?

Quote:
Originally Posted by thescrapyard View Post
I'm trying different split screen side-by-side comparisons and settled on the functions I found beforeafter and beforeline suit my needs better than a simple stackhorizontal(clip1,clip2)
I use this:

Code:
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)
}
Only the two clips are necessary, and you can use filters with strings.
creaothceann is offline   Reply With Quote
Old 3rd June 2015, 06:44   #3  |  Link
thescrapyard
Registered User
 
thescrapyard's Avatar
 
Join Date: Feb 2008
Posts: 59
Had a hunt through the forum stored on the 'wayback' archive but nothing that I can find for the [I]backdiff[I] script


If anybody has this knocking about or some suggestions how to do something similar

Is there a diff filter that shows only the difference between a before and after clip that I can use with AvspMOD


Thanks
thescrapyard is offline   Reply With Quote
Old 3rd June 2015, 21:17   #4  |  Link
Motenai Yoda
Registered User
 
Motenai Yoda's Avatar
 
Join Date: Jan 2010
Posts: 709
interleave(a,b)
__________________
powered by Google Translator
Motenai Yoda is offline   Reply With Quote
Old 4th June 2015, 20:27   #5  |  Link
thescrapyard
Registered User
 
thescrapyard's Avatar
 
Join Date: Feb 2008
Posts: 59
Just an update, I managed to find it basically reading through a totally unrelated topic on grain removal and somebody asking about comparing filters. This topic was from 2007,so no wonder I was struggling to find the function


################################################################################################
# BeforeAfterDiff by Corran (Eric Parsons) Based off of BeforeAfter by AbsoluteDestiny #
# and Corran #
# #
#order = Specifies if the filtered footage will be on the top #
# or bottom of screen (Default=true | bottom) #
#showdiff = enables/disable difference layer (Default=false | Disabled) #
#amp = Enable/disable amplify noise (Default=true | Enabled) #
#xdisplace = slides difference layer horizontally by x number #
# of pixels (Default=2*width()/3 | far right hand side of screen) #
#filters = filters used to see differences before and after their application #
# #
#Example: #
#beforeafterdiff(order=true,showdiff=true,amp=false,xdisplace=300,filters="""deen("a3d",4)""") #
################################################################################################

function beforeafterdiff(clip a, bool "order", bool "showdiff", bool "amp",int "xdisplace", string "filters"){

Assert((Float(Width(a))/16)==Round(Width(a)/16), "Source image width must be a multiple of 16")

amp = Default(amp, True)
order = Default(order, True)
showdiff = Default(showdiff, False)
placement = Default(xdisplace, 2*width(a)/3)

placement = (placement > 2*Width(a)/3) ? 2*Width(a)/3 : placement
placement = (placement < 0) ? 0 : placement
xval = (placement > Width(a)/3) ? 5 : placement+Width(a)/3+5
line = BlankClip(a,color=$FFFFFF).Crop(0,0,(Width(a)),2)
line2 = BlankClip(a,color=$FFFFFF).Crop(0,0,2,(Height(a)))
b = Eval("a."+filters)

c = (amp==true) ? Subtract(a,b).Levels(120, 1, 140, 0, 255).Tweak(bright=-5).ConvertToRGB24().\
Crop(placement,0,Round(-Width(a)+placement+Width(a)/3),0).Subtitle("Difference").\
Subtitle("(Amplified)",y=35).Overlay(line2,x=0) : Subtract(a,b).ConvertToRGB24().\
Crop(placement,0,Round(-Width(a)+placement+Width(a)/3),0).Subtitle("Difference").\
Overlay(line2,x=0)

c = Overlay(c,line2,x=Width(c)-2)

d = (order==true) ? StackVertical(a.Crop(0,0,0,-Height(a)/2).Subtitle("Before",x=xval),b.\
Crop(0,Height(a)/2,0,0).Subtitle("After",x=xval)).Overlay(line,y=Height(a)/2-1) : StackVertical(b.\
Crop(0,0,0,-height(a)/2).Subtitle("After",x=xval),a.Crop(0,Height(a)/2,0,0).\
Subtitle("Before",x=xval)).Overlay(line,y=Height(a)/2-1)

e = (showdiff==false) ? d : Overlay(d,c,x=placement)

Return e
}


Useage Examples :


Here we applied filters to the bottom half of the video

beforeafterdiff(filters="""fluxsmoothst().deen("a3d",4)""")


Here we flipped the half of the video which receives the filtering using the order parameter

beforeafterdiff(order=false,filters="""fluxsmoothst().deen("a3d",4)""")


Here we enabled the difference layer the see the changes the filters make. Notice that in this high motion scene there is detail on the wall that is being lost with the fluxsmoothst + Deen filter combo

beforeafterdiff(order=true,showdiff=true,filters="""fluxsmoothst().deen("a3d",4)""")


Here we disabled amplification of the difference layer

beforeafterdiff(order=true,showdiff=true,amp=false,filters="""fluxsmoothst().deen("a3d",4)""")


And finally here we moved the difference layer x pixels from the left side of the video to see the differences of a particular portion of the video. Note in this image that the darker a pixel in the difference layer is the less change there is to it. (The lines of the mask)

beforeafterdiff(order=true,showdiff=true,amp=true,xdisplace=200,filters="""fluxsmoothst().deen("a3d",4)""")



Examples taken from this link, that got me hunting for the original script out of curiosity

http://www.animemusicvideos.org/foru...p?f=11&t=45223

Last edited by thescrapyard; 5th June 2015 at 06:57.
thescrapyard is offline   Reply With Quote
Old 5th June 2015, 07:10   #6  |  Link
thescrapyard
Registered User
 
thescrapyard's Avatar
 
Join Date: Feb 2008
Posts: 59
The function worked perfectly first time, but now I want to add the option of either vertical or horizontal splitting to the function


If anybody can help, or I'll try to get my head around the vertical section of the script which is easy to read, but its the 'if/then/else' commands of a script I'm struggling with, comparing it to what was done in the BeforeAfterLine line uses a horizontal split and see if I can understand how to add that to the function
thescrapyard is offline   Reply With Quote
Old 5th June 2015, 19:58   #7  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
You could start with something like this (EDIT: What you wanted was really quite tricky, did my head in, a bit)

SplitTheDiff.avs
Code:
Function SplitTheDiff(clip a, String Filters, Bool "Order",Bool "Alt", Bool "Show", Bool "Amp",Float "Displace") {
/*  
    SplitTheDiff() by StainlessS @ Doom9, http://forum.doom9.org/showthread.php?p=1725525#post1725525 
    SplitTheDiff(clip a, String Filters, Bool "Order"=True,Bool "Alt"=False, Bool "Show"=False, Bool "Amp"=True,Float "Displace"=2.0/3.0)
      Based on BeforeAfterDiff by Corran which was based on BeforeAfter by AbsoluteDestiny & Corran.

    Filters, filters used to see differences before and after their application eg "Blur(1.58)".
    Order, Default True. Specifies if the filtered footage will be on the Top (default true=Top if Alt=Default False or Left if Alt= True).
    Alt, Default False. Default False = Before and After are top and bottom half of frame otherwise Left and Right of frame.
    Show Default False. True Enables Difference layer.
    Amp Default True. True Enables Amplify Difference Layer.
    Displace Default = 2.0/3.0 (0.0 -> 0.666, silent limiting). Slides difference layer horizontally (if Order==True) or Vertically if
      Order==False. To center align Difference Layer, Displace=1.0/3.0 (Difference Layer is 1/3 of X-Dimension when order=True, or
      Y-Dimension when Order=False.
    eg, SplitTheDiff(filters="""deen("a3d",4)""",Order=True,Alt=False,Show=True,Amp=False,Displace=1.0/3.0).    
*/
    Assert(Filters!="","SplitTheDiff: We need a Filters String")
    Order = Default(Order, True)        Alt = Default(Alt, False)
    Show  = Default(Show, False)        Amp = Default(Amp, True)          
    Displace  = Min(Max(Float(Default(Displace, 2.0/3.0)),0.0),2.0/3.0)
    Dim   = (Alt) ? a.Height : a.Width  Div3 = Dim/12*4
    placement = Min(Max((Int(Displace*Dim)+2)/4*4,0),Dim - Div3)/4*4
    Try {b = Eval("a."+Filters)} Catch(em) {Assert(False,"SplitTheDiff: Error evaluating Filters string" + Chr(10) + em)}    
    lineH = BlankClip(a,color=$FFFFFF).Crop(0,0,(Width(a)),2)
    lineV = BlankClip(a,color=$FFFFFF).Crop(0,0,2,(Height(a)))
    ccx=(!Alt)?placement:0      ccy=(Alt)?placement:0
    ccw=(!Alt)?Div3:0           cch=(Alt)?Div3:0      
    c = Subtract(a,b).Crop(ccx,ccy,ccw,cch)
    c = (Amp) ? c.Levels(127-16, 1.0, 128+16, 0, 255) : c
    c = c.Subtitle("Difference" + ((Amp) ? "\n(Amplified)" : ""),x=5,y=5,lsp=0)
    c = (!Alt) ? c.Overlay(lineV,x=0).Overlay(lineV,x=Width(c)-2) : c.Overlay(lineH,y=0).Overlay(lineH,y=Height(c)-2)     
    bcx = (Order&&Alt)  ? Width(a)/4*2  : 0     bcy = (Order&&!Alt) ? Height(a)/4*2 : 0
    bcw = (!Order&&Alt) ? Width(a)/4*2  : 0     bch = (!Order&&!Alt)? Height(a)/4*2 : 0
    ax=(!Alt) ? (placement>=Div3?0:placement+Div3) : ((Order) ? 0 : a.Width /4*2)
    ay=(Alt)  ? (placement>=Div3?0:placement+Div3) : ((Order) ? 0 : a.Height/4*2) 
    b = b.Crop(bcx,bcy,bcw,bch).Subtitle("After",x=((!Alt)?ax:0)+5,y=((Alt)?ay:0)+5)
    a = a.Subtitle("Before",x=ax+5,y=ay+5)
    dcx = (Order&&Alt)  ? Width(a)/4*2 : 0     dcy = (Order&&!Alt) ? Height(a)/4*2 : 0
    d = a.Overlay(b,x=dcx,y=dcy)
    d = (!Alt) ? d.Overlay(lineH,y=Height(a)/2-1) : d.Overlay(lineV,x=Width(a)/2-1)     
    Return (!show) ? d : Overlay(d,c,x=(!Alt)?placement:0,y=(Alt)?placement:0)
}
Client script
Code:
Avisource("D:\avs\test.avi")
SplitTheDiff(Last,"Blur(1.58).Blur(1.58)",Order=True,Alt=False,Show=True,Amp=True,Displace=1.0/3.0)

return last
If it dont work proper, then I dont really want to know about it
(a bit busy)

EDIT: Added documentation to script.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 8th June 2015 at 08:45.
StainlessS is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 00:24.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.