View Single Post
Old 24th September 2015, 01:01   #15  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Part 1 of LightningSelectFrames.avs (Too big for post)
Code:
#LightningSelectFrames.avs      # Req:- GScript, Grunt, RT_Stats, FrameSel, Prune.

Function ShowDB(clip c,String DB) {
/*
    ShowDB(), Show DB Status, MUST at least call InitDB beforehand.
    If not sequenced then will only show AverageLuma for each frame.
    If Sequenced then shows Sequence info.
    If both Sequenced and Partitioned, then shows Sequence and Partition info.     
*/
    c           myName="ShowDB: "
    Records   = RT_DBaseRecords(DB)     Assert(Records==FrameCount,RT_String("%sFrameCount/Records mismatch",myName))
    Th        = RT_DBaseGetID(DB,0)     nSeqs     = RT_DBaseGetID(DB,1)     PartFrames= RT_DBaseGetID(DB,2)     nParts    = RT_DBaseGetID(DB,3)
    Fmt="%d] AveY=%.2f\nSEQ:%-5d} Type='%c' Start=%-6d End=%-6d FlashFrm=%d\nPART:%4d} Type='%c' Start=%-6d End=%-6d"
    Fmt2="Thresh=%.2f : nSeqs=%d : PartFrames=%d : nParts=%d"
    SSS="""
        n    = current_frame
        RT_Subtitle(Fmt,
            \ n,RT_DBaseGetField(DB,n,0),RT_DBaseGetField(DB,n,1),RT_Ord("-DL",RT_DBaseGetField(DB,n,2)+2),
            \ RT_DBaseGetField(DB,n,3),RT_DBaseGetField(DB,n,4),RT_DBaseGetField(DB,n,5),
            \ RT_DBaseGetField(DB,n,6),RT_Ord("-DL",RT_DBaseGetField(DB,n,7)+2),RT_DBaseGetField(DB,n,8),RT_DBaseGetField(DB,n,9))            
        RT_SubTitle(Fmt2,Th,nSeqs,PartFrames,nParts,align=1)
        Return Last
    """
    Last.GScriptClip(SSS,ARGS="Fmt,Fmt2,DB,Th,nSeqs,PartFrames,nParts",Local=True)
    Return Last
}

Function WriteFlashFrames(String DB,String FN) {            # Write 1 frame from each sequence with highest AveLuma
    myName="WriteFlashFrames: "         FC = RT_DBaseRecords(DB)            nSeqs = RT_DBaseGetID(DB,1)         RT_FileDelete(FN)
    Assert(nSeqs > 0, RT_String("%sDBase Not Sequenced, Call SequenceDB(Thresh)",myName))
    GSCript("""
        For(i=0,FC-1) {
            SeqType = RT_DBaseGetField(DB,i,2)              # 0 = DARK seq : 1= LIGHT seq
            SeqEnd  = RT_DBaseGetField(DB,i,4)              # Seq End        
            if(SeqType==1) {RT_WriteFile(FN,"%d",RT_DBaseGetField(DB,i,5),Append=True)} # Frame with greatest AveLuma in seq
            i=SeqEnd                                        # next iteration SeqEnd + 1 is Start of next Seq
        }
    """)
    Return 0
}

Function WriteFlashSeqs(String DB,String FN) {              # Write all L type sequences
    myName="WriteFlashseqs: "           FC = RT_DBaseRecords(DB)            nSeqs = RT_DBaseGetID(DB,1)    RT_FileDelete(FN)
    Assert(nSeqs > 0, RT_String("%sDBase Not Sequenced, Call SequenceDB(Thresh)",myName))
    GSCript("""
        For(i=0,FC-1) {
            SeqType = RT_DBaseGetField(DB,i,2)              # 0 = DARK seq : 1= LIGHT seq
            SeqEnd  = RT_DBaseGetField(DB,i,4)              # Seq End        
            if(SeqType==1) {
                SeqLen = SeqEnd - i + 1
                (SeqLen==1) ? RT_WriteFile(FN,"%d",i,Append=True) : RT_WriteFile(FN,"%d,%d",i,SeqEnd,Append=True)
            }
            i=SeqEnd                                        # next iteration SeqEnd + 1 is Start of next Seq
        }
    """)
    Return 0
}

Function WriteFlashParts(String DB,String FN) {             # Write all L type Partitions
    myName="WriteFlashParts: "          FC = RT_DBaseRecords(DB)            nParts = RT_DBaseGetID(DB,3)    RT_FileDelete(FN)
    Assert(nParts > 0, RT_String("%sDBase Not Partitioned, Call PartitionDB(PartFrames)",myName))
    GSCript("""
        For(i=0,FC-1) {
            PartType= RT_DBaseGetField(DB,i,7)              # 0 = DARK Part : 1= LIGHT Part
            PartEnd = RT_DBaseGetField(DB,i,9)              # Part End        
            if(PartType==1) {
                PartLen = PartEnd - i + 1
                (PartLen==1) ? RT_WriteFile(FN,"%d",i,Append=True) : RT_WriteFile(FN,"%d,%d",i,PartEnd,Append=True)
            }
            i=PartEnd                                       # next iteration PartEnd + 1 is Start of next Part
        }
    """)
    Return 0
}

Function GetFlashFrames(clip c,String DB) {
    FN="Flash_"+RT_LocalTimeString(File=True)+".txt"   WriteFlashFrames(DB,FN)   Flashframes=SelectRanges(c,Cmd=FN)
    RT_FileDelete(FN)           Return Flashframes.KillAudio
}

Function GetSeqs(clip c,String DB,Bool "Dark") {
    Dark = Default(Dark,False)  FN="Seqs_"+RT_LocalTimeString(File=True)+".txt"
    WriteFlashSeqs(DB,FN)       Seqs=(Dark) ? RejectRanges(c,Cmd=FN) : SelectRanges(c,Cmd=FN)
    RT_FileDelete(FN)           Return Seqs
}

Function GetParts(clip c,String DB,Bool "Dark") {
    Dark = Default(Dark,False)   FN="Parts_"+RT_LocalTimeString(File=True)+".txt"
    WriteFlashParts(DB,FN)      Parts=(Dark) ? RejectRanges(c,Cmd=FN) : SelectRanges(c,Cmd=FN) 
    RT_FileDelete(FN)           Return Parts
}
__________________
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 October 2015 at 17:23. Reason: Update
StainlessS is offline   Reply With Quote