View Single Post
Old 23rd January 2018, 05:47   #10  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Quote:
Will come back a few days later
Very diplomatic of you.
The previous attempt was pretty awful, guess you need time to think up some response
I'll return original script back to nearer original post, we dont want anyone using that, but could be good lesson to keep without the recent screwed up attempt.

Here, some mods, hope it performs better for you.
Suggest that you try demo before anything else (always a good suggestion when I supply demo).

Fred_CSV.Txt, copy to file.
Code:
# test CSV File, StartFrame, EndFrame, Value(Int converted to FLOAT, VarMax=100.0)
   0,  0,    0     # Values (3rd field) int's will be converted to Float.
   1,  1,   10
   2,  2,   20
   3,  3,   30
   4,  4,   40
   5,  5,   50
   6,  6,   60
   7,  7,   70
   8,  8,   80
   9,  9,   90
  10, 10,  100
  11,  99,   0
 200, 299,  10
 400, 499,  20
 600, 699,  30
 800, 899,  40
1000,1099,  50
1200,1299,  60
1400,1499,  70
1600,1699,  80
1800,1899,  90
2000,2099, 100
2200,9999, 100
Make_DBase.avs (NOTE, third field now FLOAT (will accept int and convert).
Code:
# Make_DBase.avs
#########################
CSV="Fred_CSV.Txt"      # CSV.txt file containing text something like this
### Three Fields in DBase: Field 0=StartFrame, 1=EndFrame, 2=Value (NOW FLOAT)
# 100,200, 50
# 400,500, 60
# 700,750, 70
# 900,999, 80
###
DB            = "Fred_CSV.DB"
TypeString    = "iif"              # 3 DB Fields, 2 type Int, 1 type FLOAT. (Can supply Value field as int, will be converted to Float.
                                   # b=BOOL,i=INT,f=FLOAT,s=STRING,n=BIN(8bit Int).
###
CSV=RT_GetFullPathName(CSV)
DB=RT_GetFullPathName(DB)
RT_DBaseAlloc(DB,0,TypeString)     # Allocate DBase with 0 pre-allocated records, three Fields.
###
Added=RT_DBaseReadCSV(DB,CSV)
RT_DBaseQuickSort(DB,Field2=1)     # Ensure Ranges in sorted order (Ranges should NOT overlap).
Return MessageClip("Added "+String(Added)+" Records")   # Shows "Added 4 Records where same as above Fred_CSV.Txt Example".
FredDB.Avs
Code:
# FredDB.Avs : Required GamMac, GScript, Grunt, RT_Stats v2.0 Beta(latest).
GScript("""
    Function FredFun(clip c,String DB,Float Default_Val,Float ValMax,Int DampHeight,Bool Show) {
        myName="FredFun: "
        c
        n           = current_frame
        Records     = RT_DBaseRecords(DB)   # Number of records in the DBase
        Start_Field = 0                     # Field in DBase that holds Start Frame Int (as per CSV file).
        End_Field   = 1                     # Field in DBase that holds End Frame Int.
        Val_Field   = 2                     # Field in DBase that holds Fred Value (in this case is a Float as specified in DB TypeString).
        Find_Frame  = n                     # Frame Number to search for in DBase.
        Low         = 0                     # Default 0. Lowest record number to scan (likely almost always 0).
        High        = Records-1             # Highest record number to scan (likely almost always as default RT_DBaseRecords(DB)-1).
        FndRec=RT_DBaseFindSeq(DB,Start_Field,End_Field,Find_Frame,Low=Low,High=High)  # Search DBase for sequence holding current_frame n
        if(FndRec>=0) {
            UseVal = RT_DBaseGetField(DB, FndRec, Val_Field)    # Get the value set for this frame (third val in CSV file)
        } Else {                                                # Fndrec -1, Record containing current frame Not Found
            UseVal = Default_Val                                # Use the Default, ie range not set in CSV.
        }
        Assert(0.0 <= UseVal <= ValMax, RT_String("FredFun: 0 <= ValMax <= %.2f (%.2f)",ValMax,UseVal))  # UseVal Range 0 -> ValMax ONLY

        PIC_HEIGHT = Height - DampHeight - (SHOW?48:0)
        Cropped = Last.Crop(0,0,0,PIC_HEIGHT)                                 # Remove Temp Padding
        RealAve = Cropped.FredAverage.BilinearResize(Width,DampHeight)       # This is actual Average
        FredAve = RealAve.Invert                                              # This is negative of Average (Fred's Average)
        op      = (Float(UseVal) / ValMax)
        Damper  = OverLay(RealAve,FredAve,Opacity=op)
        StackVertical(Cropped,Damper)                                         # Dampen GamMac

        if(Show) {
            if(FndRec>=0) {
                SIZE  = Cropped.Height/14
                COLOR = $FF00FF
                Start = RT_DBaseGetField(DB, FndRec, Start_Field)       # Where this range starts
                End   = RT_DBaseGetField(DB, FndRec, End_Field)         # Where this range ends
                S = RT_String("%d:%d:%d,%d] Val = %.2f",n,FndRec,Start,End,UseVal)
            } Else {
                SIZE  = Cropped.Height/18
                COLOR = $FFFF00
                S = RT_String("%d] Val = %.2f",n,UseVal)
            }
            Subtitle(S,Align=5,y=(Cropped.Height+SIZE)/2,Size=SIZE,Text_Color=COLOR)
            K=Last.BlankClip(Height=4)
            RA=RealAve.BilinearResize(Width,20)
            FA=RA.Invert
            FA=FA.Subtitle(RT_String("FredAve : Opacity=%.2f (%.1f / %.1f)",Op,UseVal,ValMax))
            RA=RA.Subtitle("RealAve")
            AveBlock=StackVertical(K,FA,K,RA)                           # Metrics Block
            StackVertical(Last,AveBlock)
        }
        Return Last
    }
""")

# Stack Overhead Subtitle Text, with optional FrameNumber shown.
Function TSub(clip c,string Tit,Bool "ShowFrameNo"){
    c.BlankClip(height=20)
    (Default(ShowFrameNo,False))?ScriptClip("""Subtitle(String(current_frame,"%.f] """+Tit+""""))"""):Subtitle(Tit)
    Return StackVertical(c).AudioDubEx(c)
}

#################################
####         CONFIG          ####
#################################
FN          = "Parade.Avi"
DB          = "Fred_CSV.DB"
DampHeight  = 20                # Height of Dampen Bar, also adjusts Maximum Possible GamMac Dampening Effect, bigger, more dampening possible,
ValMax      = 100.0             # Float, Default_Val and CSV entries must be 0.0 -> VALMAX range. (Damper Maximum)
Default_Val = 75.0              # Float, GamMac Dampener Default Value, higher more dampening, ValMAx = Fully Damped.
SHOW        = true              # FredFun Show Metrics
GSHOW       = true              # GamMac Metrics
FINAL       = False             # True, No Metrics, Single Frame Final Result.
##### GamMac args
LockChan    = 1
SCale       = 2
RedMul      = 1.0
GrnMul      = 1.0
BluMul      = 1.0
Th          = 0.0
LockVal     = 128.0
OMin        = 0
OMax        = 255
Verbosity   = 2
################################
####       END CONFIG       ####
################################
SHOW =(FINAL)?FALSE:SHOW
GSHOW=(FINAL)?FALSE:GSHOW
FN          = RT_GetFullPathName(FN)
DB          = RT_GetFullPathName(DB)
ARGS        = "DB,Default_Val,ValMax,DampHeight,Show"               # FredFun args, excluding clip c
ABlk_H      = SHOW?48:0
CROPOFF     = DampHeight + ABlk_H
###
AviSource(FN).ConvertToRGB32                                        # Maybe Change source filter.
ORG=Last
#
AddBorders(0,0,0,CROPOFF,$0000)                                     # Add Padding to Bottom (ScriptClip can only return SAME SIZE as INPUT)
Last.GScriptClip("FredFun(last, "+ARGS+")", local=True, args=ARGS)  # FredFun, Add ColorBlock (Damper + AveBlock)
ColorBlock = Last.Crop(0,Last.Height-CROPOFF,0,0)                   # Save full ColorBlock for Later
AveBlock   = (SHOW) ? Last.Crop(0,Last.Height-ABlk_H,0,0) : NOP     # Save AveBlock
DampOrg    = Last.Crop(0,0,0,-ABlk_H)                               # Dont Let GamMac see AveBlock (No effect if SHOW=False)
G_NoDAMP   = ORG.GaMMac(Show=GSHOW,LockChan=LockChan,Scale=Scale,RedMul=RedMul,GrnMul=GrnMul,BluMul=BluMul,
                \ Th=Th,LockVal=LockVal,OMin=OMin,OMax=OMax,Verbosity=Verbosity)
G_Damp     = DampOrg.GamMac(Show=GSHOW,LockChan=LockChan,Scale=Scale,RedMul=RedMul,GrnMul=GrnMul,BluMul=BluMul,
                \ Th=Th,LockVal=LockVal,OMin=OMin,OMax=OMax,Verbosity=Verbosity)
G_DampNoMet= DampOrg.GamMac(Show=False,LockChan=LockChan,Scale=Scale,RedMul=RedMul,GrnMul=GrnMul,BluMul=BluMul,
                \ Th=Th,LockVal=LockVal,OMin=OMin,OMax=OMax,Verbosity=Verbosity)
WIN_1 = StackVertical(ORG,ColorBlock)
WIN_2 = G_NoDAMP.AddBorders(0,0,0,CROPOFF,$0000)
WIN_3 = (SHOW) ? StackVertical(G_Damp,AveBlock)  : G_Damp
WIN_4 = (SHOW) ? StackVertical(G_DampNoMet,AveBlock)  : G_DampNoMet
WIN_1 = (!FINAL) ? WIN_1.TSub("Original + DBar" + (SHOW?" + Dampen Metrics":"")) : WIN_1
WIN_2 = (!FINAL) ? WIN_2.TSub("GamMac No Dampen") : WIN_2
WIN_3 = (!FINAL) ? WIN_3.TSub("GamMac Dampen, GamMac mods DBar") : WIN_3
WIN_4 = (!FINAL) ? WIN_4.TSub("GamMac Dampen, GamMac mods DBar, No Metrics") : WIN_4
WIN_TOP=StackHorizontal(WIN_1,WIN_2)
WIN_BOT=StackHorizontal(WIN_3,Win_4)
StackWin = StackVertical(WIN_TOP,WIN_BOT)
Last = !FINAL ? StackWin : WIN_4.Crop(0,0,0,-DampHeight)
Return Last
Higher values Dampen GamMac effect, (could change it to other way around dampening the FredAverage Effect if required).

I'm a bit knackered, 04:46 and so will not say too much more, except hope that it makes up for my previous dismal performance.


EDIT
Below, original frame, with DBar (Dampening bar) + dampening metric.
Top bar (at the bottom) is DBar, and result after Overlay of FredAverage onto real Average, using DB thing Value (scaled 0.0->1.0)
for opacity. NOTE, in other windowed frames, the DBar will be changed by GamMac and so will look different color.
You can adjust the maximum possible (ie 100.0%) by varying the DampHeight (height of DBar), and so increase/decrease every value
setting effect at once.
Code:
DampHeight  = 20                # Height of Dampen Bar, also adjusts Maximum Possible GamMac Dampening Effect, bigger, more dampening possible,
ValMax used for scaling 0.0->1.0 for Opacity, you could make it 1000.0, or 255.0 or whatever, just need give suitable values
in CSV and Default_Value too.
Code:
ValMax      = 100.0             # Float, Default_Val and CSV entries must be 0.0 -> VALMAX range. (Damper Maximum)


EDIT: Above, GamMac effect fully Dampened, with limiting by DBar height.
EDIT: Maybe DBar height DampHeight should be set to eg 10.0% of frame height, or similar.
__________________
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 June 2018 at 18:45.
StainlessS is offline   Reply With Quote