Range() v3.2 Now with rg()

This forum is for questions and discussion of all the aspects of handling your footage. If you have questions about capturing/ripping footage, AviSynth, or compression/encoding/converting, look here.

Range() v3.2 Now with rg()

Postby Phantasmagoriat » Mon Oct 25, 2010 3:40 pm

Range() v3.2 last updated November 7th, 2010


DESCRIPTION:
  • Range() is an avisynth function that allows you to make modifications to a range of frames in your video... while leaving the rest untouched.
  • Includes Fadein/Fadeout (v2.0), Clip Replacement, Filter Presets, and Boundary Checking for special cases (v3.0).
  • Similar to ApplyRange() but with a number of advantages.
  • Somewhat in response to this thread: viewtopic.php?f=45&t=101930
  • This is useful because some filtering methods are great for a few scenes, but are terrible for other scenes... usually destroying a lot of detail in the process. See the above thread for traditional ways around this problem. In response, my own solution was to create a function that does everything I want! :awesome:

USAGE:
  • Code: Select all
    range( startframe,endframe, mod, fadein,fadeout, mod_extra, head,tail, length )
                or
       rg( head, startframe, endframe, tail, mod, mod_extra )

  • Lets imagine you did what Range() does within an editing GUI:
    Image
  • The mod parameter stands for "modification"
  • mod is a Val Type, so it can be input a number of different ways:
    1. FILTERS & FILTERCHAINS (String)
    2. PRESETS & PRESET_NUMBERS (String for Preset_Names, Integer for Preset_Numbers)
    3. REPLACEMENT_CLIPS & IMAGES (Clip)


    1. FILTERS & FILTERCHAINS (TYPICAL USAGE):
    Code: Select all
    range( 1200,1300, "filter()"      ) # 1.applies filter() from frames 1200 to 1300
    range( 1200,1300, "filter"        ) # 2.same as last example (using default arguments)
    range( 1200,1300, "filter(args)"  ) # 3.same as last example using declared arguments
    range(    0,1300, "filter()"      ) # 4.applies filter() from frame 0 to 1300
    range( 1200,   0, "filter()"      ) # 5.applies filter() from frame 1200 until the end
    range(    0,   0, "filter()"      ) # 6.all frames
    range(    0,   0, "null"          ) # 7.no frames
    range( 1200, "filter()"           ) # 8.single-frame filtering
    range( 1200, "filter()",length=24 ) # 9.using a specific range length
    USING MULTIPLE FILTERS & ARGUMENTS:
    Code: Select all
    range( 1200,1300, "filter1().filter2().filter3()"   ) #10.how to use multiple filters (filterchain)
    range( 1200,1300, "filter4(arg1,arg2,param3=arg3)"  ) #11.include any arguments

    range( 1200,1300, """filter1().filter2().filter3()...filter4(arg1, param2="arg2")""" )
    #12.triple quotes are needed here because of the single quotes around "arg2"
    USING FADEIN/FADEOUT & rg():
    Code: Select all
    range( 1200,1300, "filter()", 5,5                  ) #13.fading in/out for 5 frames before/after range
    range( 1200,1300, "filter()", head=1192, tail=1315 ) #14.specific start/end points for fadein/fadeout
       rg( 1192,1200,1300,1315, "filter()"             ) #14a.same as last example
    2. PRESETS & PRESET_NUMBERS:
    Code: Select all
    range( 1200,1300, "nuke",  0,0    ) #15.using a preset via Preset_Name (see Full Documentation for all presets)
    range( 1200,1300, 4     ,  0,0    ) #16.using a preset via Preset_Number
    range( 1200,1300, mod=4 ,  0,0    ) #17.same as last (all parameters can be called like this)
    range( 1200,1300, f1    ,  0,0    ) #18.Using a Temporary preset (FilterChain, f1, must be set *first*.  See below.)

    # 19. To Save a preset, open range.avsi, go to the Presets Section, and follow the pattern you see...
    # Just give it a new Name & Number, and you can always call it from within range()
    3. REPLACEMENT_CLIPS & IMAGES: Using Range() to compensate for over-filtering
    Code: Select all
    range( 1200,1300, c1, 0,0              ) #20.Replace frames using c1 (Clip, c1, must be set *first*.   See below.)
    range( 1200,1300, c1, 0,0, "filter2()" ) #21.Extra Filtering (method 1)
    range( 1200,1300, c1.filter2(), 0,0    ) #22.Extra Filtering (method 2)
    range( 1200,1300, c2, 0,0              ) #23.Extra Filtering (method 3)
    range( 1200,1300, c3, 0,0              ) #24.using pre-filtered clip
    range( 1200,1300, i1, 0,0              ) #25.Imag Replacement using i1 (Image, i1, must be set *first*.  See below.)

  • SETTING FILTERCHAIN VARIABLES:
    Code: Select all
    f1 = """filter1().filter2().filter3()""" # f1 is "filterchain 1"
    f2 = """filter1().filter4().filter5()"""
    f3 = """filter6().filter7"""
    f4 = f1+".filter8()"
  • SETTING CLIP VARIABLES:
    Code: Select all
    c1 = avisource("YOURORIGINALCLIP.avi")   # c1 is "clip 1"
    c2 = avisource("YOURORIGINALCLIP.avi").filter1().filter2()
    c3 = avisource("PRE-FILTEREDCLIP.avi")
    c4 = clip1.filter3().filter4()
  • SETTING IMAGE VARIABLES:
    Code: Select all
    c1 = avisource("YOURORIGINALCLIP.avi")
    all= c1.framecount()
    fps= c1.framerate()                         # i1 is "image 1"
    i1 = imagesource("YOURIMAGE.png", start=0, end=all, fps=fps)
    # you may need to change colorspace/framesize/audio etc...


