VideoHelp Forum
+ Reply to Thread
Results 1 to 10 of 10
Thread
  1. Video Restorer lordsmurf's Avatar
    Join Date
    Jun 2003
    Location
    dFAQ.us/lordsmurf
    Search Comp PM
    I don't like complicated scripts. They're hard to understand, hard to edit.

    videoFred/johnmeyer made an excellent film clean script. But sometimes it does too much. At times, I want to only use some of it. But I can't.

    How can I excise the stabilization? Help.

    This is my current failed attempt to reduce it down
    Code:
    film="e:\2.avi"
    result="result2"   
    
    maxstabH=30                                                      #maximum values for the stabiliser (in pixels) 20 is a good start value 
    maxstabV=30
    est_left=40  est_top=40  est_right=40  est_bottom=40             #crop and contast values for special Estimate clip
    est_cont=1.1                                                     #Too large a value defeats stabilization
    
    threads=3
    SetMemoryMax(512)
    
    source1=AviSource(film).converttoYV12()
    
    stab_reference= source1.crop(est_left,est_top,-est_right,-est_bottom).tweak(cont=est_cont).MT_binarize(threshold=80).greyscale().invert()
    mdata=DePanEstimate(stab_reference,trust=1.0,dxmax=maxstabH,dymax=maxstabV)
    stab=DePanStabilize(source1,data=mdata,cutoff=0.5,dxmax=maxstabH,dymax=maxstabV,method=1,mirror=15)
    
    result2= ?????????????
             
    Eval(result)
    The script is messy. Much of this syntax is probably not needed.
    I have no idea what to put at result2=
    Want my help? Ask here! (not via PM!)
    FAQs: Best Blank DiscsBest TBCsBest VCRs for captureRestore VHS
    Quote Quote  
  2. Originally Posted by lordsmurf View Post
    videoFred/johnmeyer made an excellent film clean script. But sometimes it does too much. At times, I want to only use some of it. But I can't.

    How can I excise the stabilization? Help.
    Someone else asked this exact same question just a few days ago. How weird is that?

    I cannot speak for Fred's script, but my film restoration script is (he says humbly) very nicely partitioned, specifically to make it modular and therefore easy to understand and take things out. I also added a LOT of comments to help you understand what is going on (and to help me remember stuff when I go back and make modifications).

    I have copied below the stabilizing section from the latest version of my script that I posted publicly. The input variable to the section is "cropped_source". The output of the stabilization is assigned to the variable "stab".

    So all you have to do is assign the input variable directly to the output variable, and all the code in between will be bypassed:

    stab = cropped_source

    You can then delete or comment out the lines in between, although the way AVISynth works, those lines should no longer be executed and therefore won't slow things down.

    Here's the beginning of the original script, including stabilization:

    Code:
    #START OF SCRIPT
    #....................................................................................................................................................................
    source1= Avisource(film).killaudio().assumefps(play_speed).converttoYV12()
    cropped_source=source1.crop(in_bord_left,in_bord_top,-in_bord_right,-in_bord_bot)               #remove any black borders on input video
    cropped_source=filldrops(cropped_source)     #Use this when removing bad frames that have been removed by duplicating previous frame
    
    #STABILIZING
    #....................................................................................................................................................................
    stab_reference= cropped_source.crop(est_left,est_top,-est_right,-est_bottom).tweak(cont=est_cont).MT_binarize(threshold=80).greyscale().invert()
    mdata=DePanEstimate(stab_reference,trust=1.0,dxmax=maxstabH,dymax=maxstabV)
    stab=DePanStabilize(cropped_source,data=mdata,cutoff=0.5,dxmax=maxstabH,dymax=maxstabV,method=1,mirror=15)
    Here's the same script with stabilization removed:
    Code:
    #START OF SCRIPT
    #....................................................................................................................................................................
    source1= Avisource(film).killaudio().assumefps(play_speed).converttoYV12()
    cropped_source=source1.crop(in_bord_left,in_bord_top,-in_bord_right,-in_bord_bot)               #remove any black borders on input video
    cropped_source=filldrops(cropped_source)     #Use this when removing bad frames that have been removed by duplicating previous frame
    
    #STABILIZING
    #....................................................................................................................................................................
    stab=cropped_source
    Last edited by johnmeyer; 20th Sep 2020 at 02:31. Reason: added link to doom9.org post
    Quote Quote  
  3. Video Restorer lordsmurf's Avatar
    Join Date
    Jun 2003
    Location
    dFAQ.us/lordsmurf
    Search Comp PM
    Uhhh.. huh? That's still not a usable script.

    With it that stripped down, I get:
    Code:
    I don't know what "in_bord_left" means
    (New File, Line 7)
    I see the commenting (really decent stuff), and mostly understand what's going on. Mostly.

    My issue is un-octopussing it, to make a single-task smaller script.

    Part of the issue is the var/string definitions. I hate those. All the "film=" and "source1="
    That's where I lose you. I don't always what's var/string define, and what's not. Nor how to undefine those.

    For example, removing film= and just state the path in AviSource()
    But how to undefine source1= ?

    I don't know what Eval() does
    I don't know how to use result2= when I don't want any of that code running. How to back out of there?

    Your style of code writing is backwards from how I learned to script Avisynth. I actually find yourself coding style to be fairly unique. I'm trying my best to understand it, but I hit brick walls at times.
    Last edited by lordsmurf; 20th Sep 2020 at 03:23.
    Want my help? Ask here! (not via PM!)
    FAQs: Best Blank DiscsBest TBCsBest VCRs for captureRestore VHS
    Quote Quote  
  4. Originally Posted by lordsmurf View Post
    Uhhh.. huh? That's still not a usable script.
    Gosh, it wasn't meant to be a usable script because I thought you needed help with just that one section. So I showed how to remove stabilization. From your post, it sounded like you had stripped out a lot of stuff from my lengthy film restoration script, so it is impossible for me to duplicate whatever it is you have done without knowing what your current script looks like.

    If what you posted is your entire script, that won't work at all, and all of your questions are irrelevant because you've deleted so much that all of the variables are undefined. Its like a car with half the parts removed, and asking why you can't drive it.

    I don't know what problem you are trying to tackle, but I assume it has something to do with film restoration. My advice would be to download VideoFred's script and get it running. I am recommending that you use his original version rather than my derivative because he provides all the DLLs in one package so you can put everything into one folder and, hopefully, get the whole thing running right away without error messages complaining that you are missing something.

    You will still need to use the version of AVISynth that he recommends. If you want, you can use multiple versions of AVISynth and switch between them using the AVISynth switcher available over at doom9.org.

    P.S. My script defines variables for various intermediate steps. This is pretty much required when creating more complex scripts. In simple scripts you can avoid doing this because each line uses "last" which is an internal variable that is assigned to the results from the previous line. However, when you need to use the results from something that happened a few lines earlier, you have to save that in a variable so it can be passed down to an operation that happens later in the script.

    In this script, the function QTGMC uses the results from AVISource via the hidden "last" variable:

    Code:
    AVISource("e:\myvideo.avi")
    QTGMC()
    This is exactly the same script, using a variable instead:
    Code:
    source = AVISource("e:\myvideo.avi")
    QTGMC(source)
    And this uses an alternate AVISYnth syntax for passing the "Source" variable to the function:

    Code:
    source = AVISource("e:\myvideo.avi")
    source.QTGMC()
    Last edited by johnmeyer; 20th Sep 2020 at 14:41. Reason: typos
    Quote Quote  
  5. Video Restorer lordsmurf's Avatar
    Join Date
    Jun 2003
    Location
    dFAQ.us/lordsmurf
    Search Comp PM
    I'm trying to figure out how to write two isolated fully-working scripts. Not get code snippets.

    1. This stabilize is the first. I have several already, wrote some myself. But yours is different. I want that in my library.
    2. The color correction is the second. I've not gotten that far. Not to skip ahead, but I'm intrigued by the X/X2 variables that act as a black/white floor. I want to incorporate that into my own scripts. But I don't under how it works here.

    I realize the reason for the var/string defines (complex scripts).
    The difference is our styles. I'm old-school with video. There were steps, workflows. Do 1+ steps at once, stop. Review results. Do next step(s), etc.
    Your film script is really nice, but it takes that all-in-one (AIO) impatient newbie mentality of wanting one ring to rule them all one script. That's awesome when it works, with no changes needs (or using the limited var options pre-made by the writer/programmer). When you want to advanced edit options, separate tasks, or even troubleshoot/bugfix, it's difficult.

    Your script is awesome at what it does, but techniques from it could be used elsewhere. That's my problem. Trying to un-octopus it.

    I'm actually not wanting to restore film at all here. I just want to excise the stabilize aspect to use for other things. And by "excise' I mean make a script all unto itself, because again steps/workflow. 99% of my sources are consumer video tapes. In fact, even most of my film was film>tape, and I'm trying to unring that bell as best as possible.

    Analogy: I don't want a car. I just want to take the wheel off, and roll it down the hill. But when I try to take it off, it goes flat, and won't refill with air. How can I just remove the tire, and not have it go flat? I'm just excising, or trying to, a small snippet of this script. I want source > stabilize > done (pass to Hybrid or VirtualDub)

    Do this make more sense now?
    Want my help? Ask here! (not via PM!)
    FAQs: Best Blank DiscsBest TBCsBest VCRs for captureRestore VHS
    Quote Quote  
  6. While I may still be confused, it sounds like you are trying to do the opposite of what I thought: you want to extract and use the stabilization code, not remove it.

    If I wanted to use the stabilization code by itself, the last place I would go is to some massive script like our film restoration scripts. It would be like trying to do your own deinterlacing by going into the massively long QTMC script and extracting code.

    Instead, I would start with the code given in the samples in the Depanestimate documentation, get that working, and then use tricks you find in some of these scripts to get what you want. Here's the sample code:

    Code:
    AviSource("input.avi")
    LoadPlugin("depanestimate.dll") # or use autoloading
    LoadPlugin("depan.dll")         # or use autoloading
    i = ConvertToYV12()
    mdata = DePanEstimate(i)
    DePanStabilize(i, data=mdata)
    Quote Quote  
  7. Video Restorer lordsmurf's Avatar
    Join Date
    Jun 2003
    Location
    dFAQ.us/lordsmurf
    Search Comp PM
    I already have various scripts. Some I wrote, some I found, some I got help writing. So that's not what I want. I specifically want to extract the stabilization method found in this script, as it works different from the others. Not a random script, new script, etc... but this script.

    As the author of that script, why is that hard to explain what is doing what? I don't get it.
    We're not all programmers. For me, scripting is hard. Not impossible, just hard, take time to understand. I'm visual, I work in visual mediums. Programming requires esoteric understanding of non-concrete concepts. It's like asking a cat to do algebra homework. (But don't feel superior. Asking a programmer to do visuals is like asking the same cat to draw the Mona Lisa, so it goes both ways here.) So comments like "read the documentation" can be completely worthless if the documentation is also complex jargon.

    I'm stuck, and I'm frustrated. I want to be doing video, not writing syntax/code. I'm purposely NOT a computer programmer.

    You said the code doesn't work. Your code. So how do I fix it? Where did I go wrong?

    I would much rather start it with
    Code:
    AviSource("c:\file.avi")
    converttoYV12()
    Not
    Code:
    film="e:\file.avi"
    source1=AviSource(film).converttoYV12()
    It's all backwards to me that way.

    I actually like this:
    Code:
    maxstabH=30                                                      #maximum values for the stabiliser (in pixels) 20 is a good start value 
    maxstabV=30
    est_left=40  est_top=40  est_right=40  est_bottom=40             #crop and contast values for special Estimate clip
    est_cont=1.1                                                     #Too large a value defeats stabilization
    
    threads=3
    See, that helps demystify the script.


    ******** EDIT: I just tried to write it again, and it's just error after error.

    (Note: I tend to use var/string interchangeably, because those sort of are the same thing here.)

    This is what I can understand, and what I can't:

    Code:
    film="e:\2.avi"
    var define, video will be this when called.

    Code:
    result="result2"
    No idea.

    Code:
    maxstabH=30                                                      
    maxstabV=30
    est_left=40  est_top=40  est_right=40  est_bottom=40             
    est_cont=1.1
    Define stab variables.

    Code:
    source1=AviSource(film).converttoYV12()
    Source is the film from var call, but this still isn't opening source, and is itself a var define to open the source. What the hell? So nothing actually opened source? Where do you open the source?
    Convert colorspace.

    Code:
    stab_reference= source1.crop(est_left,est_top,-est_right,-est_bottom).tweak(cont=est_cont).MT_binarize(threshold=80).greyscale().invert()
    var define, ref = var call to film + crop based on var call to stab variables + tweak same stab vars + MT/grey/invert

    Code:
    mdata=DePanEstimate(stab_reference,trust=1.0,dxmax=maxstabH,dymax=maxstabV)
    var define, analysis data, using var call to stab vars

    Code:
    stab=DePanStabilize(source1,data=mdata,cutoff=0.5,dxmax=maxstabH,dymax=maxstabV,method=1,mirror=15)
    var define actual stab function, using analysis and var call to stab vars

    Code:
    result2=
    No idea. It began to process stuff to pass to another part of script, no idea how to back out of it.

    Code:
    Eval(result)
    No idea.
    Last edited by lordsmurf; 22nd Sep 2020 at 01:45. Reason: typos, presentation
    Want my help? Ask here! (not via PM!)
    FAQs: Best Blank DiscsBest TBCsBest VCRs for captureRestore VHS
    Quote Quote  
  8. lordsmurf
    Here's the separate stabilization and color correction from videoFred/johnmeyer script
    Code:
    #Stabilization - part of script by videoFred/johnmeyer
    
    #Load plugins explicitly
    Loadplugin("plugins/Depan.dll")          #Version 1.10.0.0    4/09/2007
    LoadPlugin("plugins/DepanEstimate.dll")  #Version 1.9.2.0     3/25/2007
    Loadplugin("plugins/mt_masktools.dll")   #Version 2.0.23.0    3/14/2008    MT_binarize
    #LoadPlugin("plugins/Deflicker.dll")     #Version 0.4.0.0     8/16/2004
    
    
    film="e:\2.avi"                               #location of the videofile
    source=AviSource(film).converttoYV12()        #there may be a different decoder instead of AviSource(if there are files .mkv or .mp4 & etc.)
    
    maxstabH=30                                   #maximum values for the stabiliser (in pixels) 20 is a good start value 
    maxstabV=30
    est_left=40  est_top=40  est_right=40  est_bottom=40  #crop and contast values for special Estimate clip
    est_cont=1.1                                          #Too large a value defeats stabilization
    
    threads=3                                             #the number of processing threads, for greater stability, set 3/4 of the number of processor cores
    SetMemoryMax(512)                                     #memory usage limit
    
    stab_reference= source.crop(est_left,est_top,-est_right,-est_bottom).tweak(cont=est_cont).MT_binarize(threshold=80).greyscale().invert()
    mdata=DePanEstimate(stab_reference,trust=1.0,dxmax=maxstabH,dymax=maxstabV)
    stab=DePanStabilize(source,data=mdata,cutoff=0.5,dxmax=maxstabH,dymax=maxstabV,method=1,mirror=15)#.deflicker()
    
    #............................COMPARISONS SECTION.............................................
    #COMPARISONS: ORIGINAL VS RESULTS
    resultS1= stackhorizontal(subtitle(source,"original",size=28,align=2),subtitle(stab,"stab",size=28,align=2))
    
    #...........................Destination file-----uncomment the desired item..................
    stab     
    
    #...........................or if you want to see a comparison...............................
    #resultS1
    Code:
    #Color correction - part of script by videoFred/johnmeyer
    
    #Load plugins explicitly
    LoadPlugin("plugins/autolevels.dll")          #Version 0.6.0.0     1/09/2011
    
    film="e:\2.avi"                               #location of the videofile
    source=AviSource(film).converttoYV12()        #there may be a different decoder instead of AviSource(if there are files .mkv or .mp4 & etc.)
    
    #COLOR AND LEVELS PARAMATERS
    saturation=1.2                                                  #for all outputs
    gamma=1.0                                                       #for all outputs 
    blue= -0  red=-0                                                #manual color adjustment, when returning result3 & result4. Values can be positive or negative
    black_level=0  white_level=255 output_black=0  output_white=255 #manual levels, when returning result2 & result4
    
    #AUTO LEVELS PARAMETER
    X=4   #X  is a special parameter for reducing the autolevels effect on the whites
    X2=4  #X2 is a special parameter for reducing the autolevels effect on the blacks 
    
    #RESULT1: AUTOLEVELS,AUTOWHITE
    result1= source.coloryuv(autowhite=true).addborders(X,0,0,0,$FFFFFF).addborders(0,0,X2,0,$000000).autolevels(filterRadius=2).crop(X,0,-X2,-0)
    
    #RESULT3: AUTOLEVELS, MANUAL COLOR CORRECTIONS
    result3= source.coloryuv(off_U=blue,off_V=red).addborders(X,0,0,0,$FFFFFF).addborders(0,0,X2,0,$000000).autolevels(filterRadius=2).crop(X,0,-X2,-0)
    
    #RESULT2: MANUAL LEVELS, AUTOWHITE
    result2= source.levels(black_level,gamma,white_level,0,255).coloryuv(autowhite=true)
    
    #RESULT4: MANUAL LEVELS, MANUAL COLOR CORRECTIONS
    result4= source.coloryuv(off_U=blue,off_V=red).levels(black_level,gamma,white_level,0,255)
    
    #............................COMPARISONS SECTION.................................................
    #COMPARISONS: ORIGINAL VS RESULTS
    resultS1= stackhorizontal(subtitle(source,"original",size=28,align=2),subtitle(result1,"autolevels, autowhite",size=28,align=2))
    resultS2= stackhorizontal(subtitle(source,"original",size=28,align=2),subtitle(result2,"autowhite, manual levels correction",size=28,align=2))
    resultS3= stackhorizontal(subtitle(source,"original",size=28,align=2),subtitle(result3,"autolevels, manual color correction",size=28,align=2))
    resultS4= stackhorizontal(subtitle(source,"original",size=28,align=2),subtitle(result4,"manual colors and levels correction",size=28,align=2))
    
    #...........................Destination file-----uncomment the desired item..................
    result1      
    #result2
    #result3
    #result4
    
    #...........................or if you want to see a comparison......................................
    #resultS1      
    #resultS2
    #resultS3
    #resultS4
    you can probably adapt it to your needs now
    Quote Quote  
  9. first thing that helps is realize what types you work with

    Code:
    film="e:\2.avi"
    something between quotes is a string, paths are strings, so film becomes string as well, it is a variable with a value that is a string, so it is a string as well

    so this:
    Code:
    film="e:\2.avi"
    source1=AviSource(film).converttoYV12()
    is absolutely the same as this:
    Code:
    source1=AviSource("e:\2.avi").converttoYV12()
    it loads the source and makes sure it is in YU12

    so source1 is a video clip type now. You can put a dot behind a clip type and add another function, like that converttoYV12()

    this:
    Code:
    result="result2"
    result2= ?????????????      
    Eval(result)
    use instead at the end:
    Code:
    return stab
    Quote Quote  
  10. Video Restorer lordsmurf's Avatar
    Join Date
    Jun 2003
    Location
    dFAQ.us/lordsmurf
    Search Comp PM
    Originally Posted by Red_Logir View Post
    lordsmurf
    Here's the separate stabilization and color correction
    you can probably adapt it to your needs now
    Thank you.

    Yes, I now see where I went wrong.

    Now to learn how/why each stab script behaves differently. That's a task for another day!

    Originally Posted by _Al_ View Post
    first thing that helps is realize what types you work with
    Code:
    film="e:\2.avi"
    something between quotes is a string, paths are strings, so film becomes string as well, it is a variable with a value that is a string, so it is a string as well
    so this:
    Code:
    film="e:\2.avi"
    source1=AviSource(film).converttoYV12()
    is absolutely the same as this:
    Code:
    source1=AviSource("e:\2.avi").converttoYV12()
    it loads the source and makes sure it is in YU12
    Yes, I understood that one. I understood most string, but got lost on a couple, tripped over some other code.

    so source1 is a video clip type now. You can put a dot behind a clip type and add another function, like that converttoYV12()
    Yep, knew that too.

    this:
    Code:
    result="result2"
    result2= ?????????????      
    Eval(result)
    use instead at the end:
    Code:
    return stab
    ... and that's one of the places where I tripped and fell on face. Thanks for helping me understand that snippet.
    Want my help? Ask here! (not via PM!)
    FAQs: Best Blank DiscsBest TBCsBest VCRs for captureRestore VHS
    Quote Quote  



Similar Threads

Visit our sponsor! Try DVDFab and backup Blu-rays!