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 17th December 2014, 21:16   #81  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 5,161
OK, here we go again: http://www.mediafire.com/download/2g..._17Dec2014.zip

Raised THRESH to 0.015.
Added ReScan after UNDO (correct sequencing problem).
Had to make RT_QwikScan and RT_QwikScanEstimateLumaTol a bit safer, slowed down a little but not so very much.


Log
Code:
Fsel_Eduardobedoya_Batch.Log
THRESH = 0.015000 LUMATOL_SCALE=1.000000 LUMATOL_ADD=0.000000
MIN_EDITLEN=4     OVR_PIXCNT_THR=4       OVR_PIXCNT_LIM=50
ScanAheadSecs=600 ChromaWeight=0.333333  OutFPS=15.000000
PC709=True CROPPING=128,128,328,128

1/2 ] Processing 'D:\ED\Last capture without cursor.avi.AVI'
QWIK Scan DBase creation = 130.94 Secs (2.18 Mins)
 2124] UNDO: Matched 2095 -> 2124 : Skip 2096 to 2124 : (FDif=6.532177E-004 : LumaPixelsDifferentBy_4 = 0)
 2085] UNDO: Matched 2073 -> 2085 : Skip 2074 to 2085 : (FDif=9.394840E-006 : LumaPixelsDifferentBy_4 = 0)
 2072] UNDO: Matched 1992 -> 2072 : Skip 1993 to 2072 : (FDif=1.100854E-003 : LumaPixelsDifferentBy_4 = 9)
 1984] UNDO: Matched 1957 -> 1984 : Skip 1958 to 1984 : (FDif=2.155287E-004 : LumaPixelsDifferentBy_4 = 4)
 1951] UNDO: Matched 1923 -> 1951 : Skip 1924 to 1951 : (FDif=4.327153E-004 : LumaPixelsDifferentBy_4 = 2)
 1900] UNDO: Matched 1816 -> 1900 : Skip 1817 to 1900 : (FDif=2.470290E-003 : LumaPixelsDifferentBy_4 = 14)
 1809] UNDO: Matched 1784 -> 1809 : Skip 1785 to 1809 : (FDif=2.906874E-004 : LumaPixelsDifferentBy_4 = 1)
 1768] UNDO: Matched 1727 -> 1768 : Skip 1728 to 1768 : (FDif=9.030099E-004 : LumaPixelsDifferentBy_4 = 7)
 1716] UNDO: Matched 1693 -> 1716 : Skip 1694 to 1716 : (FDif=8.908519E-004 : LumaPixelsDifferentBy_4 = 4)
 1643] UNDO: Matched 1608 -> 1643 : Skip 1609 to 1643 : (FDif=2.812926E-004 : LumaPixelsDifferentBy_4 = 0)
 1588] UNDO: Matched 1553 -> 1588 : Skip 1554 to 1588 : (FDif=2.917927E-004 : LumaPixelsDifferentBy_4 = 0)
 1431] UNDO: Matched 1426 -> 1431 : Skip 1427 to 1431 : (FDif=1.199224E-004 : LumaPixelsDifferentBy_4 = 1)
 1411] UNDO: Matched 1391 -> 1411 : Skip 1392 to 1411 : (FDif=4.951633E-004 : LumaPixelsDifferentBy_4 = 0)
 1309] UNDO: Matched 1259 -> 1309 : Skip 1260 to 1309 : (FDif=4.758210E-004 : LumaPixelsDifferentBy_4 = 1)
 1219] UNDO: Matched 1186 -> 1219 : Skip 1187 to 1219 : (FDif=2.571976E-003 : LumaPixelsDifferentBy_4 = 11)
 1149] UNDO: Matched 1112 -> 1149 : Skip 1113 to 1149 : (FDif=4.598498E-003 : LumaPixelsDifferentBy_4 = 13)
 1048] UNDO: Matched 1039 -> 1048 : Skip 1040 to 1048 : (FDif=9.947477E-006 : LumaPixelsDifferentBy_4 = 0)
  985] UNDO: Matched 938 -> 985 : Skip 939 to 985 : (FDif=6.108304E-003 : LumaPixelsDifferentBy_4 = 24)
  928] UNDO: Matched 914 -> 928 : Skip 915 to 928 : (FDif=2.305052E-003 : LumaPixelsDifferentBy_4 = 9)
  908] UNDO: Matched 870 -> 908 : Skip 871 to 908 : (FDif=2.127102E-003 : LumaPixelsDifferentBy_4 = 8)
  850] UNDO: Matched 828 -> 850 : Skip 829 to 850 : (FDif=3.548486E-003 : LumaPixelsDifferentBy_4 = 12)
  807] UNDO: Matched 713 -> 807 : Skip 714 to 807 : (FDif=3.715935E-003 : LumaPixelsDifferentBy_4 = 20)
  668] UNDO: Matched 612 -> 668 : Skip 613 to 668 : (FDif=7.792190E-005 : LumaPixelsDifferentBy_4 = 1)
  588] UNDO: Matched 482 -> 588 : Skip 483 to 588 : (FDif=2.116602E-004 : LumaPixelsDifferentBy_4 = 0)
  460] UNDO: Matched 420 -> 460 : Skip 421 to 460 : (FDif=3.868463E-005 : LumaPixelsDifferentBy_4 = 0)
  390] UNDO: Matched 370 -> 390 : Skip 371 to 390 : (FDif=3.039507E-005 : LumaPixelsDifferentBy_4 = 0)
  368] UNDO: Matched 276 -> 368 : Skip 277 to 368 : (FDif=9.245627E-004 : LumaPixelsDifferentBy_4 = 3)
  205] UNDO: Matched 117 -> 205 : Skip 118 to 205 : (FDif=5.156109E-004 : LumaPixelsDifferentBy_4 = 1)
   65] UNDO: Matched 0 -> 65 : Skip 1 to 65 : (FDif=1.008011E-003 : LumaPixelsDifferentBy_4 = 2)