FULL DOCUMENTATION (long version with example scenarios):
Spoiler :
PARAMETERS:
  • Full syntax (for those that are interested):
    range( clip c, int [startframe], val{int/string} [endframe], val{string/string/int/clip} [mod], int [fadein], int [fadeout], val{string/string/int} [mod_extra], int [head], int [tail], int [length] )

    1. [startframe]/[endframe] + [length] (Integer)
      - The first two parameters are where you specify the range of frames you wish to modify
      - [length] is the parameter specifying the duration of your range when [endframe] is not specified.
      startframe - The framenumber where you want your video to be modified
      endframe - The framenumber where you want your video to stop being modified
      length - The number of frames you want your range to last for. Cannot be used with [endframe].


    2. [mod] (String/String/Integer/Clip)
      - The third parameter, previously known as [filterchain] is now called [mod], which stands for "modification."
      - This lets you control how you want to modify your range of frames.
      - As of v3.0, [mod] can be input in 4 ways:
        A. Filter_Chain
        B. Preset_Name
        C. Preset_Number
        D. Clip_Replacement
        See below for specific usage *

    3. [fadein]/[fadeout] (Integer)
      - The fourth & fifth parameters are the number of frames before/after range that you wish to fade-in/fade-out
      fadein - The number of frames you want to fade in before [startframe]
      fadeout - The number of frames you want to fadeout after [endframe]

    4. [mod_extra] (String/String/Integer)
      - [mod_extra] can only be used if [mod] is a clip.
      - works just like [mod], but is applied to your replacement clip
      - [mod_extra] itself cannot be a clip (you can filter a clip... but you cannot clip a clip! lol

    5. [head]/[tail] (Integer)
      - The seventh & eighth parameters can fine-tune [fadein]/[fadeout] if you have particular start/end points in mind.
      head - The framenumber you want to begin [fadein]
      tail - The framenumber you want to end [fadeout]

    *USING MOD & MOD_EXTRA - Since [mod] and [mod_extra] are Val Types, they can be input a number of different ways:
      A. FILTER_CHAINS (String)
      - To input mod as a filter chain, simply type the sequence of filters (within quotes " ") that you want to apply to your range of frames.
      - Include any arguments and parameters you desire.
      - Multiple filters can be chained together via a period (.)
      - if you just want to use the default parameters of a filter, the () is not necessary
      - if your filter chain contains quotes, enclose everything using triple quotes (""" """)
      Code: Select all
      range( 1200,1300, "filter()" )
      range( 1200,1300, "filter"   )
      range( 1200,1300, "filter1().filter2().filter3()" )
      range( 1200,1300, """filter1().filter2().filter3()...filter4(argument1, parameter2="argument2")""" )

      B. PRESET_NAMES (String)
      - Instead of inputing a specific filterchain, you can call any of the presets like so:
      Code: Select all
      range( 1200,1300, "nuke" )
      -Here is a list of the current Preset Names/Numbers:
      Code: Select all
         #     NAME:            FILTERS_USED:                 DESCRIPTION:
        -1 - "null"    - "subtitle("")"              - Does nothing to the clip.
                                                       (Basically a "null transform.")
         0 - "freeze"  - "FreezeFrame()"             - replaces all frames within your
                                                       range with the first frame
         1 - "light"   - "fluxsmoothst()"            - light filtering
         2 - "medium"  - "fft3dgpu()"                - medium filtering
         3 - "heavy"   - "dfttest()"                 - heavy filtering
         4 - "nuke"    - "deblock().\                - very heavy filtering
                          dfttest().\
                          blur(1.58)" 
         5 - "nothing" - "blankclip()"               - replaces video with blackness,
                                                       and audio with silence
         6 - "black"   - "levels(255, 1, 255, 0, 0)" - replaces video with solid black
         7 - "white"   - "levels(0, 1, 0, 255, 255)" - replaces video with solid white
         8 - "invert"  - "levels(256, 1, 0, 0, 265)" - inverts the luma
         9 - "noise"   - "addgrain(500,0,0)"         - adds grain
        10 - "blur"    - "blurmod()"                 - applies a strong blur
      - None of these filters are required for range() to work normally, however,
      - to use a preset, you may need to install the corresponding filters. For instance, the "blur" preset needs BlurMod() :amv:

      - External Filters on AviSynth.org would be a good place to start for some ideas
      - Maybe check out my last post in this thread for some useful filters as well.
      - Feel free to change the presets yourself within the code ;)
      - I'll take suggestions for presets as well


      C. PRESET_NUMBERS (Integer)
      - Instead of calling a Preset by name, you can call it by number.
      - The following all do the same thing:
      Code: Select all
      range( 1200,1300, "nuke" )
      range( 1200,1300,  4     )
      range( 1200,1300,  mod=4 )
      See the above section for a list of preset_numbers.


      D. CLIP_REPLACEMENT (Clip)
      - Instead of modifying your range with a filter or preset, you can replace the frames with another clip entirely.
      - (realistically, you would probably use a different/better version of the same clip)
      - It is usually best to declare your clips as variables first, then call them later on in the script (whenever needed):
      Code: Select all
      clip1 = avisource("youroriginalclip.avi")
      clip2 = avisource("youroriginalclip.avi").filter1().filter2()
      clip2
      range( 1200,1300, clip1 )
      -This basically returns clip2 (filtered), but frames 1200-1300 are replaced with the original non-filtered clip
      - if you want to apply additional filters on top of your replacement clip, use [mod_extra], or consult the Examples Section below.



