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 1st April 2018, 21:08   #1  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Duplicity2/DropDeadGorgeous v2.13 - Dupe Tool - 17 Nov 2018

Post #1 of 2.
Code:
/*
    Duplicity2(), v2.13, by StainlessS @ Doom9:- https://forum.doom9.org/showthread.php?t=175357

    A two faced scheming and double dealing [on your behalf] dupe tool.

    Three modes of operation,
      0) Write duplicate Frames file only (as single frames or ranges).
      1) Replace duplicates with exact duplicates. (Can also write Frames file).
      2) Replace duplicates with Interpolated or Blended frames (control via MaxDuplen and MaxInterp). (Can also write Frames file).

    Req:-
      RT_Stats v2.00_Beta_11 + CallCmd (c) StainlessS,
      GSCript, Grunt, (c) Gavino,
      MaskTools2, MvTools2, (c) Manoa/Fizick/Pinterf & Others (Pinterf Versions).
      RemoveGrain, (c) Kassandro.

      GScript not needed if Avs+ [(c) Ultim, Pinterf and others.].
      If CallCmd available then will AutoDelete DBase on clip closure, otherwise requires manual deletion.

    ColorSpace:- All v2.6 standard PLANAR colorspaces except YV411, no support for YUY2, RGB24 or RGB32.

    Function Duplicity2(clip c,"Mode"=0,Float "ThG"=1.0,Float "ThB"=ThG*2.0, Int "ThP"=64,Float "IgP"=0.0,Int "ThK"=7,
        \ Int "MaxDupLen"=9,Int "LagMax"=MaxDupLen,Int "MaxInterp"=Min(9,MaxDupLen),
        \ int "BlkW"=64,int "BlkH"=BlkW,int "OLapX"=BlkW/2,Int "OLapY=BlkH/2",
        \ Int "X"=0,Int "Y"=0,Int"W"=0,Int "H"=0,Float "CW"=0.0,Bool "ChromaI"=False,Bool "AltScan"=False,
        \ Int "SPad"=16, Int "SSharp"=1, Int "SRFilter"=4,                             [* MSuper          *]
        \ Int "ABlkSize"=16, Int "AOverlap"=4,   Int "ASearch"=3,Int "ADct"=0,         [* MAnalyse        *]
        \ Int "RBlkSize"=8,  Int "ROverlap"=2,   Int "RthSAD"=100,                     [* MRecalculate    *]
        \ Float "Iml"=200.0, Bool "IBlend"=True, Int "IthSCD1"=400, Int "IthSCD2"=130, [* MFlowInter      *]
        \ Int "OthSCD1"=400,Int "OthSCD2"=130,                                         [* Dupe Detect Override @ Scene Change *]
        \ String "OverRide"="",String "Frames"="Frames.txt",Bool "Ranges"=True,Bool "FrameAsRange"=False,
        \ Bool "Show"=True,Bool "Verb"=True,Bool "ShowBlk"=True,Bool "Dim"=True,Bool "ShowDot"=False,
        \ Bool "InterpFast"=True,String "DBase"=""
        \ )

    Duplicity2() uses 3 RT_Stats measurement functions, RT_FrameDifference(), RT_FrameMovement(), and RT_LumaPixelsDifferent().
        the first two may difference using either luma only, or with a combined weighted chroma difference. Also see CW,
    and ChromaI args. RT_LumaPixelsDifferent() differences luma only.

        DeDuppers use some method to determine if a frame is a duplicate of its predecessor, a typical measuring method might be
    RT_FrameDifference (average absolute difference per pixel), unfortunately the result of such measure may be due to a small
    frame global change (lots and lots of pixels change by a small amount), or a smaller number of pixels change by a
    larger amount, both these cases could produce the exact same result. Another case may be that of a very small number of
    pixels change by a very large amount (eg a person blinks an eye with remainder of frame static) and such measure might seem
    to be a duplicate as it could produce much smaller numbers than a frame global change of a small amount.

        Duplicity2() uses a triple measurement system (maybe it should be called Triplicity), Primary measurement (RT_FrameDifference)
    to detect frames 'Unique' to their immediate predecessor (large or 'frame Global' changes), and second and third methods to
    determine if 'Non-Unique' frames are either 'Low Motion' or 'Duplicate' frames. The second method is a block differencing
    method (RT_FrameMovement) where it splits the frame up into BlkW by BlkH blocks and finds the maximum average pixel difference
    of any one block. The third measurement method is RT_LumaPixelsDifferent (result 0.0->255.0 where 255.0 is equivalent to 100.0%,
    user args for this method actually require Duplicity2 arg 'IgP' in range 0.0->100.0%, and also show results in range 0->100.0%).
        RT_LumaPixelsDifferent, compares frames and shows percent of pixels whose corresponding absolute luma pixel difference is
    greater than Int arg 'ThP', if this percent difference is greater than 'IgP', then it is deemed to be a 'Low motion' frame and if
    less or equal to 'IgP' then is a duplicate ('IgP' can be 0.0, meaning any pixels at all with difference greater than 'ThP' is a
    'Low Motion' Frame). Where both 'ThP' and 'IgP' are 0 and 0.0 respectively, will show percentage of pixels that are not Exactly the same.
    'IgP' could be set to 0.0 (Default) in which case the function is governed solely by any pixel differences exceeding 'ThP', or can set
    'IgP'= eg 0.001% meaning the it will disregard as noise 1 pixel difference exceeding 'ThP' in every 100,000 pixels
    [eg 1 pixel in every 316x316 region]. It is probably easiest to always use IgP of 0.0 and only adjust ThP.

    The function examines the DBase to determine if status for current frame is already known, if not already known then,
    the function determines if the current frame is a 'Unique' frame or not (via 'ThG' RT_FrameDifference to predecessor), if Unique,
    then the job is done and is considered a Non-Duplicate, these Unique frames are marked in a DBase as Unique. If a frame is
    'Non-Unique', then the function scans both backwards and forwards looking for 'Unique Start' and 'Unique End' frames (and if
    necessary, marking them in DBase). This Backwards/Forwards scanning permits jumping around in the clip for perusal and getting
    exact same results as if travelling forwards only (even backwards traversal only, should work just fine). When the
    'Unique Start' and 'Unique End' frames are established, we then know the extent of the unknown (unvisited) frames, and can scan
    and measure those with the second and third measurement methods (RT_FrameMovement and RT_LumaPixelsDifferent) to determine
    Low Motion/Dupe status. When determining Low Motion/Dupe status, we compare with an 'Anchor Frame', which at the beginning of a
    'Non-Unique' sequence is the 'Unique Start' frame. When scanning a non-unique sequence the 'Anchor Frame' is the predecessor frame
    to the very first frame in the current sub sequence of the 'Non-Unique' sequence, so potential duplicates are not necessarily
    compared with their immediate predecessor. When a frame is determined to be 'Low Motion' (not a dupe), any detected duplicates are
    written to the DBase and also to the output Frames file, and it switches to detecting sequences of 'Low Motion' frames within the
    'Non-Unique' sequence. On each detected 'Low Motion' frame, the Anchor frame for the next frame (whether it be another
    'Low Motion' frame or a new 'Dupe' frame) will be switched to that newly detected 'Low Motion' frame. With this method,
    all frames BETWEEN (but excluding) the 'Unique Start' and 'Unique End' in the 'Non-Unique' sequence are detected as perhaps
    multiple 'Low Motion' and 'Duplicate' sub sequences.
      Setting LagMax arg to some low number (min 1), will limit distance of the Anchor frame prior to the current frame, eg setting
    LagMax=1, would always do LoMo/Dupe compare with the current frame and its predecessor. A LagMax greater than 1 allows better detection
    of Low-Motion frames where there is only very slow creeping movement in the sequence.

      The above method allows for reasonably fast processing, where a 'unique' frame is encountered [where it is clearly different from
    its predecessor] but where not so clear, will examine the LoMo/dupe suspect frames more closely. ThG sets the boundary between
    'Unique' frames and non unique, and so has some effect on speed, setting too high for your source will slow processing speed as many
    non dupes will be examined more closely, and setting ThG too low for your source, may increase speed but may miss duplicates in noisy
    sources (probably better to set too high than too low).

      Although you might be able to scan backwards and get same detections, results are written to the Frames file in visited sequence and
    you should NOT jump about whilst writing the final frames file. Also, this is a Multi-Instance script, can use multiple instances
    at the same time (view side by side metrics) but you should really choose a unique 'Frames' filename for each instance.

    Args:-
        Mode,         Default 0, (Range 0->2)
                        0) Write Frames file only (where Frames file="" then not written so only Show=true does anything).
                        1) Make duplicate sequences Exact Dupes.
                        2) Interpolate/Blend Duplicates (depends upon MaxDupLen and MaxInterp).

        ThG,          Default 1.0 (0.0 < ThG <= 255.0) Suggest 1.0, never below 0.5.
                      Primary Global Unique detect threshold. [current_frame-1 <-> current_frame].
                      If using 255.0 will likely scan all of the way to both Start and End frames, and then
                      detect LoMo/Dupe frames of entire clip using the 2nd & 3rd detection methods, will seem to pause for a long time,
                      dont do it (no error if using daft numbers).

        ThB,          Default Float ThG * 2.0, (Range ThG <= ThB < 255.0, Suggested about 1.5->3.5).
                      Secondary Local LoMo/Dupe Block detect threshold, [Anchor<->current_frame]
                      Tune for source and Block Size. (For smaller block size, just by random chance there may be several noisy pixels
                      in duplicate frame block, that produce considerably higher metric than most other blocks).

        ThP,          Default Int 64. (Advised Range ThB < ThP <= 64, or 255=OFF)
                      Ternary Local [single pixel] LoMo/Dupe detect threshold,  [Anchor<->current_frame].
                        On a test with 256 artificial generated 640x480 identical frames of random coloured pixels, encoded at
                      MeGUI AVC CRF 23.0(default), RT_LumaPixelsDifferent(Thresh=1) found no frames where any single pixel was
                      different by more than 1 luma level when compared with the first encoded frame from that sequence. Mpeg2
                      and flv might not fare as well. This test was on a totally clean artificial source without artefacts
                      and such, you will likely need considerably higher values of ThP than 1.
                        I have seen multiple clips exhibiting some kind of minute (perhaps sub pixel) frame shift (both horizontal and
                      vertical) where frame should have been an exact duplicate, no idea to the cause.
                        This setting is an additional knob to twiddle, and you could turn it off and rely on ThG and ThB
                      completely [ThP=255, turns off]. The default of 64 and the below setting IgP=0.0, will consider any single pixel
                      with a luma difference of 64 or more, to be a non dupe, unfortunately any clip having above mentioned sub pixel
                      shifting at dupe frames, may need a high setting to not trigger a lomo detection, I have not I think
                      seen so far any clip that needed ThP more than about 48. 64 might seem ridiculously high but if frames are shifted,
                      then a little preposterous-ness is likely necessary, in a true non-dupe, there will most usually be at least
                      one pixel that differs in luma by more than 64.
                      We have thusly decided to make the default an emergency fallback detect value of 64, the user may decide to lower
                      this value or indeed turn it off completely[ThP=255].

        IgP,          Default 0.0, (Range 0.0 <= IgP < 100.0). Percent noise threshold for Ternary Local [pixel] LoMo/Dupe Detect,
                      Note, default 0.0% means that any frame with any single pixel with abs luma difference greater than ThP will
                      be detected as LoMotion.

        ThK,          Default = 7, (0 <= ThK <= 255). 0 = K Overrides off.
                      If RT_YPlaneMinMaxDifference(Threshold=0.2) of current_frame is less ThK then will Override any detection,
                      ie black (or narrow luma range) frames are ignored as not duplicates.
                      [Threshold=0.2 ignores as noise, 1 in 500 extreme pixels when establishing loose minimum and loose maximum & luma range].

        MaxDupLen,    Default 9. Maximum permitted detection length of duplicate run, If detected dupe run exceeds this setting,
                      then it is totally ignored and presumed to be a static scene.

        LagMax,       Default MaxDupLen. Setting to a low number (min 1) will limit the distance of the Anchor frame prior to
                      the current frame, eg setting LagMax=1, would always do LoMo/Dupe compare with the current frame and its
                      predecessor. Maybe best left alone.

        MaxInterp,    Default Min(MaxDupLen,9), (Range 0->9). For Mode=2(Interpolate/Blend mode) only. Max length of interpolated frames.
                        Sequences longer than this but less or equal to MaxDupLen will be blended instead.

        BlkW,         Default 64, 8 <= BlkW, Mod 2, Best Mod 4. Width of Blocks for Secondary Metric.
        BlkH,         Default BlkW, 8 <= BlkH, Mod 2, Best Mod 4. Height of Blocks for Secondary Metric.
        OLapX,        Default BlkW/2, 0 <= OLapX <= BlkW/2, Horizontal block overlap for Secondary Block metric.
        OLapY,        Default BlkH/2, 0 <= OLapY <= BlkH/2, Vertical block overlap for Secondary Block metric.
                         Where CW==0.0 and AltScan==True, might try eg OLapY=(BlkH/2)-1, where might be faster due to AltScan and,
                      also in overlapped 'Y_Block' scan will then scan alternate scanlines that were not scanned in previous non overlapped
                      scan (if that makes any sense, ie even scanlines sampled in first block, odd lines sampled in overlapped block scan).

        X,Y,W,H,      All Default 0, Coordinates of test area, as in crop (all 0 = full frame).
                      The x,y coords will be rounded up mod4, and w,h coords rounded down mod 4.
                      Ignore eg animated logo.

        CW            [ChromaWeight] Default 0.0. (0.0 <= CW <=1.0).
                      For Primary Frame Global and Secondary Block Mode difference detection, weighting of combined chroma diff to luma diff.
                        If required, recommend about 0.1, where difference would be weighted as
                        TotDif = ((1.0 - CW) * YDif) + (CW * ((UDif+VDif)/2.0))
                      Suggest always CW=0.0 where Night Capture.
See Post #22 for current script

Zip Includes DropDeadGorgeous()

For Zip, See Mediafire in sig below this post, or SendSpace.
__________________
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; 17th November 2018 at 15:26. Reason: Update
StainlessS is offline   Reply With Quote
Old 1st April 2018, 21:08   #2  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Post #2 of 2.
Code:
        ChromaI       Default False, Primary + Secondary Block Mode setting. YV12 Only(otherwise ignored), Set True if Interlaced Chroma.
                       Also ignored if CW=0.0. DO NOT use Interlaced material with Mode=2(Interpolate/Blend).

        AltScan       Default False. Secondary (only) Block Mode setting. Scans only every other scanline of blocks.

                       MvTools2 Args, for Interpolation.
                       MSuper args:
        SPad,          Default 16,   See MvTools MSuper(hpad=8,vpad=8) [We use same for both].
        SSharp,        Default  1,   See MvTools MSuper(sharp=2)
        SRFilter,      Default  4,   See MvTools MSuper(rfilter=2)

                       MAnalyse args:
        ABlkSize,      Default 16,   See MvTools MAnalyse(BlkSize=8,BlkSizeV=8) [We use same for both].
        AOverLap,      Default  4,   See MvTools MAnalyse(OverLap=0)
        ASearch,       Default  3,   See MvTools MAnalyse(Search=4)
        ADct,          Default  0,   See MvTools MAnalyse(Dct=0). Using other than default value can be VERY slow.

                       MRecalculate args:
        RBlkSize,      Default   8,   See MvTools MRecalculate(BlkSize)
                         NOTE, RBlkSize = 0 Will Switch OFF MRecalculate, probably a bit faster at possible expense of quality.
        ROverlap,      Default   2,   See MvTools MRecalculate(Overlap)
        RthSAD,        Default 100,   See MvTools MRecalculate(thSAD=200)

                       MFlowInter args:
        Iml,           Default 200.0, See MvTools MFlowInter(ml=100.0)
        IBlend,        Default True,  See MvTools MFlowInter(Blend=True). Blend or copy frame at scene change.
        IthSCD1,       Default 400,   See MvTools MFlowInter(thSCD1=400) :  (0 < IthSCD1 <= (8*8)*255)
        IthSCD2,       Default 130,   See MvTools MFlowInter(thSCD1=130) :  (0 < IthSCD1 <= 255)
                       Threshold which sets how many blocks have to change for the frame to be considered as a
                       scene change. It is ranged from 0 to 255, 0 meaning 0 %, 255 meaning 100 %.
                       Default is 130 (which means 51.0%).
                       Used by MvTools2 MFlowInter during interpolation.

                       Duplicate detection Override due to scene change following dupes, args: (Modes 0 & 2 only)
        OthSCD1,       Default 400. as MVTools MSCDetection arg. (0 < OthSCD1 <= (8*8)*255). See MvTools2.
        OthSCD2,       Default 130. as MVTools MSCDetection arg. (0 < OthSCD2 <= 255)
                         These two thresholds govern whether frames either side of duplicate sequence are determined to be
                       from the same scene, if not from same scene then duplicate detection is overridden and 'E' flag is set in metrics,
                       on what would have been the duplicate sequence.
                       NOTE, If OthSCD1 >= 8*8*255 or OthSCD2 >= 255 then switches OFF scene change testing, will NOT override
                       any duplicate detections (will likely result in blended scene transitions where frame after dupes is from
                       a different scene).
                       NOTE, For Mode=1(Replace dupes with exact dupes), scene change detection is omitted as no blending nor
                       interpolation is done and so no blending across scene change is possible and so not necessary to detect.

        OverRide,     Default "" (ie not used).
                      Provide list of frames/ranges to OverRide as NOT DUPLICATES, can give filename or string of Overrides, eg
                        ".\Overrides.txt", text file "Overrides.txt" in current directory containing something like
                        the contents between to ############ lines.
                            ############
                                100,199         # Frames 100 to 199 overridden (as NOT dupes)
                                300,-100        # Frames 300 to 399 overridden (100 frames)
                                500             # Frame 500 Overridden.
                            ############
                        Or Preceded in string by "*" Star or Asterisk character, then remainder of string as contents of above file example.

        Frames,       Default "Frames.txt", Frames filename for output, ("" will not write Frames file).
        Ranges,       Default True (True=Write comma separated frame ranges to Frames file, else single frames only).
        FrameAsRange, Default False. If Ranges=True and FrameAsRange=default false, and single frame, then writes single frame number and
                      not range. If Ranges=True and FrameAsRange=True then writes single frame as range eg '23,23' for frame 23.

        Show,         Default True, Show metrics.
        Verb,         Default True, Additional Verbose Metrics when Show=True (Verbose Metrics not shown below).
        ShowBlk,      Default True. If true (and Show=True), then mark block on frame where secondary Block Detections occur.
                      Motion detection shown in Orange/Yellow, and greatest non 0.0 non detection block shown in Green.
                      Perhaps of use in tuning for ThB.
        Dim,          Default True. If True (AND Show=True AND Mode==0), then dims any outer area excluded by X,Y,W,H args.
                      When Mode!=0 then Dim is Ignored [ie only valid when Mode=0(Write Frames file mode)], ignored when modifying
                      source frames ie Mode=1(Make dupes exact dupes) or Mode=2(Interpolate dupes).
                      Perhaps switch to Mode=0, to examine X,Y,W,H, coords correct.
        ShowDot,      Default False. If Show AND ShowDot both True, then switches OFF Show and instead shows
                      an Asterisk/Star in top left corner of duplicates detections (after frame mods eg Exact copy or Interpolation etc).

        InterpFast,   Default True. If True, then Interpolation clips are pre-calculated, if false then calculations done in real time.
                      Pre-Calc clips a bit (maybe 10%) faster, but perhaps not quite as good quality.
                      NOTE, If experiencing Out Of Memory errors, then try switch to InterpFast=False.

        DBase,        Default "", If named DBase suppled, then is not deleted on clip closure.
                          [ If name supplied, result DB may be re-used by other scripts, eg DropDeadGorgeous() function ].
                      NOTE, If using multiple instances and named DBase, then give each DBase as different name.

            Metrics show eg
                "nnnn] OKSE:GBP:ULD {1/32 : L1/5 : uS=12 : uE=45}"
                "pG= p.gggggg  : pB= p.bbbbbb : pP%= p.pppppp"
                "aG= a.gggggg  : aB= a.bbbbbb : aP%= a.pppppp
                "{K=200 : a=567  : Lag=1}"

            Where,
                'nnnn'          = current frame
                'OKSE:GBP:ULD'  = Flags highlighted where relevant.
                                  OKSE, OverRide flags (overridden to not duplicates),
                                    O=User OverRide, (via OverRide arg)
                                      User_Overrides are set in DBase to 'Not A Duplicate', prior to scanning and cannot be changed via the
                                      detection scan.
                                    K=Low Luma Range Override (black or low luma range frames not detected as dupes), via ThK arg.
                                      K_Override via ThK can override all of the other conditions (except User Override as above).
                                    S=Static Scene OverRide, via MaxDupLen arg.
                                      Static_OverRide flagged if detected as Duplicate run but exceeds MaxDupLen.
                                    E=End+1 of current dupe sequence is change of scene, so if Mode=2 then Interpolation
                                      or Blending is skipped for that dupe sequence.
                                      NOTE, Mode=0(Write Frames), also processes scene change detection, unless disabled via eg OthSCD2=256.
                                      Mode 1(replace with exact dupes), skips scene change detection as no purpose to it.

                                  GBP, Motion detection reason flags,
                                    G=Frame Global detection via Primary detector. [Orange, Unique to current - 1]
                                    B=Block detection via Secondary Detector.      [Orange, motion between current and anchor in LoMo seq]
                                    P=Pixel detection via Ternary Detector.        [Orange, motion between current and anchor in LoMo seq]

                                  ULD, Current frame detection Status.
                                    U=Unique Frame, detect via ThG
                                    L=Low_Motion Frame, detect via ThB, ThP and IgP.
                                    D=Dupe Frame, not Unique or LoMotion.

                '1/32'          = The 1st of 32 frames in a 'Non Unique', perhaps mixed LoMo/Dupe sequence.
                'L1/5'          = The 1st of 5 frames of Low Motion sub sequence of the 'Non Unique' sequence
                                    D1/5=1st of 5 dupes.
                                    I1/5=1st of 5 dupes, Where Mode=2, and Interpolated.
                                    B1/5=1st of 5 dupes, Where Mode=2, and Blended.
                                    E4/7=4th of 7 dupes that were not processed because frame after dupes is from a different scene.
                                      Will not occur when Mode=1 (replace with exact dupes).
                                    K3/4 3rd of 4 K_Override frames.
                                    S2/99 2nd of 99 Static_OverRide frames.

                'uS=12 : uE=45'   Unique Start and End frames, 'Non Unique' LoMo/Dupe sequence is between these two frames (exclusive).

                'pG= p.gggggg.' = Primary 'Unique Frame' Frame difference metric between current and Predecessor frame.
                'pB= p.bbbbbb.' = Secondary 'Low Motion/Dupe' Block difference metric between current and Predecessor frame. (info only)
                'pP= p.pppppp.' = Ternary 'Low Motion/Dupe' Pixel difference metric between current and Predecessor frame. (Info Only)
                'aG= a.gggggg.' = Primary Unique Frame difference metric between current and Anchor frame in Non Unique sequence.
                'aB= a.bbbbbb.' = Secondary 'Low Motion/Dupe' Block difference metric between current and Anchor frame in Non Unique sequence.
                'aP= a.pppppp.' = Ternary 'Low Motion/Dupe' Pixel difference metric between current and Anchor frame in Non Unique sequence.
                'K=200'         = Current_frame RT_YPLaneMinMaxDifference(Threshold=0.2), Unique or Non Unique sequences.
                'a=567'         = Comparison Anchor frame number in Non Unique sequence.
                'Lag=1'         = Frame Count between current frame and Anchor Frame (Lag=1, Anchor is Predecessor) in Non Unique sequence.

            For 'Unique' frames, Only shows "nnnn] OKSE:GBP:ULD" on top line and also the 2nd line & 'K=2', 'Low Motion/Dupe' show the remainder.
*/
Greatest low motion block detected shown by Yellow rectangular marker. Dimm'ed area shows X,Y,W,H excluded area.
Just inside that block marker @ top LHS corner, there is an almost invisible fox (the light in doorway is due to motion detector).
Difficult scene, shimmering road due to raining.