Kept 410 of 2150 frames [1920x1080 143.33 secs (2.39 Mins) @ 15.00 FPS]
File Max Successful CrudMax = 2.758771E-003 CrudMaxFrame=1900
File Max Successful LumaPixelsDifferentBy_4 = 24 @ Frame = 985
QWIK SCAN 130.94 Secs (2.18 Mins) InFPS=16.42 OutFPS=3.13 FramesSearched=459016 FramesSearchedFPS=3505.60
1/2 'D:\ED\Last capture without cursor.avi.AVI'  Tot File Time = 262.12 Seconds (4.37 Mins)

2/2 ] Processing 'D:\ED\Test 00 tsc2.avi.AVI'
QWIK Scan DBase creation = 98.48 Secs (1.64 Mins)
 1649] UNDO: Matched 1636 -> 1649 : Skip 1637 to 1649 : (FDif=0.000000E+000 : LumaPixelsDifferentBy_4 = 0)
 1583] UNDO: Matched 1542 -> 1583 : Skip 1543 to 1583 : (FDif=5.360585E-004 : LumaPixelsDifferentBy_4 = 3)
 1498] UNDO: Matched 1391 -> 1498 : Skip 1392 to 1498 : (FDif=3.694935E-003 : LumaPixelsDifferentBy_4 = 8)
 1327] UNDO: Matched 1273 -> 1327 : Skip 1274 to 1327 : (FDif=5.472770E-003 : LumaPixelsDifferentBy_4 = 19)
 1262] UNDO: Matched 1234 -> 1262 : Skip 1235 to 1262 : (FDif=3.011875E-004 : LumaPixelsDifferentBy_4 = 3)
 1217] UNDO: Matched 1204 -> 1217 : Skip 1205 to 1217 : (FDif=8.842202E-006 : LumaPixelsDifferentBy_4 = 0)
 1190] UNDO: Matched 1099 -> 1190 : Skip 1100 to 1190 : (FDif=2.953296E-003 : LumaPixelsDifferentBy_4 = 11)
 1039] UNDO: Matched 1029 -> 1039 : Skip 1030 to 1039 : (FDif=8.068509E-005 : LumaPixelsDifferentBy_4 = 1)
  957] UNDO: Matched 951 -> 957 : Skip 952 to 957 : (FDif=1.050012E-005 : LumaPixelsDifferentBy_4 = 0)
  945] UNDO: Matched 910 -> 945 : Skip 911 to 945 : (FDif=3.842490E-003 : LumaPixelsDifferentBy_4 = 7)
  814] UNDO: Matched 805 -> 814 : Skip 806 to 814 : (FDif=0.000000E+000 : LumaPixelsDifferentBy_4 = 0)
  758] UNDO: Matched 738 -> 758 : Skip 739 to 758 : (FDif=0.000000E+000 : LumaPixelsDifferentBy_4 = 0)
  736] UNDO: Matched 673 -> 736 : Skip 674 to 736 : (FDif=5.128477E-003 : LumaPixelsDifferentBy_4 = 13)
  609] UNDO: Matched 557 -> 609 : Skip 558 to 609 : (FDif=3.419169E-003 : LumaPixelsDifferentBy_4 = 9)
  536] UNDO: Matched 527 -> 536 : Skip 528 to 536 : (FDif=6.465860E-005 : LumaPixelsDifferentBy_4 = 0)
  518] UNDO: Matched 469 -> 518 : Skip 470 to 518 : (FDif=4.058571E-003 : LumaPixelsDifferentBy_4 = 14)
  432] UNDO: Matched 418 -> 432 : Skip 419 to 432 : (FDif=8.242038E-003 : LumaPixelsDifferentBy_4 = 40)
  395] UNDO: Matched 388 -> 395 : Skip 389 to 395 : (FDif=1.989495E-005 : LumaPixelsDifferentBy_4 = 0)
  359] UNDO: Matched 324 -> 359 : Skip 325 to 359 : (FDif=6.175726E-003 : LumaPixelsDifferentBy_4 = 16)
  312] UNDO: Matched 303 -> 312 : Skip 304 to 312 : (FDif=0.000000E+000 : LumaPixelsDifferentBy_4 = 0)
  212] UNDO: Matched 207 -> 212 : Skip 208 to 212 : (FDif=7.736927E-006 : LumaPixelsDifferentBy_4 = 0)
  205] UNDO: Matched 198 -> 205 : Skip 199 to 205 : (FDif=8.842202E-006 : LumaPixelsDifferentBy_4 = 0)
  164] UNDO: Matched 111 -> 164 : Skip 112 to 164 : (FDif=1.198560E-002 : LumaPixelsDifferentBy_4 = 36)
   95] UNDO: Matched 88 -> 95 : Skip 89 to 95 : (FDif=4.421101E-006 : LumaPixelsDifferentBy_4 = 0)
   23] UNDO: Matched 0 -> 23 : Skip 1 to 23 : (FDif=7.389318E-003 : LumaPixelsDifferentBy_4 = 14)