##############################
EXAMPLE SCENARIOS:
    1. Applying a FilterChain (Typical Usage):
    - Say you want to apply some filters like ttempsmooth() and gradfunkmirror() to only frames 1200-1300 and leave the rest untouched, you can go:
    Code: Select all
    range( 1200, 1300, """ttempsmooth().gradfunkmirror()""" )

    2. Special Ranges:
    Code: Select all
    range( 0,1300, "deblock()" ) # applies deblock() from frame 0 to 1300
    range( 1200,0, "deblock()" ) # frame 1200 until the end
    range( 0,0, "deblock()"    ) # all frames
    range( 0,0, "null"         ) # no frames

    3. Using Arguments/Parameters:
    - Since range() doesn't have the limiting argument problem that applyrange() has, you can put anything in between the triple quotes-- parameters, arguments, and all:
    Code: Select all
    range( 1200, 1300, """fft3dfilter(sigma=1.5, bt=5, bw=32, bh=32, ow=16, oh=16, sharpen=0.4).lsf().gradfun2db()""" )
    - Triple quotes are only necessary when single quotes are contained within your filterchain string ie.) range(1200,1300, """filter("arg1", "arg2")"""
    -But it doesn't hurt to use them for clarity either...


    4. Single Frame Filtering:
    - If frame number 2112 is really blocky:
    Code: Select all
    range( 2112, "deblock()" )

    5. Using Length:
    - apply deblock() to frame 9000, and make it last for 24 frames (~1 second)
    Code: Select all
    range( 9000, """deblock()""", length=24 ) # same as range( 9000, 9000+24, "deblock()" )
    -in this case your range would span over nine-thousand


    6. Using fadein/fadeout:
    - As of v2.0, range implements dissolve() to rejoin segments. This allows you to have smooth transitions from your non-filtered to your filtered range. To fadein/fadeout your range for 5 frames before/after startframe/endframe, respectively (see the visual aid in the Usage Section above):
    Code: Select all
    range( 1200,1300, """dfttest()""", 5,5 )

    7. Using head/tail:
    - If you know which frames you want to begin/end your fadein/fadeout at:
    Code: Select all
    range( 1200,1300, """dfttest()""", head=92, tail=215 )

    8. Using Presets:
    - If you find a few frames that are really difficult to clean, you can use the "nuke" preset:
    Code: Select all
    range( 1200, 1224, "nuke", 5,5 )
    The "nuke" preset implements a combination of deblock(), dfttest(), and blur(1.58) to be used as a "quickfix." This is a pretty heavy filter chain and should only be used in severe cases. Another method is to use the "freeze" preset. See the Presets Section above for a list of other presets.


    9. Using Preset_Numbers:
    - Call the "nuke" preset by using it's preset number:
    Code: Select all
    range( 1200, 1224, 4, 5,5 )
    See the Presets Section above for a list of other values


    10. Make your own Presets:
    - Set your own presets as variables, then call them later from within range():
    Code: Select all
    f1 = """fluxsmoothst().\
            limitedsharpen()"""
    f2 = """fft3dgpu().\
            derainbow().\
            limitedsharpen(strength=200)"""
    f3 = """dfttest().\
            blurmod(5)"""
    avisource("C:\path\to\your\video.avi")
    range(1000, 2000, f1, 0,0)
    range(2001, 2345, f2, 5,5)
    range(2346, 3000, f1, 5,5)
    range(3200, 3200, f3, 5,0)

    11. Clip Replacement: Replace overfiltered frames with original frames
    - Let's say you want to sharpen your entire video with limitedsharpen(strength=200).
    - Suppose this worked for the majority of the video, but oversharpened a few scenes.
    - In previous versions of range() you would be stuck; extra filtering won't fix this :|
    - But as of v3.0 you can replace those scenes with the original non-filtered clip
    Code: Select all
    c1 = avisource("youroriginalclip.avi")
    c1
    limitedsharpen(strength=200) # overfilters a few scenes
    range( 1200,1300, c1, 24,24 )
    - the whole clip is filtered, but frames 1200-1300 are replaced with the original non-filtered clip
    - In this case, you also fadein/fadeout for 24 frames so the contrast isn't so great between filtered and non-filtered frames


    12. Clip Replacement with additional filtering ( method 1 - using [mod_extra] ):
    - let's say your clip replacement over-compensated
    - now it's not sharp enough, and you think some sharpening is still needed, just not using 200 strength:
    Code: Select all
    c1 = avisource("youroriginalclip.avi")
    c1
    limitedsharpen(strength=200)
    range( 1200,1300, c1, 24,24,"limitedsharpen(strength=50)" )
    - Just like the last example, the whole clip is filtered, and frames 1200-1300 are replaced with the original clip.
    - But this time, the [mod_extra] parameter is used to apply limitedsharpen(strength=50) to the replaced clip.


    13.Clip Replacement with additional filtering ( method 2 - apply your filter directly to [mod] ):
    Code: Select all
    c1 = avisource("youroriginalclip.avi")
    c1
    limitedsharpen(strength=200)
    range( 1200,1300, c1.limitedsharpen(strength=50), 24,24 )
    - does the same as previous


    14. Clip Replacement with additional filtering ( method 3 - apply your filter to clip call ):
    Code: Select all
    c1 = avisource("youroriginalclip.avi")
    c2 = avisource("youroriginalclip.avi").limitedsharpen(strength=50)
    c1
    limitedsharpen(strength=200)
    range( 1200,1300, c2, 24,24 )
    - does the same as previous


    15. Clip Replacement using pre-filtered/pre-determined clips ( likely scenario ):
    Code: Select all
    #### Set your clips & pre-filtered-clips here:
    c1=avisource("YOURORIGINAL_CLIP.avi")
    c2=avisource("PRE-FILTERED_CLIP.avi")
    c3=c1.limitedsharpen(strength=100)
    c4=c1.limitedsharpen(strength=200)
    c5=c2.fft3dgpu().limitedsharpen(strength=50)

    #### Put your main clip with ranges here:
    c3
    range( 1200,1300, c2, 5,5)
    range( 2000,2222, c2, 5,5)
    range( 2543,2700, c3, 5,5)
    range( 2987,3041, c2, 0,0)
    range( 3374,3684, c1, 5,5)
    range( 4275,4467, c2, 5,5)
    range( 5692,5923, c2, 5,5)
    range( 6256,6523, c1, 5,5)
    range( 6957,7243, c5, 5,5)
    range( 8578,8732, c2, 5,5)

    16. Replace frames with a still image:
    Code: Select all
    c1  = dss2("YOUR_VIDEO.mp4")
    all = c1.framecount()
    fps = c1.framerate()
    i1  = imagesource("PATH\TO\YOUR\IMAGE.png", start=0, end=all, fps=fps)
    c1.range(1200,1300, i1)
    -You'll need to make sure your image matches your video specifications
    -If they don't match you may need to convert colorspaces and/or change frame sizes
    -Crop/Resize/Addborders if necessary. BestFit() may be useful for that 8-)

    17. A Mixture of everything: Super Advanced Clip Replacement & Additional Filtering!
    Code: Select all
    #### Set your clips & pre-filtered-clips here:
    c0 = as("ORIGINALCLIP.avi")
    c1 = as("PRE-FILTERED.avi")
    c2 = c0.limitedsharpen(strength=200)

    #### Set your filterchain presets here:
    f0  = """invert"""
    f1  = """dfttest().gradfun2db()"""
    f2  = """dfttest().limitedsharpen(smode=2).gradfun2db()"""
    f3  = """dfttest().fastlinedarken(thinning=0).limitedsharpen().gradfun2db()"""

    c1                             # Put the main clip you want to use here.

    maa()                          # Put your main "blanket" filterchain that you
    fft3dgpu()                     # want to apply to everything here.
    limitedsharpen()

    range(1931,2025, c0, 9,5, f0)  # Compensate for over/under filtering here.
    range(2058,2110, c1, 5,5, f1)  # Use any combination of:
    range(2246,2350, c2, 5,5, f2)  # 1.Filterchains 2.Presets 3.Preset_Numbers 4.Clips
    range(2851,2898, c1, 8,0, f3)
    range(2969,2991, c1,      mod_extra=f1, head=2900, tail=3000)
    range(2176,2214, c0, 5,5, "deblock()")
    range(2383,2410, c0, 5,0, f1+".derainbow()")
    range(3038,3053, c0, 0,0, "maa()."+f1)
    range(3729,4064, c0, 5,5, "nuke")
    range(3358,3376, c1, 5,5, 0 )
    range(5180,5256, c1, 5,5, -1)
    range(5489,5590, f2, 5,5, c1)
    range(6279,6389, c0, 5,5)
    range(6489,6590, c0)
    range(6591,6600, c0.deblock() )
    range(6489,6590, mod="deblock()")
    range(6489,6590, mod="freeze")
    range(6489,6590, mod=0)
    range(6623,6721, f3)
    range(6823,6957, "deblock()" )
    range(7124,7278, 0)
    range(7500, "deblock()")
    range(7600, "nuke")
    range(7700, "4")
    range(7800, "blurmod()", length=30)
    range(0,0, "gradfun2db()")
    echo(last.framecount())
    Believe it or not, I tested this script to see if it would work, and it returned no errors... :dino:

##############################
SCRIPT:
    v3.2 ( with Fadein/Fadeout, Clip-Replacement, Presets, Boundary-Checking, and rg() ):
    Spoiler :
    Code: Select all
    ########################## Range() v3.2 by Phantasmagoriat #######################
    function range(
          \    clip    "c"
          \,    int     "startframe"
          \,    val     "endframe"
          \,    val     "mod"
          \,    int     "fadein"
          \,    int     "fadeout"   
          \,    val     "mod_extra"
          \,    int     "head"
          \,    int     "tail"
          \,    int     "length"   )
    {
      #### VARIABLE JUGGLING #########################################################
      #### ...allows you to type range(100, "filter()")
      #### ...allows mod to be a filter String or Clip type
        mod_extra    = default( mod_extra, """subtitle("")""" )
        mod          = ( isstring( endframe  ) == true ) ? endframe   : mod
        endframe     = ( isstring( endframe  ) == true ) ? startframe : endframe
        clip2        = ( isclip(mod) == true ) ? mod  : c
        mod          = ( isclip(mod) == true ) ? mod_extra : mod

      #### VALUE FIXING ##############################################################
        c            = c
        all          = c.framecount()
        startframe   = ( startframe < 0          ) ? 0   : startframe
        endframe     = ( endframe   < 0          ) ? all : endframe
        startframe   = ( startframe > all        ) ? all : startframe
        endframe     = ( endframe   > all        ) ? all : endframe
        endframe     = ( endframe   < startframe ) ? all : endframe
        mod          = string(mod)

      #### DEFAULT BEHAVIOR ##########################################################
        length       = default( length,          0                 )
        length       = (length > 0) ? length-1 : length
        startframe   = default( startframe,      0                 )
        endframe     = default( endframe+length, startframe        )
        fadein       = default( fadein,          0                 )
        fadeout      = default( fadeout,         0                 )
        head         = default( head,            startframe-fadein )
        tail         = default( tail,            endframe+fadeout  )
        head         = (head < 0  ) ? 0   : head
        head         = (head > all) ? all : head
        tail         = (tail < 0  ) ? 0   : tail
        tail         = (tail > all) ? all : tail
        fadein       = startframe-head
        fadeout      = tail-endframe

      #### PRESETS SECTION ###########################################################
      ####        NUMBER         NAME           FILTERCHAIN
        mod=( mod=="-1" || mod=="null"    ) ? """subtitle("")"""
         \ :( mod== "0" || mod=="freeze"  ) ? "FreezeFrame(startframe,all,startframe)"
         \ :( mod== "1" || mod=="light"   ) ? "fluxsmoothst()"
         \ :( mod== "2" || mod=="medium"  ) ? "fft3dgpu()"
         \ :( mod== "3" || mod=="heavy"   ) ? "dfttest()"
         \ :( mod== "4" || mod=="nuke"    ) ? "deblock().dfttest().blur(1.58)"
         \ :( mod== "5" || mod=="nothing" ) ? "blankclip()"
         \ :( mod== "6" || mod=="black"   ) ? "levels(255, 1, 255, 0, 0)"
         \ :( mod== "7" || mod=="white"   ) ? "levels(0, 1, 0, 255, 255)"
         \ :( mod== "8" || mod=="invert"  ) ? "levels(256, 1, 0, 0, 265)"
         \ :( mod== "9" || mod=="noise"   ) ? "addgrain(500,0,0)"
         \ :( mod=="10" || mod=="blur"    ) ? "blurmod(0,90)"
         \ :  mod ################# ADD OR CHANGE PRESETS ABOVE THIS LINE ############

      #### MAIN OPERATIONS ###########################################################
        f            =   eval( "clip2."  + mod          )
        unfiltered_a = c.trim( 0         , startframe-1 )
        filtered     = f.trim( head      , tail         )
        unfiltered_b = c.trim( endframe+1, all          )

      #### SPECIAL CASES #############################################################
        part = ( head==0     ) ? f.trim(0,endframe) :\
               ( head==1     ) ? dissolve( c.trim(0,-1), filtered, fadein) :\
               ( head==all-1 ) ? c.trim(0, all-1  )  \
                               : dissolve( unfiltered_a, filtered, fadein)

        full = ( head==0     ) && ( tail==0   ) ? f :\
               ( head==0     ) && ( tail==all ) ? f :\
               ( head==1     ) && ( tail==all ) ? part :\
               ( head==all   )                  ? c :\
               ( tail==all   ) ? dissolve(unfiltered_a,f.trim(head,all),fadein) :\
               ( tail==all-1 ) ? dissolve(part.trim(0,all-2),c.trim(all,all),fadeout)\
                               : dissolve(part,unfiltered_b,fadeout)
    RETURN full

    }

    function rg(clip "c"
              \, int "head", int "startframe", val "endframe", int "tail"
              \, val "mod" , val "mod_extra" , int "fadein"  , int "fadeout",int "length"   )
    {c.range(startframe, endframe, mod, fadein, fadeout, mod_extra, head, tail, length)}

    v1.0 (basic trim method):
    Spoiler :
    Code: Select all
    ########### Range() v1.0 by Phantasmagoriat #############
    function range(
          \  clip     c
          \, int     "startframe"
          \, int     "endframe"   
          \, string  "filterchain")
    {
    filterchain = default( filterchain, """deblock().dfttest().blur(1.58)""" )
    # default is a "quick fix" for areas that are hard to clean

    f = eval("c." + filterchain)

    c.trim(0,startframe-1)++\
    f.trim(startframe, endframe)++\
    c.trim(endframe+1,c.framecount())
    }