And again in frame where fox (below doorway) after activating motion sensor (sniffing at something).



See Post #22 for script

EDIT: Posted elsewhere about DropDeadGorgeous2():
Quote:
Originally Posted by StainlessS View Post
Duplicity2(), is a dupe Detector, Dupe frame list creator, Dupes replaced with exact dupes, Dupes replaced with interpolated frames + DBase of dupes creator.
DropDeadGorgeous2() uses Duplicity2 DBase to do the almost impossible, smoothing out jerking clips (where source has jerks and dupes, much better than simple interpolation of dupes).
DropDeadGorgeous2 can also [EDIT: help] up framerate (eg 25.0 -> 29.97) keeping all source frames verbatim, and creating smooth result
[squeezes out dupes, where are replaced by interpolated frames between frames of most movement - non dupe frames are relocated between jerk interpolations and dupes to squeeze out dupes (hard to explain it)].

EDIT: Perhaps this explains better
Code:
abcXdefgDDhi       Src, Two dupe [D] frames preceded (within a set range) by a jerk frame. Jerk frame X, has greater motion to its predecessor than do d, e, f, or g.
abc12Xdefghi       DropDeadGorgeous dupe removal and Jerk interpolation

Lower case non dupe non Jerk
X     = Frame of greatest motion from predecessor (Jerk)
D     = Dupe Frames
Digit = Interpolated frames between X and its predecessor c (Same Count as D dupes)
# below assumes that 2 frames both dropped and duped, similar where 1 frame dropped. [2 frames dropped is extreme and more difficult case, we describe the more difficult]
Code:
abc12Xdefghi  # How it should have been in capture, 1,2 will both be dropped, X is jerk frame following frames that will be dropped.
abcXdefgDDhi  # when 1,2 dropped by CAP device, and DD dupes inserted.
abc12Xdefghi  # DropDeadGorgeous() fixed. (1,2 are both interpolated frames {with c and X as interp source frames}, original 1,2 GONE $4E4 [forever])
__________________
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; 28th January 2024 at 21:28. Reason: Update
StainlessS is offline   Reply With Quote
Old 1st April 2018, 21:09   #3  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Script Removed. See post #22 for script.