Kept 646 of 1650 frames [1920x1080 110.00 secs (1.83 Mins) @ 15.00 FPS]
File Max Successful CrudMax = 7.427458E-003 CrudMaxFrame=432
File Max Successful LumaPixelsDifferentBy_4 = 40 @ Frame = 432
QWIK SCAN 173.10 Secs (2.88 Mins) InFPS=9.53 OutFPS=3.73 FramesSearched=490864 FramesSearchedFPS=2835.73
2/2 'D:\ED\Test 00 tsc2.avi.AVI'  Tot File Time = 271.88 Seconds (4.53 Mins)

BATCH TOTAL Time = 534.00 Seconds (8.90 Mins)
Global CrudMax=0.007427
Global MaxLumaPixelsDifferentBy_4 = 40
This is crud lump (ie not crud, detection mistake in CRUD_INSPECT script), see if you can spot it (can be any color).


EDIT:
Make this alteration near end of script, (missed writing last frame 0 to log)
Code:
            if(!SKIP || i==0) {
                if(VERBOSITY>=3 || i==0) {
                    if(i==0)    {S=RT_String("%5d]      WRITING: Frame %d",i,i) }
                    Else        {S=RT_String("            WRITING: Frame %d",i) }
                    RT_DebugF("%s",S,name=myName)
                    RT_WriteFile(LOG,"%s",S,Append=True)
                }
                RT_WriteFile(CMDFrames,"%d",i,Append=True)
                Kept = Kept + 1
            }
EDIT: Mobile now. Pub shuts in 100 minutes, gotta dash to get some more in.
Crud lump synthesised, not produced on your clips.
Think, 100% satisfactory on both clips.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

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

Last edited by StainlessS; 15th July 2017 at 19:45.
StainlessS is offline   Reply With Quote
Old 18th December 2014, 02:23   #82  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 5,161
Cute lil chipmonks here : https://www.youtube.com/watch?v=n3M7IR6jkpc

Dont hold that against me, it has been a difficult task.

So far as I am concerned, tis fixed (let me know how it goes on longer clips).
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

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

Last edited by StainlessS; 19th December 2014 at 00:31.
StainlessS is offline   Reply With Quote
Old 4th December 2016, 20:36   #83  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 5,161
Post #1 of 2 (update script for RT_Stats v2.0, converted to using RT_ Arrays instead of DBase)

Fsel_Eduardobedoya_Batch_04Dec2016.avs Part 1

Code:
# ############################
# Fsel_Eduardobedoya_Batch.avs, by StainlessS
# Remove Undos from painting captures.
########################################################################
THRESH          = 0.015     # (0.015) Max LumaTol due to crud between undone/undo frames. (set about double CrudMax)
                            # (CrudMax only valid as Check when results are satisfactory)
                            # Upper Limit for self tuning LumaTol.
#
LUMATOL_SCALE   = 1.0       # (1.0) Range 1.0 -> 2.0. Should never need change from 1.0.
                            # LumaTol is self tuning but could possibly be in error where without this setting would fail miserably.
                            # If self tune LumaTol is set too low then will not find matching UNDONE frames. This setting allows
                            # to increase LumaTol as LumaTol is multiplied by it, and then restricted at upper limit by THRESH above.
                            # If ever need to be changed, suggest something like 1.00001. (temporary change only)
#
LUMATOL_ADD     = 0.0       # (0.0) Range 0.0 -> 1.0. Additional adjustment added to LumaTol, probably never necessary, but if so then
                            # something like 0.000001. Applied before limiting to THRESH as above.
#
MIN_EDITLEN     = 4         # (4) An edit has to be at least this many frames long (frames between UNDONE and UNDO, exclusive)
OVR_PIXCNT_THR  = 4         # (4) Thresh for RT_LumaPixelsDifferentCount, only pixel differences greater than this are counted.
OVR_PIXCNT_LIM  = 50        # (50)If RT_LumaPixelsDifferentCount(Thresh=OVR_PIXCNT_THR) greater than this then is OVERRIDDEN as false detection.
                            # Above OVR_ settings for detecting override where difference between undone/undo is too visible (ie not crud).
