View Single Post
Old 17th November 2018, 14:58   #46  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Duplicity2(), DropDeadGorgeous(), v2.13 updates, see first post.

See post #22 for current Duplicity2 script, or download see 1st post (re-directs to MediaFire or SendSpace below this post).

Current DropDeadGorgeous() reversioned to v2.13, will now always be same version as Duplicity2 (and require similar version Duplicity2).

DropDeadGorgeous.avsi part 1
Code:
/*

    DropDeadGorgeous() v2.13, by the Gorgeous & Truly Scrumptious StainlessS @ Doom9
    Same Requirements as Duplicity2(). https://forum.doom9.org/showthread.php?t=175357

        Using DBase as Created by Duplicity2 v2.13.
        Corrects problems where frames were dropped in clip, and then some time later duplicates were inserted to maintain timing,
        ie 'jumpy' clips that repeatedly jerk and then freeze.
        ScanAhead is number of frames scanned ahead of current_frame looking for duplicates, default 9. Any detected dupe run will
        start between current_frame and current_frame + ScanAhead.
        If duplicates found (limit on length of duplicate run set in Duplicity2 via MaxDupLen), then a JerkFrame is found.
        A JerkFrame is searched for backwards, from DupeStartFrame-1 to to current_frame and search stops if a StartOfScene is detected.
        The JerkFrame is the frame prior to first dupe, with greatest movement/jerk when compared with its predecessor.
        If JerkFrame is found, a number of frames are interpolated starting at the JerkFrame position, (same number as in dupe run,
        and source frames to interpolation are JerkFrame and JerkFrame-1), interpolated frames shove following frames to later in clip,
        removing dupes.
        If no JerkFrame is found, ie where duplicates are of a StartOfScene frame, then so long as DupeEndFrame+1 is not another StartOfScene
        frame, then duplicates are interpolated using DupeStartFrame-1 and DupeEndFrame+1 as interpolation source frames.

    Function DropDeadGorgeous(clip c,String DB,Int "ScanAhead"=9,
        \ Int "X"=0,Int "Y"=0,Int"W"=0,Int "H"=0,
        \ 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      *]
        \ Bool "Show"=True, Bool "Verb"=True,Int "SOSthSCD2"=130
        \ )

        DB,            DBase as created by Duplicity2, v2.13, error if wrong version DBase.

        ScanAhead,     Default 9, 1 <= ScanAhead <= 60. Distance in frames to scan ahead of current frame. If first duplicate is always eg
                       3 frames after a jerk, then set this to 3.
                       ScanAhead, is deliberatley set quite high by default, then maybe reduce ScanAhead to MostCommonScanDist after full scan.
                       ALSO SEE Verbose Metrics MostCommonScanDist.

        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.

                       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.

        Show,          Default True, Show Metrics.
        Verb,          Default True, If Verb And Show, then show additional metrics.

        SOSthSCD2      Default 130. As for MSCDetection(thSCD2=SOSthSCD2). Halt backwards search for JerkFrame where StartOfScene.

        Simple metrics on Show, "nnnn] UD : S : CIR", where nnnn is frame number, and character Flags highlited where,
                Duplicity2 Status:
            U = Unique frame status from Dupliicty DBase (non dupe, includes low motion static scene etc).
            D = Dupe frame status from Dupliicty DBase.

            :
            S = Current frame is Start Of Scene.

            :   DropDeadGorgeous Decisions :
            C = Copy frame (original as source frame)
            I = Interpolated frame
                Interpolated frames also show eg {I1/2:ILft=1275,IRgt=1276}
                    where, first of 2 Interpolated frames, and interpolate source frames are 1275 and 1276(JerkFrame usually, unless DupeS-1=SOS).
            R = Relocated frame from earlier in clip (interpolated frames shove following frames to later in clip, removing dupes)
                Reloacted frames also show eg {R1/8:Src=1276,n-2}
                    where, first of 8 relocated frames, source for current relocated frame is frame 1276, which is current frame-2.

            If Verb=True, also shows eg below
             Motion(n-1,n)=0.367            # Motion metric between current frame and current frame-1 (JerkFrame search metric).
             ScanMaxdist=9 (Cnt=7) @ 3458   # Maximum ScanAhead distance found to dupes (count of instances found), and most recent @ frame 3458.
             MostCommonScanDist=8 (Cnt=190) # The most common ScanAhead distance found between jerkframe and dupes, and instance count.
                                            # Maybe reduce ScanAhead arg to value as shown for MostCommonScanDist.

        Can use any Duplicity Mode in creating DBase, the Duplicity2 End+1 Scene change thing has no effect here (not necessary).

        It may be possible to up framerate to a non multiple of source whilst keeping all source frames verbatim, where eg source
        is 24 FPS and required = 25 FPS, and using,
        Src24.ChangeFPS(25) to produce a new clip at 25 FPS with an exact duplicate every 24 source frames and save new source as eg Src25.avi.
        Process new source with eg src25.Duplicity2(ThG=0.1,DBase="D:\Src25_Det.DB"), to produce a DBase (perhaps with MaxDupLen=1, perhaps not).
        Then use Src25.DropDeadGorgeous("D:\Src25_Det.DB",ScanAhead=12) to interpolate dupe frames achieving 25.0 and with all original
        source frames. With a ScanAhead of eg 12, will locate dupes and then backwards scan up to 12 frames before the dupes looking for
        frame of greatest movement, insert an interpolated frame prior to that greatest movement frame and shove all following frames along one
        to remove the dupe. Might be worth someone experimenting.
        Or, you could just use eg Duplicity2(Mode=2,ThG=0.1) to interpolate the exact dupes directly and without DropDeadGorgeous but that might
        produce a more rhythmic stutter every 25 frames.

*/
__________________
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