@ Motenai Yoda,
I see you on-line there, give a whirl please, took some time to do, sorry. Somewhat better (I hope) than previous posted in FrameSel thread. Still need use Frames rather than ranges with the other script, I'll get down to doing it as a FrameSel plug mod soon.
@ Orum, hope you can do better than this with your new plug in devs forum, good luck.
@ JohnMeyer, I know that you aint ever completely happy with anything video related, but maybe this tickles your fancy, just a tad
__________________
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; 27th September 2018 at 01:34.
StainlessS is offline   Reply With Quote
Old 1st April 2018, 21:10   #4  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
SPARE for Growth
__________________
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 ???
StainlessS is offline   Reply With Quote
Old 1st April 2018, 21:23   #5  |  Link
Motenai Yoda
Registered User
 
Motenai Yoda's Avatar
 
Join Date: Jan 2010
Posts: 709
Sorry, I wasn't avoiding to try previous one, just there is something dependency related I have to fix.
btw CallCmd work on x64 avs+?
__________________
powered by Google Translator

Last edited by Motenai Yoda; 1st April 2018 at 21:27.
Motenai Yoda is offline   Reply With Quote
Old 1st April 2018, 21:28   #6  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Quote:
CallCmd work on x64 ?
Not yet, I'll make it work.
Can just comment out that line, delete file by hand.