#
ScanAheadSecs   = 10 * 60   # Search ahead range in seconds
ChromaWeight    = 1.0/3.0   # (1.0/3.0) YUV Chroma Weighting, 0.0 -> 1.0
FPS             = 15.0      # Play speed for output script.
VERBOSITY       = 0         # (0) 0 to 3. Debug & logging verbosity.
########################################################################
# Chop off crud around outsides
GLOBAL CROP_L    = 128  # Crop Left
GLOBAL CROP_T    = 128  # Crop Top
GLOBAL CROP_R    = 328  # Crop Right (Including that thumbnail with the delayed UNDO and additional crap)
GLOBAL CROP_B    = 128  # Crop Bottom
########################################################################
# During Testing
GLOBAL CREATE     = True
GLOBAL DELETE_ARR = false
########################################################################
GLOBAL PC709  = True
GLOBAL CROP_L = (CROP_L / 4) * 4    GLOBAL CROP_T = (CROP_T / 4) * 4
GLOBAL CROP_R = (CROP_R / 4) * 4    GLOBAL CROP_B = (CROP_B / 4) * 4
FSEL_TITLE="Select AVI files"
FSEL_DIR="."
FSEL_FILT="Avi files|*.avi"
FSEL_MULTI=True

AVIFILE_LIST = RT_FSelOpen(title=FSEL_TITLE,dir=FSEL_DIR,filt=FSEL_FILT,multi=FSEL_MULTI)
Assert(AVIFILE_LIST.IsString,"RT_FSelOpen: Error="+String(AVIFILE_LIST))


NFILES=RT_TxtQueryLines(AVIFILE_LIST)                                           # Query Number of lines in String ie number of files.
myName="Fsel_Eduardobedoya_Batch: "
LOG="Fsel_Eduardobedoya_Batch.Log"
RT_WriteFile(LOG,"%s\n",LOG,Append=False)

S=RT_String("THRESH = %f LUMATOL_SCALE=%f LUMATOL_ADD=%f\nMIN_EDITLEN=%d     OVR_PIXCNT_THR=%d       OVR_PIXCNT_LIM=%d",
    \ THRESH,LUMATOL_SCALE,LUMATOL_ADD,MIN_EDITLEN,OVR_PIXCNT_THR,OVR_PIXCNT_LIM)
RT_WriteFile(LOG,"%s",S,Append=True)
RT_DebugF("%s",S,name=myName)

S=RT_String("ScanAheadSecs=%d ChromaWeight=%f  OutFPS=%f",ScanAheadSecs,ChromaWeight,FPS)
RT_WriteFile(LOG,"%s",S,Append=True)
RT_DebugF("%s",S,name=myName)

S=RT_String("PC709=%s CROPPING=%d,%d,%d,%d",PC709,CROP_L,CROP_T,CROP_R,CROP_B)
RT_WriteFile(LOG,"%s",S,Append=True)
RT_DebugF("%s",S,name=myName)

GLOBAL Global_CrudMax   = 0.0
Global Global_PixCntMax = 0

Crud_S="""
    AMP=True
    PCTHRESH=@
    aviName=$@@$
    PC709=@@@
    Path=RT_FilenameSplit(AviName,3)
    Node=RT_FilenameSplit(AviName,4)
    CrudFrames = Path + $CrudInspect_Frames_$ + Node + $.TXT$
    Avisource(AviName)
    Crop(CROP_L,CROP_T,-CROP_R,-CROP_B)
    ConvertToYV12(matrix=(PC709)?$PC.709$:$PC.601$)
    NUMBERSCLIP=FrameSel(Cmd=CrudFrames,Ordered=False,SHOW=TRUE)
    NUMBERSCLIP=NUMBERSCLIP.CROP(0,0,20*10,1*20).POINTResize(20*10*2,1*20*2)
    NA=NUMBERSCLIP.SelectEven
    NB=NUMBERSCLIP.SelectODD
    FrameSel(Cmd=CrudFrames,Ordered=False)
    A=SelectEven
    B=SelectODD
    DELTA = Clipdelta(A,B,AMP)
    DELTA = DELTA.OVERLAY(NA,X=0,Y=DELTA.HEIGHT-NA.HEIGHT).OVERLAY(NB,X=DELTA.WIDTH-NB.WIDTH,Y=DELTA.HEIGHT-NA.HEIGHT)
    DELTA
    SC=$$$
        pc=RT_LumaPixelsDifferentCount(A,B)
        pct=RT_LumaPixelsDifferentCount(A,B,THRESH=PCTHRESH)
        ld=RT_LumaDifference(A,B)
        fd=RT_FrameDifference(A,B)
        S=RT_String($UNDO=%d]  LumaDif=%f  FrameDif=%f  LumaPixelsDifferent=%d  LumaPixelsDifferentByMoreThan_%d=%d$,current_frame,ld,fd,pc,PCTHRESH,pct)
        Subtitle(S,size=24,font=$Courier New$)
    $$$
    ScriptClip(SC)
    return Last

    # Return Clip Difference of input clips (amp==true = Amplified, show==true = show background)
    Function ClipDelta(clip clip1,clip clip2,bool $amp$,bool $show$) {
        amp=Default(amp,false)
        show=Default(show,false)
        c2=clip1.levels(128-32,1.0,128+32,128-32,128+32).greyscale()
        c1=clip1.subtract(clip2)
        c1=(amp)?c1.levels(127,1.0,129,0,255):c1
        return (show)?c1.Merge(c2):c1
    }
"""

