VideoHelp Forum


Try DVDFab Video Downloader and rip Netflix video! Or Try DVDFab and copy Blu-rays! or rip iTunes movies!
+ Reply to Thread
Results 1 to 8 of 8
Thread
  1. Hi,

    Trying to get the max RGB levels of a clip.
    I have this after splitting the clip into RGB:

    Code:
    Scriptclip(clip,"
    r = YplaneMax(RE)
    g = YplaneMax(GR)	
    b = YplaneMax(BL)
    
    max = (r >= g && r >= b) ? r : (g >= b) ? g : b)
    ")
    Somehow the conditional will not work. What I'm doing wrong?
    Quote Quote  
  2. Member
    Join Date
    Aug 2013
    Location
    Central Germany
    Search PM
    ScriptClip allows calling one function. One function. Your example might work if you declare this whole snippet as a function to call it.

    But wait ... what does it do? The function YPlaneMax() returns the maximum of the Y plane. Are the clips RE, GR, and BL calculated before? Is the value in max used in further calculations?
    Last edited by LigH.de; 6th May 2017 at 14:38.
    Quote Quote  
  3. It works if you make the following changes:
    Code:
    clip=clip.ConvertToRGB32
    RE=clip.ShowRed  ("YV12")
    GR=clip.ShowGreen("YV12")
    BL=clip.ShowBlue ("YV12")
    
    Scriptclip(clip,"""
    r = YplaneMax(RE)
    g = YplaneMax(GR)   
    b = YplaneMax(BL)
    
    max = (r >= g && r >= b) ? r : (g >= b) ? g : b #) ## extra closing paren omitted 
    """)
    BTW, the last line can be replaced with
    Code:
    max=Max(r, g, b)
    And you won't see any result out of this ScriptClip unless you insert something that uses max, like for example:
    Code:
    Subtitle("max="+String(max))
    EDIT added triple quotes (""") around ScriptClip, always recommended
    Last edited by raffriff42; 6th May 2017 at 22:20.
    Quote Quote  
  4. And keep in mind that the scope of the variable max is only within ScriptClip.
    Quote Quote  
  5. Originally Posted by LigH.de View Post
    But wait ... what does it do? The function YPlaneMax() returns the maximum of the Y plane. Are the clips RE, GR, and BL calculated before? Is the value in max used in further calculations?
    I use it for sort of autochroma leveling. The clip is splitted in RGB parts first (RE,GR,BL). Then I need to know which of the three has the highest level R, G or B.
    After that I use autolevels to adjust all three with a same amount so the relation between R,G and B stays the same but optimized.
    Say the clip has a RGB of 220,230,240. After leveling it will be 235,245,255 (I use full range).

    So, I need to find which channel (R,G,or B) has the highest value.

    Here's the complete script:

    Code:
    LoadPlugin("plugins/Autolevels_06.dll")
    
    #clip=Avisource("D:/temp/test.avi")
    clip=Avisource("F:/Videos/Bronmateriaal/amerika 1983/amerika_origineel.avi")
    
    
    clip=clip.ConvertToRGB24()
    #source=source.ConverttoYV12()
    
    RE = clip.ShowRed().converttoYV24()
    GR = clip.ShowGreen().converttoYV24()
    BL = clip.ShowBlue().converttoYV24()
    
    Scriptclip(clip,"
    r = YplaneMax(RE)
    g = YplaneMax(GR)	
    b = YplaneMax(BL)
    
    r >= g && r >= b ? max=r : g >= b ? max=g : max=b)	# find greatest channel
    subtitle(string(max),size=48)		#test
    
    diff = 255 - max
    
    RE = RE.Autolevels(coring=true,sceneChgThresh=100,filterRadius=5,output_low=0,output_high=r+diff,ignore_low=0.005,ignore_high=0.0001)
    GR = GR.Autolevels(coring=true,sceneChgThresh=100,filterRadius=5,output_low=0,output_high=g+diff,ignore_low=0.005,ignore_high=0.0001)
    BL = BL.Autolevels(coring=true,sceneChgThresh=100,filterRadius=5,output_low=0,output_high=b+diff,ignore_low=0.005,ignore_high=0.0001)
    
    MergeRGB(RE,GR,BL)
    
    ")
    Quote Quote  
  6. Originally Posted by raffriff42 View Post
    It works if you make the following changes:
    Code:
    clip=clip.ConvertToRGB32
    RE=clip.ShowRed  ("YV12")
    GR=clip.ShowGreen("YV12")
    BL=clip.ShowBlue ("YV12")
    
    Scriptclip(clip,"""
    r = YplaneMax(RE)
    g = YplaneMax(GR)   
    b = YplaneMax(BL)
    
    max = (r >= g && r >= b) ? r : (g >= b) ? g : b #) ## extra closing paren omitted 
    """)
    BTW, the last line can be replaced with
    Code:
    max=Max(r, g, b)
    And you won't see any result out of this ScriptClip unless you insert something that uses max, like for example:
    Code:
    Subtitle("max="+String(max))
    EDIT added triple quotes (""") around ScriptClip, always recommended
    Thanks for your tips!
    Never thought of that "Max". Much easier than the crap I had....
    Quote Quote  
  7. Originally Posted by jagabo View Post
    And keep in mind that the scope of the variable max is only within ScriptClip.
    ....and no way to get it out? Global? Would make life easier....
    Quote Quote  
  8. Code:
    RE = clip.ShowRed().converttoYV24()
    GR = clip.ShowGreen().converttoYV24()
    BL = clip.ShowBlue().converttoYV24()
    
    Scriptclip(clip,"
    r = YplaneMax(RE)
    g = YplaneMax(GR)   
    b = YplaneMax(BL)
    
    /*
    r >= g && r >= b ? max=r : g >= b ? max=g : max=b)  # find greatest channel
    #                     ^                ^       ^ ^  ## (4 syntax errors)
    */
    ## REWRITTEN
    max = (r>=g && r>=b) ? r : (g>=b) ? g : b  # find greatest channel
    
    ## REWRITTEN AGAIN
    max = Max(r, g, b)  # find greatest channel
    
    subtitle(string(max),size=48)       #test
    ## ABOVE HAS NO EFFECT (OVERRIDDEN BY MergeRGB BELOW)
    
    diff = 255 - max
    
    RE = RE.Autolevels(coring=true,sceneChgThresh=100,filterRadius=5,output_low=0,output_high=r+diff,ignore_low=0.005,ignore_high=0.0001)
    GR = GR.Autolevels(coring=true,sceneChgThresh=100,filterRadius=5,output_low=0,output_high=g+diff,ignore_low=0.005,ignore_high=0.0001)
    BL = BL.Autolevels(coring=true,sceneChgThresh=100,filterRadius=5,output_low=0,output_high=b+diff,ignore_low=0.005,ignore_high=0.0001)
    
    MergeRGB(RE,GR,BL)
    subtitle(string(max),size=48)       #test (MOVED DOWN)
    
    ")

    Originally Posted by PeterNL View Post
    Originally Posted by jagabo View Post
    And keep in mind that the scope of the variable max is only within ScriptClip.
    ....and no way to get it out? Global? Would make life easier....
    It is a per-frame variable, therefore it must be used in a run-time filter like ScriptClip.


    EDIT by the way, it sounds like you might want to try ColorYUV(autowhite=true, autogain=true) or, for nicer results, GamMac ["Gamma Machine"].
    Last edited by raffriff42; 7th May 2017 at 09:39.
    Quote Quote  



Similar Threads