Thread: U-V-Swap issue
View Single Post
Old 13th September 2018, 01:11   #14  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Additional Demo.

All done in one script, init DBase with scene change data, scan each scene getting min and max aveluma of scene, update DBase with min/max stuff
then play clip showing result scene numbers, and scene min/max aveluma for each frame in scene.

Code:
######
# Demo, Add something to DBase for each scene/record, in this case just min and max average luma as 2 Floats @ Field 2=min, 3=max
######
AVISource("D:\Parade.AVI")
DB="D:\Parade.DB"
######
# 1st Create DBase with 2 additional fields
######
RT_DBaseAlloc(DB,0,"iiff")          # Alloc two int fields for SOS & EOS, also add Field 2 Float for MinAveLuma, and Field 3 for MaxAveLuma
Records = DBase_DetectScenes(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)
#return MessageClip("DONE")

######
### 2nd, Scan scenes in clip, establish Min/max luma for each scene, and update DBase
### Using AVS+ here, mod if using GSCript
######
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)
    MinLum=256.0    MaxLum=-1.0           # Prep for scene
    for(frm=SFrm,EFrm) {                  # Scan all Frames in Scene
        AveLum=RT_AverageLuma(n=frm)      # could specify eg area to measure eg x=32,y=32,w=-32,h=-32 # as for crop(32,32,-32,-32)
        MinLum=Min(MinLum,AveLum)
        MaxLum=Max(MaxLum,AveLum)
    }
    RT_DbaseSetField(DB,scene,2,MinLum)     # Set Minimum encountered luma in this scene to 3rd field, field 2
    RT_DbaseSetField(DB,scene,3,MaxLum)     # Set Maximum encountered luma in this scene to 4th field, field 3
    RT_DebugF("DEMO: Scene#%d[%d,%d] MinLuma=%.3f MaxLuma=%.3f",scene,SFrm,EFrm,MinLum,MaxLum) # See output in DebugView (Google)
}
#return MessageClip("DONE")

######
# 3rd, NOW PLAY Clip
######

SSS="""
    n=current_frame
    Record=DB_FindTrim(DB,0,1,n)                            # Record or scene number (relative 0) # -1 NOT FOUND
    if(Record>=0) {
        Records    = RT_DBaseREcords(DB)                    # Show number of records ie scenes
        SceneStart = RT_DBaseGetField(DB,Record,0)          # Get scene start from field 0 (SOS)
        SceneEnd   = RT_DBaseGetField(DB,Record,1)          # Get scene end from field 1 (EOS)
        MinLum     = RT_DBaseGetField(DB,Record,2)          # Get MinLuma for entire scene (same for each frame in scene)
        MaxLum     = RT_DBaseGetField(DB,Record,3)          # Get MaxLuma for entire scene (same for each frame in scene)
        SceneFMax  = SceneEnd-SceneStart                    # For show scene relative frame number n/nmax, 0 rel
        RT_Subtitle("%d/%d] #%d/%d:%d/%d[%d,%d,Len=%d]\nMinLuma=%.3f\nMaxLuma=%.3f",
            \ n,FrameCount-1,Record,Records-1,n-scenestart,SceneFMax,SceneStart,SceneEnd,SceneFMax+1,MinLum,MaxLum)
    } Else { Subtitle("ERROR: RECORD NOT FOUND !",align=5,size=48)}
"""
Scriptclip(SSS)
It will take some time before playing with long clip (scan for scene change/ scan for minmax avluma, then play).

Can view some stuff via DebugView while Scanning (Google)
EDIT: You also need prev posted library funcs.

EDIT: In above ScriptClip Play section, could if required only update scene constant stuff from DBase, when a new scene
is encountered, eg MinLuma is set for entire scene, and would only need be gotten once per scene, but
is no real problem to get it every time, when it would be a good idea, would be when getting some string
from DBase, where strings take up quite a bit of memory as new string required for every iteration, (waste of mem).
However, if updating only on new record/scene, then would require a Global variable to remember the previous record/scene,
and also the previous string.
__________________
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; 13th September 2018 at 16:57.
StainlessS is offline   Reply With Quote