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

 

Go Back   Doom9's Forum > Capturing and Editing Video > Avisynth Usage

Reply
 
Thread Tools Display Modes
Old 9th December 2012, 12:38   #81  |  Link
jmac698
Registered User
 
Join Date: Jan 2006
Posts: 1,869
Ok,
I've tried another example and now I'm having a lot of trouble. I can't get it to work at all, and when changing around some parameters, sometimes it makes a letterbox on the video, I don't know why.
You've done so much, but it would be great if you could help me figure out this one:
http://www.sendspace.com/file/f4qh1v
jmac698 is offline   Reply With Quote
Old 9th December 2012, 16:47   #82  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 11,417
Quote:
Wonder why it jumps a little though
Who knows, maybe starlight making minor differences.
The moon is a little dark at the top and hence the close cropping there, and the bottom has
a bit of a halo around it hence the not quite so close cropping.
It's not a de-jitterer, it just crops when the scaled thresh is broken for 3 consecutive scanlines (h/v).

Shall download the 2nd sample and have a play.

PS, the "Insert Link" button works fine in Quick Reply.
__________________
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 ???
StainlessS is offline   Reply With Quote
Old 9th December 2012, 16:58   #83  |  Link
martin53
Registered User
 
Join Date: Mar 2007
Posts: 408
Quote:
Originally Posted by StainlessS View Post
@Martin53,
Hows about this. Func to return combined rgb data (as for single clip Luma funcs, excluding comparison funcs), for all channels,
eg ave, max, min, YInRange, YPlaneMedian, YPlaneMinMaxDifference, all as Global Variables, with a user supplied Prefix.
If you don't mind, please have a look at the 'proof of concept' code.
The intention and use case I had in mind is this:
You need a number that is frame specific. Today, you have the options