INSTALLATION: [the usual]
  • copy/paste the script into a .txt file,
  • [make sure you have file extensions showing on your computer]
  • rename to something like "Range().avsi"
  • put it in your avisynth plugins folder, usually:
    C:\Program Files\AviSynth 2.5\plugins or
    C:\Program Files (x86)\AviSynth 2.5\plugins


##############################
CHANGELOG:
Code: Select all
CHANGELOG:
v3.2 - Included rg() function with conveniently rearranged variables: rg( head,startframe,endframe,tail,mod )
v3.1 - Presets are now in a completely isolated code block. 
       - This makes it much easier to Save your own presets. Instructions are in the Docs. 
       - Conversely, you can delete the entire Presets Section in the code,
         and it won't affect range()'s functionality.
v3.0 - Changed [mod]/[mod_extra] into Val Types to allow four different inputs using the same variables:
          A. Filter_Chains (String)
          B. Preset_Names (String)
          C. Preset_Numbers (Integer)
          D. Replacement_Clips (Clip)
v2.9 - Changed default value for [mod] to "null" because of Clip Replacement
v2.8 - Added Preset_Numbers (as Integers)
     - Added more Presets:
          "freeze", "nothing", "black", "white", "invert", "noise", "blur"
v2.7 - Changed [filterchain] parameter to [mod]
     - Added [mod_extra] parameter