EDIT: 2nd last line of script function, ie
Code:
CallCmd(close=RT_String("""CMD /C chcp 1252 && del "%s" """,DB), hide=true, Synchronous=7)  # Auto delete DBase file on clip closure.
__________________
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; 1st April 2018 at 21:30.
StainlessS is offline   Reply With Quote
Old 1st April 2018, 22:52   #7  |  Link
Motenai Yoda
Registered User
 
Motenai Yoda's Avatar
 
Join Date: Jan 2010
Posts: 709
you should delete those last 2 lines.
also it throw a "Script error: There is no function named 'GScript'."
__________________
powered by Google Translator
Motenai Yoda is offline   Reply With Quote
Old 1st April 2018, 23:10   #8  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Quote:
There is no function named 'GScript'."
I guess that is something that was forgotten during the emulation implementation.

Quote:
Req RT_Stats v1.43 + CallCmd (c) StainlessS, + GSCript + Grunt (c) Gavino.
Even if Avs+ has GScript functionality, you are likely to have problems having to comment out lines in GScript using scripts that can run on either avs standard and avs+.
I always have Gscript and Grunt [required for GScriptClip(arg=Args,Local=True)] in my plugins, whether avs or avs+ is in use.

Quote:
you should delete those last 2 lines.
Which other line are you talking about, the GScript(InstS) thing actually calls the function, and so of course cannot be commented out and still function as expected (or at all).
__________________
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; 1st April 2018 at 23:15.
StainlessS is offline   Reply With Quote
Old 1st April 2018, 23:15   #9  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
try
Code:
#    GScript(InstS)
    Eval(InstS)
