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 15th September 2018, 16:50   #21  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 5,863
Franc62,
This should work perfectly for entire clip (mehopes).
Use original ClipClop script for final render.
I've used correlation, rather than frame diff.
Need prev posted lib funcs.

Code:
###     CONFIG    ###
AVISource("D:\UVSwap.mp4.AVI")
ClipClopName=  "D:\ClipClopCmd.txt"
DB="D:\UVSwap.DB"
DEBUG         = False    # False only write Detections, not metrics
CLIPCLOP_SHOW = True
STACK         = True
CONT_U        = 0  # ColorYUV U Sat adjust for bad range (0=no adjust)
CONT_V        = 0  # ColorYUV V Sat adjust for bad range (0=no adjust)
###### END CONFIG ###
ORG=Last
Crop_L=10 CROP_T=36 CROP_R=-20 CROP_B=-4
MID          = Crop(Crop_L,CROP_T,CROP_R,CROP_B) # Crop off all border crap
UC           = MID.UToY8
VC           = MID.VToY8
SWAPUV_C     = MID.SwapUV()
SWAPUV_UC    = SWAPUV_C.UToY8
SWAPUV_VC    = SWAPUV_C.VToY8
CN_Chroma    = MID.MergeChroma(MID.SelectEvery(1,1))            # Copy Next Chroma into current, Fix End Bad + 1 half bad frame
CN_Chroma_UC = CN_Chroma.UToY8
CN_Chroma_VC = CN_Chroma.VToY8
OUT_V1       = (CONT_U!=0 || CONT_V!=0)?ORG.SwapUV.ColorYUV(cont_u=CONT_U,cont_v=CONT_V):ORG.SwapUV
OUT_V2       = ORG.MergeChroma(ORG.SelectEvery(1,1))
###
ClipClopName = (ClipClopName!="") ? RT_GetFullPathName(ClipClopName) : ""
               (ClipClopName!="") ? RT_Filedelete(ClipClopName)      : NOP

RT_DBaseAlloc(DB,0,"ii")                # Alloc two int fields for SOS & EOS
Records = DBase_DetectScenes(MID,DB)    # Use Defaults for fields, Offset, and thSCD1 and thSCD2
RT_DebugF("DEMO: Detected %d Scenes, added to DBase",Records) # See output in DebugView (Google)