v2.6 - Implemented Clip Replacement
v2.5 - Implemented Filter Presets:
          "light", "medium", "heavy", "nuke"
v2.4 - Added special ranges:
          range(20,0 "filter()") filters frames 20 until the end.
          range( 0,0 "filter()") filters all frames
v2.3 - Added Boundary checking for those pesky special cases :P
v2.2 - Added Single-frame filtering
v2.1 - Added [Length] parameter
v2.0 - Implemented dissolve method to allow:
          [fadein]/[fadeout]/[head]/[tail] parameters
v1.0 - Range() made public

TODO:
Code: Select all
TODO:
- Test Everything (The provided examples were tested and worked fine though...)
- Possibly work with Animate() for even smoother transitions...
- Allow [mod] and [mod_extra] to be independent of one another
- Create still-image-replacement preset
- Possibly add/change presets?... I'll take suggestions :)
- Make an editing GUI using range() as a base function (never gonna happen... but I can dream...)

KNOWN BUGS:
Code: Select all
KNOWN BUGS:
v3.0 - No known bugs ATM.
       Hopefully I have addressed all the special cases from v2.0.
       Please report any bugs :)
v2.0 - Special cases when:
        * start == 0
        * start == 1
        * start == c.FrameCount() - 1
        * start == c.FrameCount()
        * start > c.FrameCount()
        * end < 0
        * end == 0
        * end == c.FrameCount() - 1
        * end == c.FrameCount()
        * end > c.FrameCount()
v1.0 - No known bugs ATM. Please report any ;)

DISCUSSION ON DOOM9:
http://forum.doom9.org/showthread.php?p ... ost1453670

##############################



Enjoy,


~Phan
Last edited by Phantasmagoriat on Sun Nov 07, 2010 4:49 pm, edited 13 times in total.
Image
Org Profile | AMVGuide | Phan Picks! | THE424SHOW | YouTube | "Galactic Escape"

"Effort to Understand; Effort to be Understood; to See through Different Eyes."
User avatar
Phantasmagoriat
 
Joined: 06 Feb 2006
Status: ☁SteamPunked≈☂

Re: Range() and Selective Filtering

Postby Scintilla » Mon Oct 25, 2010 5:11 pm

Wait. Didn't AbsoluteDestiny or Corran write a function about 5-6 years ago that works exactly like this, based on my own TweakScene(), and include it in the AMVapp as of version 2ish?

(I'm asking because I've never installed the AMVapp.)

http://www.a-m-v.org/forum/viewtopic.ph ... 01#p563701
ImageImage
:pizza: :pizza: Image :pizza: :pizza:
User avatar
Scintilla
(for EXTREME)
 
Joined: 31 Mar 2003
Location: New Jersey
Status: Quo