Works for me in avs+ 32bit.

EDIT: I'll fix it so that it works on avs 2.6 standard or avs+(without GSCript or script editing).
__________________
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; 1st April 2018 at 23:20.
StainlessS is offline   Reply With Quote
Old 1st April 2018, 23:45   #10  |  Link
Motenai Yoda
Registered User
 
Motenai Yoda's Avatar
 
Join Date: Jan 2010
Posts: 709

I have those 2 lines at the end, from .zip
__________________
powered by Google Translator
Motenai Yoda is offline   Reply With Quote
Old 1st April 2018, 23:59   #11  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Link and posts updated to v1.01.

EDIT: Actually, I mistakenly used RT_VarExist("GScript") when I should have used RT_FunctionExist("Gscript"),
but it works OK anyway, arh well, I'll leave as it is for just now, I'll fix it for next time.

EDIT: I'll fix in the posted script, I'll just leave the zip as it is for now.
__________________
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; 2nd April 2018 at 00:20.
StainlessS is offline   Reply With Quote
Old 2nd April 2018, 00:08   #12  |  Link
johnmeyer
Registered User
 
Join Date: Feb 2002
Location: California
Posts: 2,685
I'll be out for several days but would like to try this. I do a LOT of work that involves detecting and then doing something with duplicates.