BadSeqs=0
HalfBad=0
Records=RT_DBaseRecords(DB)
For(scene=0,Records-1) {
    SFrm = RT_DBaseGetField(DB,scene,0)                             # Get scene start from field 0 (SOS)
    EFrm = RT_DBaseGetField(DB,scene,1)                             # Get scene end from field 1 (EOS)
    Prev_Start=-1 IN=False Prev_In=False
    for(n=SFrm+1,EFrm) {                                            # Scan Frames in Scene, (start at 1st frame +1)
        U   = RT_LumaCorrelation(UC,UC,n=n-1,n2=n)                  # U prev to current [correlation, higher is better match, -ve is invert)
        V   = RT_LumaCorrelation(VC,VC,n=n-1,n2=n)                  # V prev to current
        USW = RT_LumaCorrelation(UC,SWAPUV_UC,n=n-1,n2=n)           # U prev to current U SWAP
        VSW = RT_LumaCorrelation(VC,SWAPUV_VC,n=n-1,n2=n)           # V prev to current V SWAP
        (DEBUG) ? RT_DebugF("%d] U=%f V=%f USW=%f VSW=%f",n,U,V,USW,VSW) : NOP
        T1 = (USW > U)  T2 = (VSW > V)
        Bingo = T1 && T2
        In = (BINGO) ? !In : IN
        if(In) { # Start
            if(!Prev_In) {
                Prev_start=n
                (DEBUG) ? RT_DebugF("%d] START: = %d",n,Prev_Start) : NOP
            }
        } Else {
            if(Prev_In) { # Stop
                BadSeqs = BadSeqs + 1
                RT_DebugF("%d] STOP: Writing ClipClop replacment with Index 1 clip, range %d,%d",n,Prev_Start,n-1)
                RT_WriteFile(ClipClopName,"1 %d,%d",Prev_Start,n-1,Append=True) # Write ClipClop Range to replace with clip index 1
                SWP_CN_U = RT_LumaCorrelation(SWAPUV_UC, CN_Chroma_UC, n=n-1,n2=n)            # U SWAP prev to current CN_Chroma_U
                SWP_CN_V = RT_LumaCorrelation(SWAPUV_VC, CN_Chroma_VC, n=n-1,n2=n)            # V SWAP prev to current CN_Chroma_V
                SWP_U    = RT_LumaCorrelation(SWAPUV_UC,           UC, n=n-1,n2=n)            # U SWAP prev to current U
                SWP_V    = RT_LumaCorrelation(SWAPUV_VC,           VC, n=n-1,n2=n)            # V SWAP prev to current V
                (DEBUG) ? RT_DebugF("%d] SWP_CN_U=%f SWP_CN_V=%f SWP_U=%f SWP_V=%f",n,SWP_CN_U,SWP_CN_V,SWP_U,SWP_V) : NOP
                T1 = (SWP_CN_U > SWP_U)  T2 = (SWP_CN_V > SWP_V)                              # Correlation to Next chroma better ?
                Bingo = T1 && T2
                if(Bingo) { # Half Bad Frame, next Chroma Better match
                    HalfBad = HalfBad + 1
                    RT_DebugF("%d] HALFBAD: Writing ClipClop replacment with Index 2 clip, Frame %d",n,n)
                    RT_WriteFile(ClipClopName,"2 %d",n,Append=True)             # replace End Bad + 1 frame with clip index 2 frame
                }
                Prev_Start=-1
            }
        }
        Prev_In=In
    }
}

(DEBUG) ? RT_DebugF("BadSeqs=%d HalfBad=%d",BadSeqs,HalfBad) : NOP

NickNames ="""  # Psuedonyms for clips (clip index number)
    SwapUV    = 1 # Fixed Bad range clip (SwapUV with optional Chroma Sat adjustment)
    CN_Chroma = 2 # Fixed half bad end bad + 1 frame (Copy Chroma from next)
"""

ClipClop(ORG,OUT_V1,OUT_V2,Cmd=ClipClopName,nickname=NickNames,show=CLIPCLOP_SHOW)
(STACK)?StackVertical(Last,ORG):Last
EDIT: DEBUG, mod to only write detections, when False.

For any mishaps (dont expect any), then can edit ClipClopCmd.txt file.
EDIT: There are no thresholds, either better match or not, where in initial comparison, 1 pair is expected to be -ve, and other +ve.
EDIT: If 1st frame of scene is swapped, then aint no way we can detect, with likely error, not likely to be able to detect using any
other method either.

EDIT:
Quote:
1 pair is expected to be -ve, and other +ve
What was I thinking, is swapped chroma, not inverted ???
but should still work OK.
__________________
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; 16th September 2018 at 12:12.
StainlessS is offline   Reply With Quote
Old 15th September 2018, 18:42   #22  |  Link
Frank62
Registered User
 
Join Date: Mar 2017
Posts: 29
Thanks, @StainlessS!
Will I need any drivers or other database files to run this, or is the whole database functionality integrated in your RT library, so that the code generates the DB-file and simply works?

I have no time at all to test and try out at the moment, that's a real pity. But I will, by the beginning of next week, that's for sure.
Frank62 is offline   Reply With Quote
Old 15th September 2018, 20:21   #23  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 5,863
Just need RT_Stats, old v1.43 should be OK.
+ Library func DBase_DetectScenes() previousy posted in post #13 [DB_FindTrim() not necessary].
+ MvTools2, Masktools2, Avs+.
Nothing else I think, should 'simply work'.

EDIT:
Quote:
1 pair is expected to be -ve, and other +ve
What was I thinking, is swapped chroma, not inverted ???
but should still work OK.
__________________
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; 15th September 2018 at 20:40.
StainlessS is offline   Reply With Quote
Reply

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 17:42.


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