Re: Range() and Selective Filtering

Postby Zarxrax » Mon Oct 25, 2010 5:30 pm

Hmmm. I wonder why ApplyRange has such weird syntax to begin with. The best solution would be to get applyrange fixed in the avisynth source.
User avatar
Zarxrax
 
Joined: 01 Apr 2001
Location: Concord, NC

Re: Range() and Selective Filtering

Postby Phantasmagoriat » Mon Oct 25, 2010 5:37 pm

Scintilla wrote:Wait. Didn't AbsoluteDestiny or Corran write a function about 5-6 years ago that works exactly like this, based on my own TweakScene(), and include it in the AMVapp as of version 2ish?

(I'm asking because I've never installed the AMVapp.)

http://www.a-m-v.org/forum/viewtopic.ph ... 01#p563701
wow, I wasn't even here 6 years ago -_-

I suppose the syntax is the same, but mine's still better :nose: because:
-The code is easier to read
-It doesn't use unnecessary if/then statements EDIT: They are necessary for special cases
-It has a default filter chain
-It will eventually have fadein/fadeout parameters
-It will eventually include clip replacement


Zarxrax wrote:Hmmm. I wonder why ApplyRange has such weird syntax to begin with. The best solution would be to get applyrange fixed in the avisynth source.
I suppose, but the developers are probably working on more important stuff -_-
Last edited by Phantasmagoriat on Thu Nov 04, 2010 12:28 pm, edited 1 time in total.
Image
Org Profile | AMVGuide | Phan Picks! | THE424SHOW | YouTube | "Galactic Escape"

"Effort to Understand; Effort to be Understood; to See through Different Eyes."
User avatar
Phantasmagoriat
 
Joined: 06 Feb 2006
Status: ☁SteamPunked≈☂

Re: Range() and Selective Filtering

Postby Mister Hatt » Mon Oct 25, 2010 10:59 pm

>avisynth developers
>working on ANYTHING
Aha no.
Mister Hatt
 
Joined: 25 Dec 2007
Status: better than you

Re: Range() and Selective Filtering

Postby Phantasmagoriat » Mon Oct 25, 2010 11:11 pm

Don't be so pessimistic,
they'll have 64bit, mt, cross-platform in no time 8-)
Image
Org Profile | AMVGuide | Phan Picks! | THE424SHOW | YouTube | "Galactic Escape"

"Effort to Understand; Effort to be Understood; to See through Different Eyes."
User avatar
Phantasmagoriat
 
Joined: 06 Feb 2006
Status: ☁SteamPunked≈☂

Re: Range() and Selective Filtering

Postby mirkosp » Tue Oct 26, 2010 7:43 am

Phantasmagoriat wrote:they'll have 64bit

Already out, but filters compatibility and overall stability makes it not recommended
mt

There are already mt builds of avisynth, but using mt is far from stable, so scripts will crash easily
cross-platform

Spoiler :
:rofl: :rofl: :rofl: :rofl: :rofl:

in no time 8-)

Feel free to keep dreaming about avs 3... :asd:
Image
User avatar
mirkosp
MODkip
 
Joined: 24 Apr 2006
Location: Gallarate (VA), Italy
Status: (」・ワ・)」(⊃・ワ・)⊃

Re: Range() and Selective Filtering

Postby Phantasmagoriat » Tue Oct 26, 2010 11:39 am

mirkosp wrote:Feel free to keep dreaming about avs 3... :asd:
Image
Image
Org Profile | AMVGuide | Phan Picks! | THE424SHOW | YouTube | "Galactic Escape"

"Effort to Understand; Effort to be Understood; to See through Different Eyes."
User avatar
Phantasmagoriat
 
Joined: 06 Feb 2006
Status: ☁SteamPunked≈☂

Re: Range() and Selective Filtering

Postby Phantasmagoriat » Wed Oct 27, 2010 2:36 pm

Code updated to v2.0 to include fadein/fadeout :)
Image
Org Profile | AMVGuide | Phan Picks! | THE424SHOW | YouTube | "Galactic Escape"

"Effort to Understand; Effort to be Understood; to See through Different Eyes."
User avatar
Phantasmagoriat
 
Joined: 06 Feb 2006
Status: ☁SteamPunked≈☂

Re: Range() and Selective Filtering

Postby mirkosp » Wed Oct 27, 2010 3:52 pm

Phantasmagoriat wrote:Code updated to v2.0 to include fadein/fadeout :)

Sound like WIN to me. :dino: :dino:
Image
User avatar
mirkosp
MODkip
 
Joined: 24 Apr 2006
Location: Gallarate (VA), Italy
Status: (」・ワ・)」(⊃・ワ・)⊃

Re: Range() and Selective Filtering

Postby Mister Hatt » Sat Oct 30, 2010 11:19 pm

Phantasmagoriat wrote:Don't be so pessimistic, they'll have 64bit, mt, cross-platform in no time 8-)
As an avs developer, lolololololol.
Mister Hatt
 
Joined: 25 Dec 2007
Status: better than you

Re: Range() and Selective Filtering [now with fadein/fadeout!]