However ...

The most typical scenario that I come across that creates duplicates is from either a capture card or streaming video drops a frame and then, to keep the audio in sync, adds a duplicate frame. In those scenarios, the duplicate is a true duplicate, and no fancy logic is needed to find it. The much, much bigger issue is find the place where the dropped frame happened because it is at THAT point you have to do something, typically synthesizing a new frame using motion estimation.

As for how to detect differences and thereby determine which frames are dups, I haven't used RTStats for a while so I don't remember all the functions, but when using native AVISynth functions, it is the YDifference functions that are the most useful because, if I remember correctly, they compute their metric by the absolute differences between each pixel position in one frame with the same pixel position in the adjacent frame and then summing all of those differences. It will be interesting to see how your new function compares with that.
johnmeyer is offline   Reply With Quote
Old 2nd April 2018, 00:29   #13  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
RT_LumaDifference can use two separate clips if required + any two frame numbers (one for each clip), [YDifference is single clip], but same measurement.

Yoda wanted to list dupe frames and temporarily remove them for MC processing, and then replace with identical dupes from the
MC processed clip.

ie here:- https://forum.doom9.org/showthread.p...14#post1832814

I think he may want this for vfr stuff, not sure.
__________________
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 ???
StainlessS is offline   Reply With Quote
Old 2nd April 2018, 00:47   #14  |  Link
Motenai Yoda
Registered User
 
Motenai Yoda's Avatar
 