GSCript("""
    TOTSTART = RT_TimerHP
    For(i=0,NFILES-1) {
        START = RT_TimerHP
        FN=RT_TxtGetLine(AVIFILE_LIST,i)                                        # Filename of avi file i
        S=RT_String("\n%d/%d ] Processing '%s'\n",i+1,NFILES, FN)
        RT_DebugF(S,name=myName)
        RT_WriteFile(LOG,"%s",S,Append=True)

        DropUndo(FN,Crud_S,ScanAheadSecs,thresh=THRESH,Min_EditLen=MIN_EDITLEN,
            \ log=LOG,ChromaWeight=ChromaWeight,fps=FPS,
            \ ovr_pixcnt_thr=OVR_PIXCNT_THR,ovr_pixcnt_lim=OVR_PIXCNT_LIM,
            \ LumaTol_Scale=LUMATOL_SCALE,LumaTol_Add=LUMATOL_ADD,Verbosity=VERBOSITY)

        T = RT_TimerHP - START
        S=RT_String("%d/%d '%s'  Tot File Time = %.2f Seconds (%.2f Mins)",i+1,NFILES,FN, T,T/60.0)
        RT_DebugF(S,name=myName)
        RT_WriteFile(LOG,"%s",S,Append=True)
    }
    T = RT_TimerHP - TOTSTART
    S=RT_String("\nBATCH TOTAL Time = %.2f Seconds (%.2f Mins)\nGlobal CrudMax=%f\nGlobal MaxLumaPixelsDifferentBy_%d = %d",
        \ T,T/60.0,GLOBAL_CrudMax,OVR_PIXCNT_THR,Global_PixCntMax)
    RT_DebugF(S,name=myName)
    RT_WriteFile(LOG,"%s",S,Append=True)
    S=RT_String("\nDONE\n\n%s",S)
    S=RT_StrReplace(S,Chr(10),"\n")
""")


Return blankclip(length=24*60*60*24).Subtitle(S,Align=5,Y=100,lsp=0,Size=30)
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but are any of them infinitely bigger ???
StainlessS is offline   Reply With Quote
Old 4th December 2016, 20:37   #84  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 5,161
Post #2 of 2

Fsel_Eduardobedoya_Batch_04Dec2016.avs Part 1