Postby Phantasmagoriat » Tue Nov 02, 2010 8:32 pm

Alrighty, I've made a *TON* of changes to range() over the last couple days ^__^
The major ones being:
- The old parameter [filterchain] is now called [mod] which stands for "modification" because it accepts other Types of input now.
- Clip Replacement
- A place in the code for Presets
- Boundary Checking (for the special cases brought up on doom9)

So:
- Code updated to v3.0
- Documentation updated to reflect all the new features
- (Now, the first post is HUGE because of all the extra functionality!)
- see the Changelog and new Docs for full details

Code: Select all
CHANGELOG:
v3.0 - Changed [mod]/[mod_extra] into Val Types to allow four different inputs using the same variables:
          A. Filter_Chains (String)
          B. Preset_Names (String)
          C. Preset_Numbers (Integer)
          D. Replacement_Clips (Clip)
v2.9 - Changed default value for [mod] to "null" because of Clip Replacement
v2.8 - Added Preset_Numbers (as Integers)
     - Added more Presets:
          "freeze", "nothing", "black", "white", "invert", "noise", "blur"
v2.7 - Changed [filterchain] parameter to [mod]
     - Added [mod_extra] parameter
v2.6 - Implemented Clip Replacement
v2.5 - Implemented Filter Presets:
          "light", "medium", "heavy", "nuke"
v2.4 - Added special ranges:
          range(20,0 "filter()") filters frames 20 until the end.
          range( 0,0 "filter()") filters all frames
v2.3 - Added Boundary checking for those pesky special cases :P
v2.2 - Added Single-frame filtering
v2.1 - Added [Length] parameter
v2.0 - Implemented dissolve method to allow:
          [fadein]/[fadeout]/[head]/[tail] parameters
v1.0 - Range() made public

Enjoy,

[and yes, let me know if you find any bugs too :P ]
Image
Org Profile | AMVGuide | Phan Picks! | THE424SHOW | YouTube | "Galactic Escape"

"Effort to Understand; Effort to be Understood; to See through Different Eyes."
User avatar
Phantasmagoriat
 
Joined: 06 Feb 2006
Status: ☁SteamPunked≈☂

Re: Range() v3.0 [Now with Clip Replacement and Presets!]

Postby Zarxrax » Tue Nov 02, 2010 10:44 pm

Are the presets really necessary?
I think they add unnecessary complexity to the function.
Also, every single preset is quite simple. There's really no advantage to using the preset than just writing the function directly, except you have to memorize what all the presets are, when people probably already know how to use the original filters anyways.
User avatar
Zarxrax
 
Joined: 01 Apr 2001
Location: Concord, NC

Re: Range() v3.0 [Now with Clip Replacement and Presets!]

Postby Phantasmagoriat » Tue Nov 02, 2010 11:41 pm

Well, no the presets aren't really necessary, but they do add convenience.

I mean, if I want a section to fade to solid black, I can just type:
Code: Select all
range(1200,1300, "black", 24,24)

instead of remembering what values are required for levels, and in what order:
Code: Select all
range(1200,1300, "levels(255, 1, 255, 0, 0)", 24,24)
Using the preset number 6, is optional, so you don't have to memorize anything as long as you can remember a name like "black"

But what I really wanted to do was create a block of code in the script where you can put your own presets. Particularly with "light", "medium", and "heavy" which you can change to whatever you want. The defaults are just suggestions. I want to encourage people to add/change presets in the main script with their favorite filtering methods, so they just have to add them once using an easily-to-remember name, save the script, and then call them any time they want later. You are right, most of the presets are simple enough to be called regularly, but since there is a dedicated block of code for presets (labeled ## PRESET RECOGNITION ##), it's really easy to set your own ones for more complicated filterchains.

It's basically a way to put all your favorite filterchains in one place.
Image
Org Profile | AMVGuide | Phan Picks! | THE424SHOW | YouTube | "Galactic Escape"

"Effort to Understand; Effort to be Understood; to See through Different Eyes."
User avatar
Phantasmagoriat
 
Joined: 06 Feb 2006
Status: ☁SteamPunked≈☂

Re: Range() v3.1 [Now with Clip Replacement and Presets!]

Postby Phantasmagoriat » Wed Nov 03, 2010 2:59 pm

Yet another update:
Code: Select all
CHANGELOG:
v3.1 - Presets are now in a completely isolated code block.
       - This makes it much easier to Save your own presets. Instructions are in the Docs.
       - Conversely, you can delete the entire Presets Section in the code,
         and it won't affect range()'s functionality.

-amongst some extra code cleaning, I also condensed the docs. It's still not as brief as I want it, but I can't see it getting any shorter than that.
Image
Org Profile | AMVGuide | Phan Picks! | THE424SHOW | YouTube | "Galactic Escape"

"Effort to Understand; Effort to be Understood; to See through Different Eyes."
User avatar
Phantasmagoriat
 
Joined: 06 Feb 2006
Status: ☁SteamPunked≈☂

Next

Return to Footage Help

Who is online

Users browsing this forum: No registered users and 0 guests