Join Date: Jan 2010
Posts: 709
Yep something about full of dups stuff
but as lossy codecs will introduce artifacts between dups, loss of detail et simila iirc TDecimate uses a threshold to filter out small differences (default 0) and a block based metric to find slight differences in small area only.
__________________
powered by Google Translator
Motenai Yoda is offline   Reply With Quote
Old 2nd April 2018, 01:10   #15  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
I use a block based metric in SecurityCamExtractMotion.avs as shown in action here:- https://forum.doom9.org/showthread.p...05#post1775305

Is too big to post, but included in RT_Stats v2.0 beta.

I did at one time use it in the Duplicity script, maybe I'll add as an option or something.
__________________
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 ???
StainlessS is offline   Reply With Quote
Old 2nd April 2018, 02:23   #16  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
If anybody has wanted to try SecurityCamExtractMotion.avs as mentioned in previous post but has had trouble down to Gscript and Avs+,
find fixed version works on AVS/AVS+ :- http://www.mediafire.com/file/xfqzoh...1_20180402.zip

Or on SendSpace below in my sig.

Looks like this
__________________
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; 2nd August 2018 at 10:31.
StainlessS is offline   Reply With Quote
Old 2nd April 2018, 03:16   #17  |  Link
johnmeyer
Registered User
 
Join Date: Feb 2002
Location: California
Posts: 2,685
I used that security cam motion detect logic several years ago and it worked incredibly well. This looks like a much later version because I don't remember being able to draw a box on the screen to define the "live" area for the detection logic to use (or ignore).
johnmeyer is offline   Reply With Quote
Old 2nd April 2018, 03:25   #18  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
The dimmed area stuff (edge of frame) is highlited in Blue, the marker stuff hilited in purple, was updated at least 12 months ago.

Code:
# SecurityCamExtractMotion.AVS, v2.01, By StainlessS.
#
# Requires RT_Stats v2.0, FrameSel v1.03, GScript, Grunt, mt_tools_2. [GScript not needed if Avs+]
#
# Clip, Planar, YUY2 or RGB clip, YV411 not supported due to non support in Overlay.
#  (RGB, will likely require different thresholds)
#
# MUST SCAN STRAIGHT THROUGH, NO JUMPING ABOUT IN MotDetect.
#
# MotDetect() creates four .txt command files for KEEP frames (movement), DROP frames (not movement), DUPE frames and HOLD frames.
#  HOLD frames are combination of all KEEP frames and, DROP frames where block with greatest difference is in close proximity to previous 
#  KEEP frame block with greatest difference (ie there seems to be possible movement very near previously identified movement).
# Using SelectFrames() you can select frames types of each of the 4 command files, or using the Reject mode of FrameSel, you can
# instead return the frames NOT in the command file, so using the 4 created command files, you can extract 8 variations of frame types
# after a single detection scan.
#
############################################
Th      = 6.0         # Greater or equal KEEP (movement), below is DROP(or DUPE, or possibly HOLD).
                      # Need check against source, block size and almost all other settings.
#
dTH     = 4.0         # Below or equal is DUPE, 0.0 <= dTh < Th (above dTh and below Th is DROP [or possibly HOLD]).
#
BLKW    = 64          # Suggest about 16 -> 64 (even only, mod 4 else probably slower). Metrics will change with block size.
BLKH    = BLKW        # Localized movement, adjust for smallest size of moving objects to detect, makes only little difference to speed,
                      # bigger, may be a bit faster.
                      # For human target, suggest box encompassing head + shoulders of most distant human.
                      # RT_FrameMovement returns greatest average pixel difference for any one of the blocks.
                      # Block searches may be overlapped by up to half a block both horizontally and vertically and so total x,y,w,h area
                      # of each pair of frames is compared up to about 4 times due to the half block overlaps.
                                            
#                      
X =  16               # Area Of Interest, avoid eg passing traffic or timecode (or could use eg Overlay to blot out stuff for dclip).
Y =  16               # Suggest cut out eg sky unless looking for flying saucers (less to search, faster).
W = -16               # As for Crop. Best MOD 4 only
H = -16
#
CW = 0.0              # ChromaWeight, 0.0->1.0. 0.0 = Luma ONLY, about 0.1 suggested for color (luma ONLY faster for YUV).
                      # For RGB, Matrix used where CW==0.0 to convert to Luma-Y. If CW != 0.0, then returns average pixel differences,
                      #  (apdR+apdG+apdB)/3.0.
                      # Perhaps always CW=0.0 [luma only] for YUV night captures.
                      # Can convert RGB to YUV for Luma-Y detect and SelectFrames() using original RGB, if required.
#
AltScan=false         # If True, Scan only every other raster line starting from Y (maybe faster, especially YUV Luma scan only).
#
ChromaI=False         # If True, YV12 chroma is interlaced (ignored if not YV12 or if Luma ONLY scan [CW==0.0]).
#
Matrix=(Width>1100||Height>600)?3:2     # Matrix used for RGB conversion to Luma-Y. 
                                        # Default, If (Width>1100 || Height>600) then 3(PC.709), else 2(PC.601). (0=Rec.601, 1=Rec.709)
                                        # NOTE, default PClevels conversions will likely require different thresholds to YUV because of the
                                        # greater differences in Y (after RGB-Luma-Y conversion), probably about (255.0/219.0) times greater.
