Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion. Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules. Domains: forum.doom9.org / forum.doom9.net / forum.doom9.se |
|
|||||||
|
|
Thread Tools | Search this Thread | Display Modes |
|
|
#11 | Link |
|
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 11,406
|
Here An updated QueryBorderCrop(), unfortunately, the site screws up at a simple 16K script, so
I'm splitting it into several posts. Here Some of the Text I will have to strip out of the AVS file. Code:
Function QueryBorderCrop(clip c,int "Samples",Float "Thresh",bool "Laced",int "XMod",int "YMod",int "WMod",int "HMod", \
bool "Relative", String "Prefix",int "RLBT",bool "DEBUG",float "Ignore",int "Matrix") {
# QueryBorderCrop v1.08, By StainlessS, Requires GScript & RT_Stats v1.01 Plugins.
# http://forum.doom9.org/showthread.php?p=1586858#post1586858
#
# Prescan function to get coords for eg cropping black borders. Planar, YUY2, RGB.
# Simultaneously returns 4 sets of strings holding crop coords, here is one set: "QBCropX=8 QBCropY=8 QBCropW=640 QBCropH=480".
# String sets are Chr(10) separated, the 'exact found' coords set as above, not rounded at all and possibly throwing an error if
# you try to crop, although could use in eg resize.
# Second set using eg "QBCropXL=8", which is CropLess("L" trailer), ie when rounding for Xmod,WMod etc may leave some black border.
# Third set using eg "QBCropXM=8", which is CropMore, ie when rounding for Xmod,WMod etc may crop some image.
# Forth set using eg "QBCropXP=8", which is CropPlus, moves border positions an extra 2 pixels inwards on each edge and then as CropMore.
# The non-exact coords try to center the coords when cropping for larger WMod/HMod's so as to evenly crop from eg both left and right instead of
# just one side. Also returned in the return string is the used Threshold, perhaps set by AutoThresh, as eg "QBCropThresh=32.0"
# You can use eg Eval(QueryBorderCrop()) to set values into QBCropX, QBCropY,QBCropW,QBCropH etc variables.
#
# Args:-
#
# Samples=24, Number of frames to sample from source clip c.
#
# Thresh= -32.0, Average luma value below or equal to which is considered possible black border, above considered possible image
# (if 3 adjacent pixel rows/columns above Thresh, then taken as image).
# A zero or negative value is 'AutoThresh', will prescan 'Samples' frames looking for minimum pixel luma value (but ignoring a percentage
# of the darkest pixels, see Ignore) and set 'Thresh' to that value plus the negated AutoThresh value, ie defaults sets Thresh to minimum
# found Y value + 32.0.
# Auto cropping will likely fail on END CREDITS ONLY clips, where on black background, and will probably crop off the sides that are no
# different in average luma to any letterbox borders, if you cannot see the borders, then neither can QueryBorderCrop(), even setting the
# auto Thresh to eg -1.0 or 0.0 is quite likely to fail. (See RLBT edge bitflags).
# v1.08, If 'samples' < 12 [samples would have been reduced if greater than framecount], and Thresh is not specified, then default
# AutoThresh will be adjusted.
# Thresh = -(((samples - 1) * (31.5/(12-1))) + 0.5) # samples==1 comes out as -0.5 : samples==12 would come out at -32.0
# So if eg single frame, would use an AutoThresh of -0.5
# If RGB and user specified a PC matrix then AutoThresh would also be scaled up a little (by (255.0/(235-16)).
# The adjustment to auto Thresh where samples < 12, is to reduce the possibility of overcropping on eg a dark single 'Samples' clip,
# but could result in not cropping enough border, its a bit of a balancing act really.
# As an observation, most clips have good border recogition within the 1st 2 sampled frames using the default -32 AutoThresh
# although have noticed some dark clips that required ~8 samples (or more) for full recognition @ default Thresh = -32.
# We use a default Samples=24, because we are intrinsically paranoid.
# To speed up, you may want to leave Auto-Thresh alone and reduce samples, but there is danger that it will not detect all borders
# (overcrop).
# NOTE, The plugin AutoCrop() uses a Thresh of 40.0 and samples == 5 by default (No AutoThresh), but the logic is not too dissimilar.
#
# Laced=true, set true for Interlaced. (Modifies defaults for YMod,HMod, explicit YMod/HMod will override).
#
# XMod, Default: Planar 2, YUY2=2, RGB=1
# YMod, Default: Planar=2, YUY2=1, RGB=1: BUT, Doubled if laced=true.
# WMod, Default: Planar=4, YUY2=2, RGB=1
# HMod, Default: Planar=2, YUY2=1, RGB=1: BUT, Doubled if laced=true.
# The above XMod etc set rounding for the non-exact cropping coords.
# The only real reason for default planar WMod=4 is VirtualDubMod dont like it less than that (Vdub latest, OK).
#
# Relative=false, False returns Width and Height, true returns Width/Height relative eg QBCropW=-6 QBCropH=-4.
#
# Prefix="QBCrop", string for returned variable names, only use valid variable name characters eg NO SPACES. Default returns eg "QBCropX".
#
# RLBT=15=All Borders, Bitflags of edges to crop, 15 ($0F) crops all four. Each letter in the name 'RLBT' represents an edge and bit position
# starting with 'R' in bit 3 representing the value 8 (2^3=8). 'L' = bit 2=4 (2^2=4), 'B' = bit 1=2 (2^1=2), 'T' = bit 0=1 (2^0=1).
# To calculate the RLBT bitflags, for 'R'(Right) add 8, for 'L'(Left) add 4, for 'B'(Bottom) add 2, and for 'T'(Top) add 1.
# Add all of the bit flags together 8+4+2+1 (=15) crops all four edges, 8+4 crops only Right & Left, and 2+1 crops only Bottom & Top.
#
# DEBUG=False=No Debug. Set True for debugging info, need DebugView: http://technet.microsoft.com/en-gb/sysinternals/bb545027
#
# Ignore=0.2, percentage of darkest pixels to ignore during Full image AutoThresh scan.
#
# Matrix, For conversion of RGB to YUV-Y, 0 = Rec601, 1 = Rec709, 2 = PC601, 3 = PC709
# Default for RGB is 2(PC601) if width <= 720 else 1(PC709) : YUV not used
# The defaults are for PC601 & PC709 range 0-255.
# So as to not require different Thresh for RGB, if clip c is RGB and matrix is PC range, then Thresh will be scaled
# to RGB full range ie Thresh = Thresh * (255.0/(235.0-16.0))
#
# If cropping too much border, then increase Samples or reduce Thresh
# If not cropping enough border then border is being seen as image, increase Thresh.
__________________
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; 4th September 2012 at 14:53. |
|
|
|
| Tags |
| averageluma, correlation, lumadifference, runtime |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|