- Store it in a text file in a prior pass and read it in, e.g. with ConditionalReader() or with RT_Stats.
____Not so nice since you need multiple passes and have to create (unique) file names.
- Evaluate it directly from where it comes from.
____Slow and memory consuming if the evaluation is complicated.
- Use a veeerrry long string as comma separated list and Eval("Select(..." it.
____Not applicable to my experience with really long clips. Slow, I suspect.

The 'new' idea is, to store a floating point variable in a clip, because the clip has the neccessary property to be an 'array', the frame number being the index into the array, and AviSynth's frame cache will provide fast access to several elements of the array, as long as they are accessed frequently before being kicked out of the cache.

I started with 32 bits resolution and fixed point (range 0...256) for the variable. Of course, a real floating point variable would rather have bits for the signs of mantissa end exponent and fields of some width to store mantissa and exponent themselves.

What I really would like to point out, is, that one argb pixel can really be regarded as one variable. With two pixels of rgb24 etc, finer resolutions are easy to think of. I dont know what the AviSynth resolution of type float is. But the typical 6 digit display does not need more than 20 bits for the mantissa, so another 10 bits would be free for the exponent, thus allowing -1,048,576e-1024...1,048,575e1023 with an accurracy of 6 digits to be stored in the 1x1argb clip. A pair of functions that just stored the bits from a float variable into the - say - 8 bytes of a 1x2 argb clip and retrieved it to a float variable again would make a fine interface to use the kind of 'array of float' that I decribed above.
martin53 is offline   Reply With Quote
Old 9th December 2012, 20:24   #84  |  Link
jmac698
Registered User
 
Join Date: Jan 2006
Posts: 1,869
Yeah, the same idea is used in avsLib where this is all done for you. Or you could move to Vapoursynth.
jmac698 is offline   Reply With Quote
Old 10th December 2012, 02:06   #85  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 11,417
Martin53,

Code:
Function Luma2argb(clip cMeasured) {
	cContainer = blankclip(cMeasured, pixel_type="RGB24", width=1, height=1)
	return cContainer.GScriptClip("""
		FV=cMeasured.RT_AverageLuma(Matrix=2)
		longVal = round($10000*FV)					#longVal is supposed to be 3 bytes : $rr,gg,bb.
		RT_Debug("FV="+String(FV),"LONGVAL="+String(LongVal))
		return Blankclip(Last, color=longVal)	#Put high byte to red,then green,blue
	""", args="cMeasured")
}

Function Argb2float(clip c, int delta, int currentframe) {
	r = c.RGB_ChanAve(n=currentframe, delta=delta, chan=0)
	g = c.RGB_ChanAve(n=currentframe, delta=delta, chan=1)
	b = c.RGB_ChanAve(n=currentframe, delta=delta, chan=2)
	RT_Debug("R="+String(R),"G="+String(G),"B="+String(B))
	return r + g/$100 + b/$10000
}

c = ColorBars().Trim(0,-2)	# With Matrix=0(rec601)==97.900780 : Matrix=2(pc601)=95.287369
cAL = c.Luma2argb()	#cAL holds the AverageLuma of C with 24bit res.
c.GScriptClip("""
	subtitle(string(cAL.Argb2float(1, current_frame)))	#displays AverageLuma of following frame :) :) :)
""", args="cAL")
return last
Above uses only RGB24, 24 bits, same as mantissa in Avisynth float.
Note, Max value return by AverageLuma & RT_AverageLuma is 255.0 not 255.99999

I knocked up a temp func, RGB_ChanAve() as for RT_AverageLuma but without the matrix arg but additional chan arg (0-3==RGBA [0==R]).
EDIT: Link Removed.

In original script, dont think I noticed any value in the blue channel at all (other than 0).

Here a Jmac thread on float/int conversion:
http://forum.doom9.org/showthread.ph...light=mantissa

EDIT: You might want to edit the func names (remove the "A"), may or may not want to pack into RGB32.
__________________
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; 12th December 2012 at 00:39.
StainlessS is offline   Reply With Quote
Old 10th December 2012, 18:51   #86  |  Link
martin53
Registered User
 
Join Date: Mar 2007
Posts: 408
StainlessS,
I appreciate RGB_ChanAve()! Thank you!

If I asked you if you can make a function that just 'typecasts' float-->RGBA and another one that 'typecasts' RGBA-->float, i.e the first takes a float and returns a valid 'color' in range 0 ...$ff.ff.ff.ff without further calculation, just the 4 bytes, the 2nd one is like RGB_ChanAve, say 'RGB_2float()' and directly returns type float from the 4 channels of the pixel, would you like to help me with that?

Edit: assume to only allow RGB_2float(w=1, h=1)

Last edited by martin53; 10th December 2012 at 21:51.
martin53 is offline   Reply With Quote
Old 10th December 2012, 19:11   #87  |  Link
martin53
Registered User
 
Join Date: Mar 2007
Posts: 408
Quote:
Originally Posted by jmac698 View Post
Yeah, the same idea is used in avsLib
... with that, you mean the very long string, right? Then, as only one matter, the string concatenation issue of AviSynth 2.6 affects AVSLib too, and makes the whole lib practically useless.

Quote:
Originally Posted by jmac698 View Post
Or you could move to Vapoursynth.
Vapoursynth interests me very much, but I didn't take time to read more thoroughly through the doc. Can you please say a word about runtime environment in Vapoursynth ('ScriptClip()' etc). Is that supported?

Last edited by martin53; 10th December 2012 at 19:14.
martin53 is offline   Reply With Quote
Old 10th December 2012, 20:09   #88  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 11,417
Quote:
('ScriptClip()' etc). Is that supported?
So far as I know, Avisynth script is not supported and so neither would ScriptClip be. (leastwise not yet)
But perhaps a Vapoursynth similar func is available.

(gonna sleep a few days and come back and read other posts).
__________________
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 ???
StainlessS is offline   Reply With Quote
Old 11th December 2012, 18:33   #89  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 11,417
@Martin53,
Done what you require but adding it and other stuff to RT_Stats (eg RT_BitAND, RT_BitSet, RT_Hex).
I've implemented as RT_RgbChanAve, RT_RGB32AsFloat, and RT_FloatAsRGBA, if you dont like names,
then suggest others.
RT_RGB32AsFloat() given args similar to eg RT_AverageLuma excluding w,h interlaced and matrix, so you could
store a two dimensional array of float using StackHorizontal/Vertical (presume thats what you wanted).

@Jmac,

Gonna have another crack at your moon prob soon as I get this RT_Stats stuff out of the way, need to
attack from a different direction.

EDIT:
Quote:
Originally Posted by StainlessS View Post
so you could store a two dimensional array of float using StackHorizontal/Vertical.
Three dimensional if you count frame number.
__________________
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; 11th December 2012 at 21:02. Reason: mistake correct
StainlessS is offline   Reply With Quote
Old 11th December 2012, 22:00   #90  |  Link
martin53
Registered User
 
Join Date: Mar 2007
Posts: 408
Quote:
Originally Posted by StainlessS View Post
RT_RgbChanAve, RT_RGB32AsFloat, and RT_FloatAsRGBA
magnificent!
I am going to test it tomorrow or Thursday.
martin53 is offline   Reply With Quote
Old 12th December 2012, 00:42   #91  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 11,417
Temporary version RT_Stats 1.07beta.

New funcs noted here:
Code:
RT_Stats Avisynth Plugin by StainlessS

RT_RgbChanAve(clip,int "n"=current_frame,int "delta"=0,int "x"=0,int "y"=0,int "w"=0, int "h"=0,bool "interlaced"=false,int "chan"=0)
Return the average value for an RGB channel (RGB 24/32). (default = 0 = R [RGBA])


RT_FloatAsRGBA(float)
Given a float arg, returns an int formatted as for use as a color to eg BlankClip.
Can later be recovered from that clip using RT_RGB32AsFloat().


RT_RGB32AsFloat(clip,int "n"=current_frame,int "delta"=0,int "x"=0,int "y"=0)
Given an RGB32 clip that had a pixel value created via RT_FloatAsRGBA(), gets that pixel and returns as the
original float given to RT_FloatAsRGBA. By creating single pixel clips and stacking them horizontally/vertically,
you can use frames as a two dimensional array of float, perhaps use the frame number for a third dimension.


RT_GraphLink(clip source, clip c1, ... , clip cn, bool b1, ... , bool bn)
Standard filter function.
This function is a standard filter graph function, not a runtime/compile time function.
It takes a compulsory source clip which it will return unchanged.
The clips, c1 to cn (one or more, at least one of them) are by default forcibly linked into
the filter graph. The bools b1 to bn are optional (zero or more) and would default to True
if not supplied. These bools will if false, switch OFF the forcible linking into the filter graph
for the corresponding clip c1 to cn.
Avisynth does not normally process any filter chains that do not contribute to the output clip,
this filter allows you to select graph chains that you wish to forcibly process.
The usual way to force process an unused chain is to do a stackHorizontal/Vertical and a crop.
All args un-named.
Example: [will only render the TestA" and TestC images]
  a=ImageSource("d:\avs\1.jpg",end=0)  # Single frame
  TmpA = a.subtitle("TestA").ImageWriter("d:\avs\TestA_", type="png")   # Written
  TmpB = a.subtitle("TestB").ImageWriter("d:\avs\TestB_", type="png")   # Skipped
  TmpC = a.subtitle("TestC").ImageWriter("d:\avs\TestC_", type="png")   # Written
  RT_GraphLink(a,TmpA,TmpB,TmpC,True,false)                             # 3rd bool defaults true
  return Last


RT_Hex(int , int "width"=0)
First arg is an integer to convert to a hexadecimal string.
'width' is the minimum width of the returned string.
eg RT_Hex(255,4) returns "00FF".


RT_HexValue(String)
Returns an int conversion of the supplied hexadecimal string.
Fixes a HexValue bug in 2.58 & 2.6a3.


RT_BitNOT(int) 
Returns the integer result of a bitwise NOT operation on it's int argument.


RT_BitAND(int, int) 
Returns the integer result of a bitwise AND operation on the two int arguments.


RT_BitOR(int, int) 
Returns the integer result of a bitwise OR operation on the two int arguments.


RT_BitXOR(int, int) 
Returns the integer result of a bitwise XOR operation on the two int arguments.


RT_BitLSL(int, int) 
Returns the integer result of a Logical Shift Left on the first integer, by a shift count of the second int.
An Arithmetic Shift Left and a Logical Shift Left, are essentially the same.


RT_BitLSR(int, int) 
Returns the integer result of a Logical Shift Right on the first integer, by a shift count of the second int.
Logical shift right will shift zeros into the high bits.


RT_BitASL(int, int) 
Returns the integer result of an Arithmetic Shift Left on the first integer, by a shift count of the second int.
An Arithmetic Shift Left and a Logical Shift Left, are essentially the same.


RT_BitASR(int, int) 
Returns the integer result of an Arithmetic Shift Right on the first integer, by a shift count of the second int.
Arithemtic shift right will shift into the high bits, zeros for a +ve number and ones for a -ve number, so -ve
numbers will stay -ve and +ve stay +ve.


RT_BitTST(int, int) 
Returns the bool result of a bit test on first integer, the bit number is given in the second int.
A zero in the bit returns False and a 1 returns True.


RT_BitCLR(int, int) 
Returns the integer result of a bit clear (make 0) on first integer, the bit number is given in the second int.


RT_BitSET(int, int) 
Returns the integer result of a bit Set (make 1) on first integer, the bit number is given in the second int.


RT_BitCHG(int, int) 
Returns the integer result of a bit change (0->1, 1->0) on first integer, the bit number is given in the second int.


RT_BitROR(int, int) 
Returns the integer result of a bit Rotate Right on first integer, the bit rotate count is given in the second int.


RT_BitROL(int, int) 
Returns the integer result of a bit Rotate Left on first integer, the bit rotate count is given in the second int.
http://www.mediafire.com/?lejdpznk631hdnd


Martin53, Testem all out if you can, Not had much testing here, done all of the funcs bar RT_RgbChanAve()
today, and I'm a bit whacked out.

EDIT: You interested in storing ints in a clip too ?

EDIT:

Quote:
so you could store a two dimensional array of float using StackHorizontal/Vertical.
Three dimensional if you count frame number.
With a little thought you could have 4 dimensions using n and delta.

EDIT: Have now implemented RT_RGB32AsInt(), no need for a sister func.
__________________
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; 12th December 2012 at 16:01.
StainlessS is offline   Reply With Quote
Old 16th December 2012, 22:14   #92  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 11,417
Jmac, see below PlanetCrop() works great, even with your 2nd moon image set.

Code:
#import("D:\AVS\BANK\QueryLumaMinMax.avsi")

Fn="D:\MOON\*.JPG|BMP"
BAFFLE      = 12        # Number of consecutive scanlines that need to pass, below considered noise.    
BLK         = 32        # Where black sky can vary in brightness
GROW_W      = 256       # Enlarge canvas width  by GROW_W pixels (keep surround area, Use with KEEP_MARGIN)
GROW_H      = 256       # Enlarge canvas height by GROW_H pixels
FAR         = 1.0       # Frame Aspect Ratio
STRENGTH    = 1.0       # AutoLevel Strength 0.0 -> 1.0
SHOWAL      = True      # Right Hand Side Only AutoLeveled
KEEP        = true      # True tries to keep some of the cropped area instead of AddBorders
SHOWKEEP    = true      # Show Kept margin
SHOWBORDER  = true      # True Show replaced border in Red, else Black. (FAR affects) (Test CROP)
DEBUG       = True


Return PlanetCrop(Fn,BAFFLE,BLK,GROW_W,GROW_H,FAR,STRENGTH,SHOWAL,KEEP,SHOWKEEP,SHOWBORDER,DEBUG)

#--------------------------------------------------------------------------------
Function PlanetCrop(String "FileName",int "Baffle",Int "BlackRange",int "Grow_W",int "Grow_H",Float "FAR", \
        Float "AutoLevelStrength",bool "ShowAutoLevel",bool "KeepMargin",bool "ShowMargin",bool "ShowBorder",bool "Debug") {
# PlanetCrop v1.0 -  16 Dec 2012
#
# Requires GScript, RT_Stats and QueryLumaMinMax.avs
#
# Given a series of time lapse planetoid images, locates those images in frame, crops out and joins them all together into
# a video clip of required Frame Aspect Ratio, 1 FPS, with optional Auto Luma Levelling.
#     First scans each image establishing maximum dimensions for whole sequence (after cropping out the planets). Optionally 'grows' those
# dimensions to maintain some of the area around the cropped planets. A 'canvas' size is then established to contain the now maximum
# dimensions and respecting the desired Frame Aspect Ratio, synthetic black borders are added where necessary.
# Borders are the areas added to maintain aspect ratio and can be hi-lited in red. Margins are areas that use the
# original image content instead of synthetic black borders (where possible), they replace synthetic borders, and can be hi-lited
# in green. Margins are the areas between the established crop coords and synthetic borders.
# --------------------------------------
# Args:-
#  Filename: Default "*.BMP|JPG|JPE|JPEG|PNG|TGA|TIF|GIF|TIFF". Image Path and wildcard with mulitple pipe separated extensions.
#  Baffle: Default 12. Number of scanlines that must break a threshold to be accepted as 'planet'. Avoids noise.
#  BlackRange: Default 32. Where background (sky) can vary in luminance by a significant amount.
#  Grow_W,Grow_H: Default 128. Size in pixels by which to 'grow' the accumulated maximum dimensions once all planets have been identified.
#  FAR: Default 4.0/3.0. Frame Aspect Ratio.
#  AutoLevelStrength: Default 0.0. Auto luma leveling, range 0.0 -> 1.0. 0.0 is OFF.
#  ShowAutoLevel: Default False. If true then shows Auto leveling on right hande side of image ONLY.
#  KeepMargin: Default True. When padding to maintain Frame Aspect Ratio, tries to keep image instead of adding borders.
#  ShowMargin: Default False. If True, shows kept margins in Green.
#  ShowBorder: Default False. When padding to maintain Frame Aspect Ratio, borders are shown in red.
#  Debug: Default False. Show debug info via DebugView. Need DebugView: http://technet.microsoft.com/en-gb/sysinternals/bb545027
#
    VERS="PlanetCrop v1.0 - 16 Dec 2012"        
    FileName= Default(FileName,"*.BMP|JPG|JPE|JPEG|PNG|TGA|TIF|GIF|TIFF")
    Baffle=Default(Baffle,12)
    BlackRange=Default(BlackRange,32)
    Grow_W=Default(Grow_W,128)
    Grow_H=Default(Grow_H,128)
    FAR=Float(Default(FAR,4.0/3.0))
    AutoLevelStrength=Float(Default(AutoLevelStrength,0.0))
    ShowAutoLevel=Default(ShowAutoLevel,false)
    KeepMargin=Default(KeepMargin,True)
    ShowMargin=Default(ShowMargin,False)
    ShowBorder=Default(ShowBorder,False)
    DEBUG=Default(DEBUG,False)
    # Lesser changed stuff Hardcoded
    BORDER      = (ShowBorder) ? $FF0000 :  $000000     # Color for replaced borders.
    MARGINBORDER= $00FF00                               # Color for KEEP_MARGIN borders.
    DEBUG_QLMM  = False                                 # Debug QueryLumaMinMax
    FPS         = 1.0                                   # Whatever.
    WMOD        = 1
    HMOD        = 1
    OUT_FILE    = "PLANET.List"
    Assert(Baffle>0,"Baffle must be 1 or more")
    Assert(BlackRange>=0,"BlackRange must be 1 or more")
    Assert(Grow_W>=0,"Grow_W Cannot be -ve")
    Assert(Grow_H>=0,"Grow_H Cannot be -ve")
    Assert(FAR>0.0,"FAR must be greater than 0.0")
    Assert(AutoLevelStrength>=0.0 && AutoLevelStrength <= 1.0,"AutoLevelStrength must be 0.0 -> 1.0")
    #
    GScript("""
        Function QPC(clip c,int Baffle) {
            c
            Thresh=0.04                 # 4%, Baffle should remove need to change
            w=Width h=height
            got = 0 x1 = 0 x2 = w-1 Cnt=0
            For(x=0,w-1) {
                th=RT_YInRange(0,x=x,y=4,w=1,h=-4,lo=2,hi=255,Matrix=2) # PC levels and skip end 4 pixels (crud around frame edge)
                if(got==0) {
                    if(th > Thresh) {
                        Cnt=Cnt+1
                        if(Cnt >= Baffle) {
                            x1=x-Baffle+1
                            Cnt=0
                            got=1
                        }
                    } else {
                        Cnt = 0
                    }
                } else {
                    if(x2 == w-1 && th <= Thresh) {
                        Cnt=Cnt+1
                        if(Cnt >= 2) {          # Weak BAFFLE on transition to black
                            x2=x-2
                            x=w
                        }
                    }
                }
            }    
            got=0 y1 = 0 y2 = h-1 Cnt=0
            For(y=0,h-1) {
                th=RT_YInRange(0,x=4,y=y,w=-4,h=1,lo=2,hi=255,Matrix=2)
                if(got==0) {
                    if(th > Thresh) {
                        Cnt=Cnt+1
                        if(Cnt >= Baffle) {
                            y1=y-Baffle+1
                            Cnt=0
                            got=1
                        }
                    } else {
                        Cnt = 0
                    }
                } else {
                    if(y2 == h-1 && th <= Thresh) {
                        Cnt=Cnt+1
                        if(Cnt >= 2) {          # Weak BAFFLE on transition to black
                            y2=y-2
                            y=h
                        }
                    }
                }
            }    
            Return "PC_X="+String(x1)+" PC_Y="+String(y1)+" PC_W="+String(x2-x1+1)+" PC_H="+String(y2-y1+1)
        }
        #
        if(DEBUG){ RT_Debug(" ") RT_Debug(VERS,"- By StainlessS") RT_Debug(" ") }
        picclip = 0                                                                 # Dummy for now
        result=RT_WriteFileList(FileName,OUT_FILE)                                   # Create a listing file of Pic files
        Assert((result!=0), "No files found")
        FILELIST=RT_ReadTxtFromFile(OUT_FILE)                                       # Get list of files
        NFILES=RT_TxtQueryLines(FILELIST)                                            # Query Number of lines in String ie number of files.
        (DEBUG) ? RT_Debug("Found files = " + String(NFILES)) :NOP
        # Prescan to ascertain max wid/hit of all files, also Autocrop & Auto Levels
        MAXH=0 MAXW=0                                                               # init max wid and hit
        CROPCOORDS=""                                                               # Clear results array (string)
        AUTOLEVELS=""                                                               # Clear AutoLevels array (string)
        AUTOLEVEL=(AutoLevelStrength>0.0)                                           # Adjust using Levels.
        For(i=0,NFILES-1) {
            FN=RT_TxtGetLine(FILELIST,i)                                            # Filename of pic/vid file i
            (DEBUG)?RT_Debug(String(i+1)+"/"+String(NFILES)+") Getting File dimensions",FN):NOP
            k=ImageReader(FN,end=0).ConvertToRGB32()
            OrgW=k.width    OrgH=k.height
            # For QPC
            Grey=k.GreyScale()
            MinLum=Grey.RT_YPlaneMin(0,threshold=0.2,Matrix=2)
            Grey=Grey.Levels(MinLum+BlackRange,1.0,MinLum+BlackRange+1,0,255,Coring=false)
            #
            PCS=Grey.QPC(Baffle)
            Eval(PCS)
            k=k.Crop(PC_X,PC_Y,PC_W,PC_H)
            CROPCOORDS=RT_TxtAddStr(CROPCOORDS,PCS)
            if (AUTOLEVEL) {
                QLMM = k.QueryLumaMinMax(debug=(DEBUG&&DEBUG_QLMM))     # Query luma levels (on cropped clip)
                Eval(QLMM)                                              # Set Avisynth vars
                AUTOLEVELS=RT_TxtAddStr(AUTOLEVELS,QLMM)                # Avisynth Bugfix, same as AUTOLEVELS = AUTOLEVELS + QLMM + Chr(10)
            }
            If(MAXW<PC_W) {MAXW=PC_W}        
            If(MAXH<PC_H) {MAXH=PC_H}
            if (DEBUG) {                                                # KEEP main debug messages together
                RT_Debug ("Orig Width =",String(orgW),"Orig Height =",String(OrgH))
                if((PC_W != OrgW) || (PC_H != OrgH)) {                  # Was Caused by AUTOCROP
                    RT_Debug("Crop Width =",String(PC_W),"Crop Height =",String(PC_H))
                }
                RT_Debug("MAX Width So Far =",String(MAXW),"MAX Height So Far =",String(MAXH))
                (AUTOLEVEL)? RT_Debug("AutoLevel MinLuma=",String(QLMMMin)," MaxLuma =",String(QLMMMax)) : NOP          
                RT_Debug(" ----------------------------- ")            # line separator
            }
        }
        if(Grow_W>0 || Grow_H > 0) {
            (DEBUG)?RT_Debug("Enlarging Max Width,Height to enlarge canvas"):NOP
            MAXW=MAXW+Grow_W
            MAXH=MAXH+Grow_H
        }
        maxFAR = Float(MAXW) / MAXH
        if(FAR >= maxFAR) {
            # Required Frame Aspect Ratio greater or same as maximum accumulated dimensions. Need to pad horizontal
                canvasheight    = Int((MAXH  + (HMOD/2)) / HMOD) * HMOD
                canvaswidth     = Int((canvasheight * FAR + (WMOD/2)) / WMOD) * WMOD
        } else {    # Need to pad vertical
                canvaswidth     = Int((MAXW  + (WMOD/2)) / WMOD) * WMOD
                canvasheight    = Int((canvaswidth / FAR + (HMOD/2)) / HMOD) * HMOD
        }    
        if(DEBUG){
            RT_Debug("SETTING CanvasWidth =",String(canvaswidth)," CanvasHeight =",String(canvasheight))
            RT_Debug(" ----------------------------- ")       # line separator
        }
        For(i=0,NFILES-1) {
            FN=RT_TxtGetLine(FILELIST,i)         # Filename of pic/vid file i
            if(DEBUG){RT_Debug(string(i+1)+"/"+String(NFILES)+")","Processing File",FN)}
            k=ImageReader(FN,end=0).ConvertToRGB32()
            OrgW=k.width    OrgH=k.height
            Eval(RT_TxtGetLine(CROPCOORDS,i))
            Left    =   (canvaswidth-PC_W) / 2      # Borders
            Right   =   canvaswidth-PC_W - Left
            Top     =   (canvasheight-PC_H) / 2
            Bot     =   canvasheight-PC_H-Top
            Left2=0 Right2=0    Top2=0  Bot2=0      # Init keep margin borders
            if(KeepMargin) {
                Left2   =   ((PC_X<Left) ? PC_X : Left) / WMOD *WMOD
                if(Left2>0) {
                    Left=Left-Left2
                }                   
                Right2  =   (((OrgW-PC_X-PC_W)<Right) ? (OrgW-PC_X-PC_W) : Right) / WMOD * WMOD
                if(Right2>0) {
                    Right=Right-Right2
                }                   
                Top2    =   ((PC_Y<Top) ? PC_Y : Top) / HMOD *HMOD
                if(Top2>0) {
                    Top=Top-Top2
                }                   
                Bot2    =   (((OrgH-PC_Y-PC_H)<Bot) ? (OrgH-PC_Y-PC_H) : Bot) / HMOD * HMOD
                if(Bot2>0) {
                    Bot=Bot-Bot2
                }                   
                if(!ShowMargin) {
                    PC_X=PC_X-Left2
                    PC_W=PC_W+Left2+Right2
                    PC_Y=PC_Y-Top2
                    PC_H=PC_H+Top2+Bot2
                }
            }
            (DEBUG)? RT_Debug("Crop("+String(PC_X)+","+String(PC_Y)+","+String(PC_W)+","+String(PC_H)+")") : NOP        
            k=k.Crop(PC_X,PC_Y,PC_W,PC_H)       
            if (AUTOLEVEL) {
                QAT = RT_TxtGetLine(AUTOLEVELS,i)
                Eval(QAT)
                if(k.IsYUV()) {
                    CSMin = 16
                    CSMax = 235
                } else {        
                    CSMin = 0
                    CSMax = 255
                }
                TMP_K=k         
                ALMin = Int(CSMin - ((CSMin - QLMMMin) * AutoLevelStrength) + 0.5) # Round Up
                ALMax = Int(CSMax - ((CSMax - QLMMMax) * AutoLevelStrength))       # Round down
                (DEBUG) ? RT_Debug("Levels("+String(ALMin)+",1.0,"+String(AlMax)+","+String(CSMin)+","+String(CSMax)+",Coring=False)") : NOP
                k = k.Levels(ALMin,1.0,ALMax,CSMin,CSMax,Coring=False)              # DONT EVER USE Coring 
                if(ShowAutoLevel) {
                    tmpw=k.width/4*2
                    LeftClip = TMP_K.Crop(0,0,tmpw,-0)
                    RightClip= k.Crop(tmpw,0,-0,-0)
                    k=StackHorizontal(LeftClip,RightClip)               
                }
            }        
            if(KeepMargin && ShowMargin) {
                (DEBUG) ? RT_Debug("KeepMargin AddBorders("+String(Left2)+","+String(Top2)+","+String(Right2)+","+String(Bot2)+")") : NOP               
                k = k.Addborders(Left2,Top2,Right2,Bot2,MARGINBORDER)
            }
            (DEBUG) ? RT_Debug("AddBorders("+String(Left)+","+String(Top)+","+String(Right)+","+String(Bot)+")") : NOP
            k = k.Addborders(Left,Top,Right,Bot,BORDER).assumefps(fps)
            picclip = (IsClip(picclip)) ? picclip ++ k : k              # Append to  clip so far
            k=k.ConvertToRGB24() # Addborders done (bug in AddBorders rgb24) 
            if(DEBUG){RT_Debug(" ") RT_Debug(" ----------------------------- ")}        # line separator
        }
    """)
    return PicClip
}
Given args are just to demo the border/margin stuff.

Updated PlanetCrop() in RT_Stats zip.
__________________
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; 9th January 2013 at 16:33.
StainlessS is offline   Reply With Quote
Old 17th December 2012, 07:54   #93  |  Link
martin53
Registered User
 
Join Date: Mar 2007
Posts: 408
StainlessS,
- How could you know that I just needed RT_BitTST() and RT_BitSET() ! It was exactly what I intended to use to replace some string operations.

RT_FloatAsRGBA() and RT_RGB32AsFloat() seem to work flawless.
I'm sure the hexfunctions will come in handy at least for subtitles.
martin53 is offline   Reply With Quote
Old 17th December 2012, 09:39   #94  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 11,417
Thank you for the report. As you probably know, 2.6a3 has bit type operations, however few will use in
general scripts because they are not available in 2.58, the RT_ versions overcome that as available to all.
Also several of the bit ops are not implemented in 2.6 (rotates and bitchg, I think). I did not use identical names to
2.6, I'm more comfortable with the Motorola MC68000 assembler mnemonics for the bit ops.
In QueryBorderCrop, I ended up splitting a flags int into multiple separate bools to be able to test,
bit ops make some things so much easier.

Hope you noticed that I used the RT_YInRange func as suggested by you, in previous post script, would not
have been able to implement that script without it, thank you again.
__________________
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; 17th December 2012 at 10:08.
StainlessS is offline   Reply With Quote
Old 27th December 2012, 17:33   #95  |  Link
Forensic
Registered User
 
Join Date: Apr 2008
Location: California, USA
Posts: 127
StainlessS, this is brilliant. I haven't done much coding since my 6502 days and have yet to develop the skills to write my own DLLs. Implementing your tools just gave me a huge speed improvement over using the internal runtime functions. My next task is extracting Mediainfo using your RT_Call. Thank you.
Forensic is offline   Reply With Quote
Old 27th December 2012, 18:04   #96  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 11,417
You're very welcome kind sir.
The built in's are clearly faster than RT_stats raster funcs for full frame, but RT is intended for partial frame/scanline/pixel
reading, and are probably faster than repeatedly chopping out individual scanlines/pixels and testing them.

I did a tiny-weeny bit of 6502/6809/8080 in 81 but not much, later did Z80A for about 3/4 years, would hate to do that again.
M68K spoilt me for assy progging and I just hate little endian, did not really know any different when I did Z80.

Will up a new version RT within a few days, with a few additional funcs to those previously posted for v1.07beta.
(By the way, no real problems found in v1.07 beta although I changed some parts a little.)

Code:
RT_GetFrame(clip,int "n"=current_frame,int "delta"=0) # Name might change : Changing to RT_YankChain()
Compile/runtime clip function.
n (default = current_frame) frame number.
delta (default = 0), frame number offset.
Process frame (n + delta) of a clip ie forcibly process the filter graph chain for frame n + delta.
Replaces need for eg RT_AverageLuma(n=i,w=1,h=1) to sample a single pixel from frame n to do the same.


RT_NumberString(int ,int "base"=10, int "width"=0)
First arg is an integer to convert to a number base/radix string.
Base, (10, 2 -> 36), is the number base or radix, eg 2 == Binary, 8 == Octal, 10 == Denary/Decimal, 16 == Hexadecimal.
 The default of 10 (decimal) will just convert a number to its decimal string equivalent possibly with a '-' minus sign.
 All number bases with the exception of decimal, will be unsigned form, ie -1 to hexadecimal will produce "FFFFFFFF",
 (the sign is in the digits rather than as separate 'sign and magnitude' used in decimal representation).
 Here the digits used for the base, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ". Binary uses first two; decimal, the first 10;
 Hexadecimal the first 16; base 36 all 36 digits.
Width, (0, 0 -> 32) is the minimum width of the returned string.
 eg RT_NumberString(255,16,4) returns "00FF".


RT_NumberValue(String,int "base"=10)
Returns an int conversion of the supplied number base string.
Base, (10, 2 -> 36) is the number base that the string uses.
Conversion will cease at the first non legal number base digit, without producing an error.
 eg RT_NumberValue("1100",2) returns 12 from the binary string.

RT_RGB32AsInt(clip,int "n"=current_frame,int "delta"=0,int "x"=0,int "y"=0)
Compile/Runtime clip function.
Given an RGB32 clip that had a pixel value created from an Int, gets that pixel and returns as the
original Int. By creating single pixel clips and stacking them horizontally/vertically,
you can use a frame as a two dimensional array of Int, perhaps use the frame number for a third dimension.
Peace Bro

EDIT:
Quote:
The built in's are clearly faster than RT_stats raster funcs
As it turns out, actually they are not faster.
__________________
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 June 2014 at 00:11.
StainlessS is offline   Reply With Quote
Old 27th December 2012, 20:04   #97  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 11,417
@mastrboy,

Could I possibly ask you to delete your post #2 and repost again. I shall then repost my reply to you.
This is so that I can use my post #3 as an extension to the first post.
That might well break some links, but the limit in the Usage forum is 16K (20K I think in Developer),
but the current text description for RT is now at 23kb. Thank you.

(Unless a moderator has an alternative solution)

Happy New Year to one and all, and may your God smile upon you.
__________________
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; 27th December 2012 at 22:02.
StainlessS is offline   Reply With Quote
Old 30th December 2012, 09:55   #98  |  Link
Forensic
Registered User
 
Join Date: Apr 2008
Location: California, USA
Posts: 127
@StainlessS

DOS BAT file (works great)
set var=test.avi
MediaInfo_CLI\MediaInfo.exe "%CD%\%var%" > %var%.txt

RT_Call in AVS file to get the same output (fails)
a="test.avi"
Cmd="MediaInfo_CLI\MediaInfo.exe "+chr(34)+"%CD%\"+a+chr(34)+" > "+a+".txt"
RT_Call(Cmd,Hide=True)

I can't figure out what I am doing wrong. Any suggestions?
Forensic is offline   Reply With Quote
Old 30th December 2012, 11:50   #99  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 11,417
At a guess I'de say that it has no idea where MediaInfo_CLI\ is nor Test.avi,
Try using full path to both. DOS knows where it is, and so can use paths relative to itself,
RT_Call does not have a clue where DOS is/was.

I'll add a debug option to the func, to give a better clue as to what went wrong.

EDIT: I'll give it try myself, and check it out.
__________________
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; 30th December 2012 at 11:54.
StainlessS is offline   Reply With Quote
Old 2nd January 2013, 04:25   #100  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 11,417
@Forensic, (sorry about the delay in getting back to you)

The main problem in you usage of RT_Call is the mixing of MediaInfo commands and DOS commands.

You are calling MediaInfo and supplying it with %CD% and redirection ">", neither of which means anything to MediaInfo.

This is more like what you want

Code:
a="test.avi"

#SetWorkingDir("D:\Whatever")
Dir=_GetWorkingDir()

Cmd_1=QuoteStr(Dir+"MediaInfo_CLI\MediaInfo.exe") + " " + QuoteStr(Dir+a) + " --LogFile=" + QuoteStr(Dir+a+".1.txt")
Cmd_2=QuoteStr("MediaInfo_CLI\MediaInfo.exe") + " " + QuoteStr(a) + " --LogFile=" + QuoteStr(a+".2.txt")

RT_Call(Cmd_1,Hide=true)
RT_Call(Cmd_2,Hide=true)

return colorbars 

# _GetWorkingDir(), Get Current Working Directory as used by Avisynth for easy importing of scripts:- By StainlessS
Function _GetWorkingDir(){Try{Import("?\")}Catch(_){s=FindStr(_,Chr(34))_=MidStr(_,s+1,FindStr(_,"?")-s-1)}_}

Function QuoteStr(string s) {return Chr(34)+s+Chr(34)}
Might though be better to give an explicit directory for MediaInfo rather than scriptdir relative.

EDIT: Oops, removed the "debug=true" arg which is not as yet available in public releases.

ALSO NOTE, below previously given MediaInfo usage in RT_Stats doc

Code:
Example to write Aspect Ratio in form "1.333" to file D:\OUT\MEDINFO.TXT.
 RT_Call("D:\TEST\MediaInfo.Exe" + " --LogFile=" + "D:\OUT\MEDINFO.TXT" + " --Output=Video;%AspectRatio% " + "D:\VID\1.mpg")
I think I got the above from the MediaInfo included doc, but, --Output and %AspectRatio% seem to be deprecated (missing from
MediaInfo built in help) but still work ok.

Below the currently non deprecated usage, (using '--Inform' and '%DisplayAspectRatio%')
Code:
  RT_Call(QuoteStr("D:\TEST\MediaInfo.Exe") + " --LogFile=" + Quotestr("D:\OUT\MEDINFO.TXT") + \
      " --Inform=Video;%DisplayAspectRatio% " + Quotestr("D:\VID\1.mpg"))
__________________
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; 2nd January 2013 at 13:32.
StainlessS is offline   Reply With Quote
Reply

Tags
averageluma, correlation, lumadifference, runtime

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:11.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.