#                                          
OLapX= BlkW/2         # X Block Overlap. 0->BLKW/2 (bigger more accurate, slower)
OLapY= BlkH/2         # Y Block Overlap. 0->BLKH/2
                      #   Where YUV, CW==0.0 and AltScan==True, might try eg OLapY=(BlkH/2)-1, where would be faster due to AltScan and,
                      #   also in overlapped 'Y_Block' scan will then scan alternate scanlines that were not scanned in previous non overlapped
                      #   scan (if that makes any sense, ie even scanlines sampled in first block, odd lines sampled in overlapped block scan).

LAG  = 1              # Lag (default 1, ie no lag. 1 or more). Compares current frame n with frame n-Lag. Detection is always
                      # initially compared(n,n-1), if neither DUPE nor KEEP detected and Lag>1, then will redetect using comparison(n,n-Lag)
                      # where n-lag frame is limited to no earlier than the most recent KEEP frame.
                      # A moderate Lag (up to about 50 or so), may be more sensitive to very small amount of movement, 
                      # it introduces a time delay between compared frames. There is no upper limit to Lag arg.
                      # NOTE, Lag > 1 will likely produce more KEEP and HOLD frames (ie identify more movement), and also a bit slower
                      # due to 2nd detection scan where initial scan identified DROP frame (ie DROP may be converted to KEEP or HOLD).
                      # Lag will not make any huge difference to results, small amount of movement at beginning of sequence of movements may be
                      # detected, use lag > 1 only where every possible movement frame is required. 

SHOWDCLIP=false        # If True, then shows DClip in MotDetect rather than source clip (Only useful if dclip pre-processed in some fashion)
#
dclip=Last            # Detection clip.
                      # Or some kind of denoise or whatever, used for detection (visible in ShowMetrics if SHOWDCLIp==True).
                      # Use SPATIAL denoise ONLY.
#dclip=dclip.MaxContrast(Samples=64,Gamma=1.0).VagueDenoiser(threshold=0.8,method=1,nsteps=6,chromaT=0,interlaced=false) # SLOWISH
#dclip=dclip.MaxContrast(Samples=64,Gamma=1.0).hqdn3d(2.0, 0.0,0.0,0.0,0) # A bit FASTER

###
### Show Metrics ONLY
DIM=False             # Dim/darken area outside of the x,y,w,h search area. A little faster with Dim==False when showing metrics only.
SHOWMISS  =true       # Show block 'Marker' for greatest moving DROP block (miss), (markers never shown for dupes).
MISSCOLOR =$AAFF00    # Color, block 'Marker' for  greatest DROP block (when SHOWMISS==True). 
HITCOLOR  =$FFFF44    # Color, block 'Marker' for  greatest KEEP block (hit).
HOLDCOLOR =$FF8800    # Color, block 'Marker' for  HOLD block (Miss converted to HIT due to Miss proximity to previous Hit).
VERBOSE=True          # Show additional metrics, Th, dTh, BLK Args
Quote:
worked incredibly well
With RT_Stats v2.0, have implemented RT_FrameMovement (I think may have been implemented as RT_LumaMovement, ie luma only) in version that your tried,
yep, it works damned lovely

The Block marker in yellow show area of max change/movement.

EDIT:
Quote:
HOLD frames are combination of all KEEP frames and, DROP frames where block with greatest difference is in close proximity to previous
KEEP frame block with greatest difference (ie there seems to be possible movement very near previously identified movement).
I remember about time I did the above frame cap, that a bloke walking down the street went behind a car, and you could only just see the top of his hat above the car/van bobbing up and down, and the HOLD frame thing above managed to track only a few pixels of the oscillating hat until he emerged a few yards on, was quite fascinating to see it actually working profoundly well, in the words of Harry Potter, "I Love Magic",
__________________
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; 2nd April 2018 at 04:50.
StainlessS is offline   Reply With Quote
Old 3rd April 2018, 03:19   #19  |  Link
`Orum
Registered User
 
Join Date: Sep 2005
Posts: 178
Quote:
Originally Posted by StainlessS View Post
Yoda wanted to list dupe frames and temporarily remove them for MC processing, and then replace with identical dupes from the MC processed clip.
Interesting. Why does he want the duplicates put back in? Does some playback device not support VFR?

Edit: Thinking about this, it shouldn't be too hard to do; just parse the timestamp file and insert duplicate frames when necessary.
Quote:
Originally Posted by StainlessS View Post
@ Orum, hope you can do better than this with your new plug in devs forum, good luck.
Heh, thanks for the vote of confidence! Anyway if you give it a shot let me know what you think. It really needs block-level metrics but that should be coming very soon (probably in the next release).
__________________
My filters: DupStep | PointSize

Last edited by `Orum; 3rd April 2018 at 03:29.
`Orum is offline   Reply With Quote
Old 3rd April 2018, 08:11   #20  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Quote:
Interesting. Why does he want the duplicates put back in? Does some playback device not support VFR?
I have never played with vfr, but I'm guessin' that he wants to put back [EDIT: Identical] dupes so that some other vfr stuff can then work with the
inserted identical duplicates to produce the vfr 'thingy'.

Here is a working demo for removing the dupes for some MC processing of only non-dupes, and then to replace the removed dups with
identical dups from the newly processed MC result, I'm gonna add the "MakeReDupCmd()" functionality to FrameSel plug.
https://forum.doom9.org/showthread.p...14#post1832814

Looking forward to seeing what your plug can do, Peace bro
__________________
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; 3rd April 2018 at 08:55.
StainlessS is offline   Reply With Quote
Reply

Tags
dedup, deduplicate, duplicates

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 06:36.


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