Code:
Function DropUndo(String AviName,String Crud_S,Float "ScanAheadSecs",Float "THRESH",Int "Min_EditLen",
        \ String "Log",Float "ChromaWeight",float "fps",Int "ovr_pixcnt_thr",Int "ovr_pixcnt_lim",
        \ Float "LumaTol_Scale",Float "LumaTol_Add", Int "Verbosity") {
    myName="DropUndo: "
    ScanAheadSecs=Float(Default(ScanAheadSecs,10.0*60.0))
    THRESH=Float(Default(THRESH,0.02))
    MIN_EDITLEN=Default(MIN_EDITLEN,4)
    LOG = Default(LOG,"DropUndo.LOG")
    ChromaWeight = Float(Default(ChromaWeight,1.0/3.0))
    FPS = Float(Default(FPS,FPS))
    OVR_PIXCNT_THR=Default(OVR_PIXCNT_THR,4)
    OVR_PIXCNT_LIM=Default(OVR_PIXCNT_LIM,50)
    LumaTol_Scale = Float(Default(LumaTol_Scale,1.0))
    LumaTol_Add   = Float(Default(LumaTol_Add,0.0))
    VERBOSITY=Default(VERBOSITY,0)

    Assert(Exist(AviName),myName+AviName+" Does Not Exist")

    Avisource(AviName)
    ORG=Last

    Crop(CROP_L,CROP_T,-CROP_R,-CROP_B)                                           # Crop crud
    ConvertToYV12(Matrix=(PC709)?"PC.709":"PC.601")

    Assert(ScanAheadSecs>0.0,myName+"ScanAheadSecs Must be greater than zero")
    Assert(THRESH>0.0, myName+"THRESH Must be greater than zero")
    Assert(MIN_EDITLEN>0,myName+"Greater than zero please")
    Assert(ChromaWeight>=0.0 && ChromaWeight<=1.0,    myName+"ChromaWeight range 0.0 -> 1.0")
    Assert(OVR_PIXCNT_THR>=0 && OVR_PIXCNT_THR<=8,    myName+"OVR_PIXCNT_THR range 0 -> 8")
    Assert(OVR_PIXCNT_LIM>=0 && OVR_PIXCNT_LIM<=100,  myName+"OVR_PIXCNT_LIM range 0 -> 100")
    Assert(LumaTol_Scale>=1.0 && LumaTol_Scale<=2.0,  myName+"LUMATOL_SCALE range 1.0 -> 2.0")
    Assert(LumaTol_Add>=0.0 && LumaTol_Add<=1.0,      myName+"LUMATOL_ADD range 0.0 -> 1.0")
    Assert(VERBOSITY>=0 && VERBOSITY<=3,              myName+"VERBOSITY range 0 -> 3")

    Path = RT_FilenameSplit(AviName,3)                                            # Drive + Dir
    Node = RT_FilenameSplit(AviName,4)                                            # Name
    PathAndNode = Path+Node                                                       # Drive + Dir + Name
    CMDFrames=PathAndNode+"_Frames.TXT"
    Ranges=PathAndNode+"_Ranges.TXT"
    ScriptFile=Path+"_AVS_"+Node+"_SelectFrames.AVS"
    CrudScript = Path + "_CRUD_INSPECT_" + Node + ".AVS"
    CrudFrames = Path + "CrudInspect_Frames_" + Node + ".TXT"
    Fnd_S = RT_String("CROP_L\nCROP_T\nCROP_R\nCROP_B\n$\n@@@\n@@\n@\n")
    Rep_S = RT_String("%d\n%d\n%d\n%d\n%c\n%s\n%s\n%d",CROP_L,CROP_T,CROP_R,CROP_B,34,PC709,RT_GetFullPathName(AviName),OVR_PIXCNT_THR)
    Crud_S = RT_StrReplaceMulti(Crud_S,Fnd_S,Rep_S)

    ScanAheadFrames = Int(ScanAheadSecs*FrameRate)
    ARR=PathAndNode+".ARR"
    PREV=PathAndNode +  "_Prev.ARR"
    NEXT=PathAndNode +  "_Next.ARR"

    RT_FileDelete(CMDFrames)                                                       # Delete any existing frames file
    RT_FileDelete(Ranges)                                                          # Delete any existing Ranges file
    RT_FileDelete(CrudFrames)
    RT_FileDelete(CrudScript)
    CRUD_DB="~"+RT_LocalTimeString+".DB"
    RT_DBaseAlloc(CRUD_DB,0,"ii")                                                  # CRUD_DB int,int 

    ### TEMPLATE script
    FrameSel_Select="""
        Show=False                                                                      # Set True to show original Frame Number
        fn="%s"
        Avisource(fn)
        (Show) ? ScriptClip("Subtitle(String(current_frame))") : NOP
        PathAndNode="%s"
        CmdFrames=PathAndNode+"_Frames.txt"
        Ranges=PathAndNode+"_Ranges.txt"
        Ex=Exist(CmdFrames)
        (Ex) ? FrameSel_CmdReWrite(Ranges,cmd=CmdFrames,reject=False) : NOP             # Informational ONLY
        (Ex) ? FrameSel(cmd=CmdFrames,reject=False) : NOP
        Return Last.AssumeFPS(%f)
    """

    ###
    Select_S = FrameSel_Select
    Select_S = RT_StrReplaceDeep(RT_StrReplace(Select_S,Chr(9)," "),"  "," ")           # TAB and SPACE compact
    Select_S = RT_String(Select_S,AviName,PathAndNode,FPS)                              # Insert filenames

    FramesSearched  = 0
    CrudMax         = 0.0
    CrudMaxFrame    = -1
    PixCntMax       = 0
    PixCntMaxFrame  = -1
    Kept            = 0

    GSCript("""
        if(CREATE) {
            START = RT_TimerHP
            RT_QwikScanCreate(ARR,prev="",next=NEXT,debug=true)
            T= RT_TimerHP - START
            S = RT_String("QWIK Scan ARRAY creation = %.2f Secs (%.2f Mins)",T,T/60.0)
            RT_WriteFile(LOG,"%s",S,Append=True)
        }
        START = RT_TimerHP
        LastFrame=FrameCount-1
        RT_DebugF(" QWIK Scanning file ... Please Wait",name=myName)

        for(i=LastFrame,0,-1) {
            SKIP   = False
            if(i > 0) {
                PreUndoDif = RT_FrameDifference(Last,Last,n=i,n2=i-1,ChromaWeight=ChromaWeight)
                FramesSearched = FramesSearched + 1
                if(PreUndoDif > 0.0) {
                    StartFrame = Max(i-ScanAheadFrames,0)
                    EndFrame   = (i - 1 - MIN_EDITLEN)

                    # We are looking for an UNDONE frame that is more similar to i frame than i-1.
                    # If i is an UNDO frame then UNDONE frame will be more similar to i than i-1, so LumaTol estimate will find it fast.
                    # Alternatively, if i is not an UNDO frame then LumaTol estimate will speed up NOT FINDING frame.
                    # If estimate greater than THRESH, then i could still be an UNDO frame just i-1 is quite a lot different to i frame, so we
                    # limit LumaTol to THRESH assuming well set for Crud max.
                    # Below two lines speed up whole script significantly (rather than just using THRESH setting for LumaTol).

                    # arg frame order IS SIGNIFICANT (we are matching to i frame, estimate is for i-1).
                    LumaTol = RT_QwikScanEstimateLumaTol(Last,Last,n=i,n2=i-1)
                    LumaTol = LumaTol_Scale * LumaTol + LumaTol_Add
                    LumaTol = (LumaTol>THRESH) ? THRESH : LumaTol

                    DifThresh = PreUndoDif*0.999999                              # We are looking for BETTER match, NOT equal

                    if(VERBOSITY>=1) {
                        S = RT_String("%5d]    NEWSEARCH: SearchStart=%d SearchEnd=%d Seeking FDif <= %E {LumaTol=%E}",
                                \ i,StartFrame,EndFrame,DifThresh,LumaTol)
                        RT_DebugF("%s",S,name=myName)
                        RT_WriteFile(LOG,"%s",S,Append=True)
                    }
                    For(j=StartFrame,EndFrame) {
                        MaxDistance =  EndFrame - j
                        if(VERBOSITY>=2) {
                            S = RT_String("             SEARCH: SearchStart=%d MaxDistance=%d",j,MaxDistance)
                            RT_DebugF("%s",S,name=myName)
                            RT_WriteFile(LOG,"%s",S,Append=True)
                        }
                        # XP=3, strictly better than, ie left most frame (first found, furthest from i).
                        # MaxDistance limits search to exclude MIN_EDITLEN frames.
                        Result=RT_QwikScan(Last,j,Last,i,ARR,NEXT,lumatol=LumaTol,Flags=$04,fd=DifThresh,maxdistance=MaxDistance,XP=3)
                        if(Result>=0) { # Exit Condition succeeds
                            FramesSearched = FramesSearched + (QWKS_BM_FD_FRM-j+1)
                            if(VERBOSITY>=2) {
                                S = RT_String("              MATCH: Frame=%5d FrameDifference=%E ",QWKS_BM_FD_FRM,QWKS_BM_FD)
                                RT_DebugF("%s",S,name=myName)
                                RT_WriteFile(LOG,"%s",S,Append=True)
                            }
                            CrudPix=RT_LumaPixelsDifferentCount(Last,Last,n=i,n2=QWKS_BM_FD_FRM,Thresh=OVR_PIXCNT_THR)
                            FramesSearched = FramesSearched + 1
                            if(CrudPix <= OVR_PIXCNT_LIM) {
                                YCrudDif = RT_QwikScanEstimateLumaTol(Last,Last,n=i,n2=QWKS_BM_FD_FRM)   # Crud measured by LumaTol estimate
                                FramesSearched = FramesSearched + 1
                                if(YCrudDif > CrudMax) {
                                    CrudMax         = YCrudDif
                                    CrudMaxFrame    = i
                                }
                                if(CrudPix > PixCntMax) {
                                    PixCntMax = CrudPix
                                    PixCntMaxFrame = i
                                }
                                RT_DBaseAppend(CRUD_DB,QWKS_BM_FD_FRM,i)      
                                if(VERBOSITY==0) {
                                    S=RT_String("%5d] UNDO: Matched %d -> %d : Skip %d to %d : (FDif=%E : LumaPixelsDifferentBy_%d = %d)",
                                        \ i,QWKS_BM_FD_FRM,i,QWKS_BM_FD_FRM+1,i,QWKS_BM_FD,OVR_PIXCNT_THR,CrudPix)
                                } Else {
                                    S=RT_String("               UNDO: Matched %d -> %d : Skip %d to %d : (FDif=%E : LumaPixelsDifferentBy_%d = %d)",
                                    \ QWKS_BM_FD_FRM,i,QWKS_BM_FD_FRM+1,i,QWKS_BM_FD,OVR_PIXCNT_THR,CrudPix)
                                }
                                RT_DebugF("%s",S,name=myName)
                                RT_WriteFile(LOG,"%s",S,Append=True)
                                i = QWKS_BM_FD_FRM+1 # Skip edited Frames up to and including UNDO frame:  Rescan @ i - 1
                                SKIP = True # Dont write i
                                if(VERBOSITY>=2) {
                                    S=RT_String("             RESCAN: @ %d",i-1)
                                    RT_DebugF("%s",S,name=myName)
                                    RT_WriteFile(LOG,"%s",S,Append=True)
                                }
                                j = EndFrame                                            # Break
                            } Else {
                                if(VERBOSITY>=2){
                                    S=RT_String("           OVERRIDE: LumaPixelsDifferentBy_%d = %d (I -> Matched Frame)",OVR_PIXCNT_THR,CrudPix)
                                    RT_DebugF("%s",S,name=myName)
                                    RT_WriteFile(LOG,"%s",S,Append=True)
                                }
                                j = QWKS_BM_FD_FRM                                      # Continue search
                            }
                        } Else { # Result < 0, Exit condition fails
                            FramesSearched = FramesSearched + MaxDistance + 1           # Searched full extent
                            if(VERBOSITY>=3) {
                                if(QWKS_BM_FLAGS!=0) {                                  # Got a Best Match Only
                                    S = RT_String("          NOT FOUND: Best Match Frame=%5d FDif=%E",QWKS_BM_FD_FRM,QWKS_BM_FD)
                                } Else {                                                # Did not even get a Best match
                                    S = RT_String("          NOT FOUND: No Best Match:")
                                }
                                RT_DebugF("%s",S,name=myName)
                                RT_WriteFile(LOG,"%s",S,Append=True)
                            }
                            j = EndFrame                                                # Break
                        }
                    }      # End for j
                } Else {   # PreUndoDif <= 0.0
                    if(VERBOSITY>=2) {
                        d = i-1
                        for(k=d-1,0,-1) {
                            Dif = RT_FrameDifference(Last,Last,n=i,n2=k,ChromaWeight=ChromaWeight)
                            FramesSearched = FramesSearched + 1
                            if(Dif == 0.0) {
                                d = k
                            } Else {
                                k = - 1
                            }
                        }
                        S=RT_String("%5d]    IDENTICAL: Frames %d to %d : Skipping Frames %d to %d",i,d,i,d+1,i)
                        RT_DebugF("%s",S,name=myName)
                        RT_WriteFile(LOG,"%s",S,Append=True)
                        i = d+1     # Retry at d
                    }
                    SKIP = True # Dont write i
                }
            } # i == 0
            if(!SKIP || i==0) {
                if(VERBOSITY>=3 || i==0) {
                    if(i==0)    {S=RT_String("%5d]      WRITING: Frame %d",i,i) }
                    Else        {S=RT_String("            WRITING: Frame %d",i) }
                    RT_DebugF("%s",S,name=myName)
                    RT_WriteFile(LOG,"%s",S,Append=True)
                }
                RT_WriteFile(CMDFrames,"%d",i,Append=True)
                Kept = Kept + 1
            }
        }

    # Delayed write of crud frames (cannot now use FrameSel(Ordered=True) in Crud_Inspect script due to RESCAN duplicate frames Nos)        
    for(i=RT_DBaseRecords(CRUD_DB)-1,0,-1) {
        RT_WriteFile(CrudFrames,"%d\n%d",RT_DBaseGetField(CRUD_DB,i,0),RT_DBaseGetField(CRUD_DB,i,1),Append=True)
    }
    RT_FileDelete(CRUD_DB)

    RT_WriteFile(ScriptFile,"%s",Select_S)
    RT_WriteFile(CrudScript,"%s",Crud_S)
    (DELETE_ARR) ? RT_FileDelete(ARR)     : NOP
    (DELETE_ARR) ? RT_FileDelete(NEXT) : NOP
    T = RT_TimerHP - START
    FT=FrameCount / FrameRate
    S=RT_String("\nKept %d of %d frames [%dx%d %.2f secs (%.2f Mins) @ %.2f FPS]",Kept, FrameCount,ORG.Width,ORG.Height,FT,FT/60.0,FrameRate)
    RT_DebugF(S,name=myName)
    RT_WriteFile(LOG,"%s",S,Append=True)
    S=RT_String("File Max Successful CrudMax = %E CrudMaxFrame=%d",CrudMax,CrudMaxFrame)
    RT_DebugF(S,name=myName)
    RT_WriteFile(LOG,"%s",S,Append=True)
    S=RT_String("File Max Successful LumaPixelsDifferentBy_%d = %d @ Frame = %d",ovr_pixcnt_thr,PixCntMax,PixCntMaxFrame)
    RT_DebugF(S,name=myName)
    RT_WriteFile(LOG,"%s",S,Append=True)
    S=RT_String("QWIK SCAN %.2f Secs (%.2f Mins) InFPS=%.2f OutFPS=%.2f FramesSearched=%d FramesSearchedFPS=%.2f",
            \ T,T/60.0,FrameCount/T,Kept/T,FramesSearched,FramesSearched/T)
    RT_DebugF(S,name=myName)
    RT_WriteFile(LOG,"%s",S,Append=True)
    Global Global_CrudMax   = Max(Global_CrudMax,CrudMax)
    Global Global_PixCntMax = Max(Global_PixCntMax,PixCntMax)
    """)
    Return 0
}
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but are any of them infinitely bigger ???
StainlessS is offline   Reply With Quote
Reply

Tags
avisynth, detection, duplicated, frames, trim

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 02:54.


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