View Full Version : Assess the brightness of an area of frame
postler1978
9th July 2012, 16:50
Hello.
I would like to ask you for an advice. I would like to asses the brightness of (constantly) predefined area of frame and - depending on that value - to trigger a command.
Is there a command that would be able to return a value of brightness of a certain area of an each single frame ?
More detailed, I want to do something like that:
1 Select a part of frame (left,up,width,height) (where the borders are same for all the frames).
2 Get a brightness value of the selected part of frame
3 IF the brightness > const THEN DELETE the frame
4 go to next frame
I suppose, the most close to this issue was the link:
http://forum.doom9.org/showthread.php?t=132264&highlight=determine+brightness
but I have no idea, how to get the value of brightness itself.
If avisynth is not suitable program to solve this problem, could you recommend an other program for that purpose to me, please.
Thanks
jmac698
9th July 2012, 20:40
From http://avisynth.org/mediawiki/Advanced_Scripting_Tips (which I wrote, btw - very useful reference)
colorbars(pixel_type="YV12")
area=last.Crop(220, 324, -368, -122)
current_frame=0
luma=area.AverageLuma()
messageclip(string(luma))
In order to do anything on a frame-by-frame basis, you must use scriptclip. I don't have time to write the whole thing now, but it's something like this:
colorbars(pixel_type="YV12")
Scriptclip("""
thresh=50
area=last.Crop(220, 324, -368, -122)
luma=area.AverageLuma()
subtitle(string(luma))
luma>thresh?subtitle("delete this frame",y=16):last
""")
StainlessS
9th July 2012, 21:18
See here:
http://forum.doom9.org/showthread.php?p=1539598#post1539598
Using AverageLuma.
EDIT:
# PASS 1
source=avisource("D:\avs\avi\1.avi").ConvertToYV12()
X = 40 # X-Coord of Crop area, For your Area of Interest.
Y = 40 # Y-Coord of Crop area
W = 32 # Width of Crop area, YV12, MOD4
H = 32 # Height of Crop area, YV12, MOD4
METRICS = True # True To Show Metrics (NO Pass1 CMD file Created)
DIM = True # True will dim NON Area Of Interest when viewing Metrics
Thresh = 128.0 # 0.0 -> 255.0, Threshold for frame drops. SET using view metrics
ALIGN = 7 # METRICS SubTitle Alignment 7=TopLeft, 1=BotLeft (As KeyPad)
# -----------------------
cropped=source.Crop(X,Y,W,H) # Your area of interest
source = (DIM) ? source.levels(0,1.0,255,0,128).Overlay(cropped,x=X,y=Y,opacity=1.0) : source
Return (METRICS)\
? source.ScriptClip(""" TmpAL=cropped.AverageLuma() Subtitle(String(TmpAL) + ((TmpAL>Thresh)?" DROP":""),align=ALIGN)""" ) \
: cropped.PruneDeleteFrames("cmd.txt","AverageLuma>Thresh",Fast=True)
Function PruneDeleteFrames(clip c, string fileName, string condition, bool "Fast") {
# Conditional DELETE frames Command File generator for Prune()
# MUST call with correct colorspace for condition eg YDifferenceFromPrevious requires a Planar colorspace.
# Is EXACT opposite of PruneKeepFrames() for same conditional.
# NOTE, any additional end frame condition as used in PruneKeepFrames, will also be inverted
# eg " || current_frame==0", frame 0 would be deleted.
c=(Default(Fast,true))?c.AssumeFPS(250.0):c # Fast as we can if Fast = true (Default true)
condition = "!(" + condition + ")"
WriteFileIf(c, fileName, condition, """ "0," """, "current_frame", append=false)
}
#PASS 2
Source=avisource("D:\avs\avi\1.avi") #.ConvertToYV12() YV12 Not needed for Pass 2
SHOW=False # Change to True to show which source frames are being used.
Source.Prune(CMD="cmd.txt",show=SHOW)
StainlessS
10th July 2012, 23:07
Previous post updated.
postler1978
15th July 2012, 18:19
Thank you very much for your help, jmac698 and StainlessS. Let me some time to try it. Thank you.
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.