User:Raffriff42/Utils-r41 Quick Reference

From Avisynth wiki
< User:Raffriff42(Difference between revisions)
Jump to: navigation, search
m (Debugging filters: add bigsub)
m (update, formatting)
 
(10 intermediate revisions by one user not shown)
Line 1: Line 1:
 
<div style="max-width:62em" >
 
<div style="max-width:62em" >
 +
{{BoldColor|#4F81BD|120|{{Template:AvsPluscon}} utilities}}
  
'''This list serves only as a quick reference;''' see the [[media:Utils-r41.avsi|Utils-r41.avsi]] source for full documentation.
+
:Download: '''[[media:Utils-r41.avsi|Utils-r41.avsi]]'''
 +
<br>
 +
 
 +
{{BoldColor|#4F81BD|120|Some of the most useful functions (a short selection)}}
  
 
__TOC__
 
__TOC__
 +
==== Deep Color Argument Scaling Functions ====
 +
===== sc8x =====
 +
:* [[Autoscale_parameter|Autoscale]] filter arguments to [[Deep_Color|high bit depth]]; scale an 8-bit value for target clip {{FuncArg|T}}.
 +
:: For example, if clip {{FuncArg|C}}'s bit depth = 10, <span style="font-size:104%"><code>C.sc8x('''255''')</code></span>&nbsp;==&nbsp;<span style="font-size:96%">''255''&nbsp;×&nbsp;2<sup>(''10''-8)</sup>&nbsp;==&nbsp;1023</span>.
 +
:: See also, '''sc8s''' &ndash; same as sc8x but with String result, suitable for use in [[MaskTools2|MaskTools]] expressions
 +
<div {{BoxWidthIndent|56|2}} >
 +
## @ T - clip with target bit depth
 +
## @ returns int for int formats, float for 32-bit float
 +
##
 +
function sc8x(clip T, float f)
 +
</div>
  
=== String functions ===
+
==== Utility Filters ====
----
+
===== ToRGB =====
{{FuncDefH4|SplitLines}}
+
:* Convert from anything to planar RGB[A]
{{FuncDef|SplitLines(string s, [int ''lastcol'', int ''cc''])}}
+
:: Attempts YUV'''&rarr;'''RGB conversion with best possible quality;
: Split long lines for Subtitle line wrap
+
:: hides the details of conversion from [[Interleaved]] to [[Planar]].
 +
<div {{BoxWidthIndent|56|2}} >
 +
## @ matrix  - ignored if not converting from YUV; default "Rec601"
 +
## @ bits_out - output bit depth, one of (8|10|12|14|16); default same as source
 +
## @ A - if supplied, becomes the alpha channel of the resulting clip;
 +
##      overrides any existing alpha channel.
 +
##      * if 'A' is RGBA or YUVA, the A channel is used;
 +
##      * if 'A' YUV or Y-only,   the Y channel is used;
 +
##      * if 'A' == "none", any existing alpha channel is removed;
 +
##      * if 'A' == "add", a new opaque alpha channel is added;
 +
##      * else, 'A' is ignored.
 +
##
 +
function ToRGB(clip C, string "matrix", int "bits_out", clip "A")
 +
</div>
  
{{FuncDefH4|TrimLeft}}
+
===== To444 =====
{{FuncDef|TrimLeft(string s)}}
+
:* Convert from anything to YUV[A]444
: SplitLines helper &ndash; trim spaces from left side of string
+
:: Attempts RGB'''&rarr;'''YUV conversion with best possible quality;
 +
:: hides the details of conversion from [[Interleaved]] to [[Planar]].
 +
<div {{BoxWidthIndent|56|2}} >
 +
## @ matrix  - ignored if not converting from RGB; default "Rec601"
 +
## @ bits_out - output bit depth, one of (8|10|12|14|16); default same as source
 +
## @ A - if supplied, becomes the alpha channel of the resulting clip;
 +
##      overrides any existing alpha channel.
 +
##      * if 'A' is RGBA or YUVA, the A channel is used;
 +
##      * if 'A' YUV or Y-only,  the Y channel is used;
 +
##      * if 'A' == "none", any existing alpha channel is removed;
 +
##      * if 'A' == "add", a new opaque alpha channel is added;
 +
##      * else, 'A' is ignored.
 +
##
 +
## Return YUV(A)444, max 16-bit (no float output)
 +
##
 +
function To444(clip C, string "matrix", int "bits_out", clip "A")
 +
</div>
  
{{FuncDefH4|GetNameFromPath}}
+
===== To16bit =====
{{FuncDef|GetNameFromPath(string path)}}
+
:* Convert from anything to best equivalent 16-bit version; no RGB'''&harr;'''YUV conversions
: Given a valid file path, get the filename only
+
<div {{BoxWidthIndent|56|2}} >
 +
## @ A - if supplied, becomes the alpha channel of the resulting clip;
 +
##      overrides any existing alpha channel.
 +
##      * if 'A' is RGBA or YUVA, the A channel is used;
 +
##      * if 'A' YUV or Y-only,  the Y channel is used;
 +
##      * else, 'A' is ignored.
 +
##
 +
## Returns:
 +
##  any RGB(A) -> RGB(A)P16
 +
##  any 444    -> YUV(A)444P16
 +
##  any 422    -> YUV(A)422P16
 +
##  any 420    -> YUV(A)420P16
 +
##  any Yxx    -> YxxP16 // no alpha 
 +
##
 +
function To16bit(clip C, clip "A")
 +
</div>
  
{{FuncDefH4|GetParentFolder}}
+
===== To8bit =====
{{FuncDef|GetParentFolder(string path)}}
+
:* Convert from anything to 'best' (v2.6.x compatible) equivalent 8-bit version
: Given a valid file path, get the parent folder path
+
:: Automatically converts [[Avisynthplus_color_formats|Planar RGB]] to RGB24/RGB32; removes any [[Avisynthplus_color_formats|alpha channel on YUV]].
 +
<div {{BoxWidthIndent|56|2}} >
 +
## @ dither  - if true, add dither when applicable; default false
 +
##
 +
## Returns:
 +
##  any RGBA -> RGB32
 +
##  any RGB  -> RGB24
 +
##  any 444  -> YV24
 +
##  any 422  -> YUY2
 +
##  any 420  -> YV12
 +
##  any Yxx  -> Y8
 +
##  YV411 (no change)
 +
## (no YUVA output, so save your alpha channel elsewhere)
 +
##
 +
function To8bit(clip C, bool "dither")
 +
</div>
  
=== Numeric functions ===
+
===== ToVdubFM =====
----
+
:* Make minimal color format conversion needed to view in [https://sourceforge.net/projects/vdfiltermod/ VirtualDub FilterMod].
{{FuncDefH4|_mod}}
+
<div {{BoxWidthIndent|56|2}} >
{{FuncDef|_mod(int m, float f)}}
+
## @ dither - if true, reduce bit depth to 8 bit with dithering if applicable;
: Return argument {{FuncArg|f}} as integer and ensure it is modulo {{FuncArg|m}}
+
##            default false
 +
##
 +
## vdubFM does not currently (AFAIK) support all AVS+ color spaces;
 +
## ToVdubFM does minimally-destructive translation
 +
## per docs, vdubFM accepts:
 +
##      10-bit 422 (v210 interleaved)
 +
##      16-bit 422, 444, 420 (planar)
 +
##      16-bit RGBA
 +
## this filter returns:
 +
##      8-bit formats unchanged, except YV411->YV420
 +
##      10-bit 422 (planar, not interleaved)
 +
##      16-bit 422 (planar)
 +
##      16-bit RGBA
 +
##
 +
function ToVdubFM(clip C, bool "dither")
 +
</div>
  
{{FuncDefH4|StrinF}}
+
===== MatchColorFormat =====
{{FuncDef|StrinF(float f, [int ''decimals''])}}
+
:* Match color format of source {{FuncArg|C}} to template {{FuncArg|T}}
: Format a Float as a String with (by default) 2 decimals
+
:: Useful when temporarily changing color format and to splice disparate clips together.
 +
<div {{BoxWidthIndent|56|2}} >
 +
## @ matrix    - ignored if not converting between RGB<>YUV; default "Rec601"
 +
## @ keepbits  - if true, retain original bit depth;
 +
##              else (default) force bit depth to match 'T'
 +
## @ dither    - if true, add dither when converting to lower bit depth; default false
 +
##
 +
function MatchColorFormat(clip C, clip T, string "matrix",
 +
\                        bool "keepbits", bool "dither")
 +
</div>
  
{{FuncDefH4|Hex2}}
+
===== MatchAudioFormat =====
{{FuncDef|Hex2(int i)}}
+
:* Match audio properties of source {{FuncArg|C}} to template {{FuncArg|T}}
: [[Internal_functions/Hex|Hex]] with leading "0" if less than 2 chars long
+
:: For ease of splicing, interleaving etc.
 +
<div {{BoxWidthIndent|56|2}} >
 +
##  Properties matched:
 +
##  number of channels (see note), bit depth, sample rate
 +
##
 +
## AudioChannels handling:
 +
##  if 'T' has no audio, returns 'C'.KillAudio;
 +
##  if 'C' has no audio, copies silenced audio from 'T';
 +
##  if 'T' and 'C' have the same channel count, no change is made;
 +
##  if 'T' has 1 channel, returns 'C'.ConvertToMono;
 +
##  if 'T' has 2 channels and 'C' has 1, returns 'C' with split mono;
 +
##  otherwise, an error is raised (manual intervention is needed)
 +
##
 +
## @ allowresample - if true, resample audio to match template if needed;
 +
##                  if false (the default), use [[AssumeSampleRate]],
 +
##                  which may affect audio/video sync.
 +
##
 +
function MatchAudioFormat(clip C, clip T, bool "allowresample")
 +
</div>
  
{{FuncDefH4|IsReallyFloat}}
+
===== remove_gamma =====
{{FuncDef|IsReallyFloat(val v)}}
+
:* Remove [[wikipedia:sRGB|sRGB]] gamma transfer function (if bit depth > 8)
: Bugfixed [[Internal_functions/IsFloat|IsFloat]]
+
:: Improves appearance of certain filters like [[Resize]]; must call [[#restore_gamma|restore_gamma]] before final output; requires [[MaskTools2|MaskTools]] v2.2.x
 +
<div {{BoxWidthIndent|56|2}} >
 +
## @ enable - default true; if false, do nothing (bypass)
 +
function remove_gamma(clip C, bool enable)
 +
</div>
  
{{FuncDefH4|MakeYUVColor}}
+
===== restore_gamma =====
{{FuncDef|MakeYUVColor(float y, float u, float v, [float ''a''])}}
+
:* Apply standard gamma transfer function (if bit depth > 8)
: Given Y, U, V [, A], return an Avisynth color_yuv
+
:: Reverses effect of [[#remove_gamma|remove_gamma]].
 +
<div {{BoxWidthIndent|56|2}} >
 +
## @ enable - default true; if false, do nothing (bypass)
 +
function restore_gamma(clip C, bool enable)
 +
</div>
  
{{FuncDefH4|MakeRGBColor}}
+
==== Color And Overlay Filters ====
{{FuncDef|MakeRGBColor(float r, [float ''g'', float ''b'', float ''a''])}}
+
===== LevelsPlus =====
: Given R, G, B [, A], return an Avisynth color
+
:* Scale [[D_Notation|0-255]]{{D}} [[Levels]] arguments to current bit depth.
 +
:: {{FuncArg|coring}}=''false'' by default.
 +
<div {{BoxWidthIndent|56|2}} >
 +
## @ input_x, output_x - now Float to allow fractional values
 +
## @ coring - unlike 'legacy' Levels, 'coring' now defaults to false
 +
## @ chroma - if true (default) process chroma like Levels; else bypass YUV chroma
 +
##
 +
function LevelsPlus(clip C,  
 +
\            float input_low, float gamma, float input_high,
 +
\            float output_low, float output_high,
 +
\            bool "coring", bool "dither", bool "chroma")
 +
</div>
  
{{FuncDefH4|transparent_color}}
+
==== Crop, Resize And Transform Filters ====
{{FuncDef|transparent_color(float a, int color)}}
+
===== ScaleSize =====
: Given Avisynth color, set its transparency
+
:* Switch (or fade) between three [[Resize]] clips depending on scale factor.
 +
:: Resizers may be user-specified; default resizers are [[#remove_gamma|gamma-aware]].
 +
::* default 'small' (< 65%) resizer: gamma-aware <tt>[[Resize#BicubicResize|BicubicResize]] (b=-0.5, c=0.25)</tt>
 +
::* default 'medium'&nbsp;&nbsp; resizer:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; gamma-aware <tt>[[Resize#Spline_based_resizers|Spline64Resize]]</tt>
 +
::* default 'large' (> 133%) resizer: gamma-aware <tt>[[Resize#GaussResize|GaussResize]] (p=50)</tt>
 +
<div {{BoxWidthIndent|56|2}} >
 +
## @ fwid  - new width
 +
## @ fhgt  - new height
 +
##            (if 'fwid' <= 0, it is calculated from 'fhgt' and aspect ratio)
 +
##            (if 'fhgt' <= 0, it is calculated from 'fwid' and aspect ratio)
 +
##            (if both <= 0, an error is raised)
 +
## @ mod  - new size modulo; if <= 0,
 +
##            'mod'=1 if source is RGB or YUV 4:4:4 or Y-only; else 'mod'=2
 +
##
 +
## (see script for more, advanced options)
 +
##
 +
function ScaleSize(clip C, float fwid, float fhgt, int mod,
 +
\            string "sm", string "med", string "lg", 
 +
\            float "thrSm", float "thrLg", bool "fade", bool "ident", bool "gamma")
 +
</div>
  
{{FuncDefH4|f2c}}
+
===== CropEx =====
{{FuncDef|f2c(float f)}}
+
:* Symmetrically [[Crop|crop]] or [[AddBorders|expand]] a clip to ensure it is a certain size, with size forced to [[Modulo|mod]]-4, mod-8 etc.
: Scale "normal" float arguments to [[ColorYUV]]'s ''gain_x'', ''gamma_x'' & ''cont_x''  
+
:: Quick & easy way to [[Splice|splice]] or [[StackHorizontal|stack]] disparate clips together.
 +
<div {{BoxWidthIndent|56|2}} >
 +
## @ wid, hgt - New desired width & height (will be rounded to nearest 'mod')
 +
## @ mod      - [[Mod]] value; one of (1|2|4|8|16|32); default 2
 +
## @ border  - Border color; default 0 (black border)
 +
## @ mode    - Expand method: (extend|mirror|blur|border)
 +
##              default/fallback="border"
 +
## @ align    - @see [[Subtitle]] ("number pad notation"); position clip within frame.
 +
##              Default 5 (centered)
 +
## @ dx, dy  - Shift output in x/y direction. Positive = right/down. Default 0.
 +
##              Note output shift rounded to nearest mod-2 unless 'mod'=1.
 +
  ##
 +
function CropEx(clip C, float wid, float hgt, int "mod", 
 +
\            int "border", string "mode",
 +
\            int "align", int "dx", int "dy", bool "debug")
 +
</div>
  
{{FuncDefH4|_gcd}}
+
==== Debugging Filters ====
{{FuncDef|_gcd(int x, int y)}}
+
===== EvalShow =====
: MatchAudioFormat helper &ndash; Greatest Common Divisor
+
:* [[Internal_functions/Eval#Eval|Evaluate]] a script snippet; display the script and its result on screen.
 +
<div {{BoxWidthIndent|56|2}} >
 +
## @ s - a snippet of AviSynth code; any string allowed as an argument to [[Internal_functions/Eval#Eval|Eval]].
 +
## @ size, align - cf. [[Subtitle]]. 'size' is quite small by default;
 +
##                you may prefer size=24. Disable subtitle w/ size = 0.
 +
## @ opacity    - 1.0 = opaque text, 0.0 = transparent. Default 0.7
 +
##
 +
function EvalShow(clip C, string s, float "size", int "align", float "opacity")
 +
</div>
  
{{FuncDefH4|CalcWidth}}
+
===== Grayramp =====
{{FuncDef|CalcWidth(clip C, int new_hgt, [int ''mod'', int ''lim''])}}
+
:* Return grayscale ramp clip w/ same specs as template clip {{FuncArg|T}}
: Given new height, calulate new width, preserving aspect ratio
+
:: Useful for measuring luma response curve when used in combination with [[#HistogramTurn|HistogramTurn]].
 +
:: See script for ''ColorRampEx'' &ndash; ramp between any two colors.
 +
<div {{BoxWidthIndent|56|2}} >
 +
## @ T      - Any color format (8, 10, 12, 14 or 16-bit);
 +
##            determines all properties except Height.
 +
## @ height - default 80
 +
## @ zigs  - if true, 8 pixels on left and right reverse ramp direction;
 +
##            useful for determining whether clipping has occurred.
 +
## @ stack  - if true, stack on top of clip 'T';
 +
##            resulting audio is taken from 'T'
 +
## @ noise  - if > 0, add fixed, random noise; range 0_4, default 0
 +
##
 +
function Grayramp(clip T, int "height", bool "zigs", bool "stack", int "noise")
 +
</div>
  
{{FuncDefH4|CalcHeight}}
+
===== ScopeR =====
{{FuncDef|CalcHeight(clip C, int new_wid, [int ''mod'', int ''lim''])}}
+
:* Show waveform + vectorscope; accepts RGB or YUV
: Given new width, calulate new height, preserving aspect ratio
+
:: Rotate waveform 90&deg; CCW and make brighter; rotate vector 180&deg;.
 +
<div {{BoxWidthIndent|56|2}} >
 +
## @ shrink - if true, shrink clip+scopes & add side borders so output size = input;
 +
##            if false (default), height increases by 264 px
 +
## @ vector - if true, show Histogram("color2") (inverted so red is top-left)
 +
## @ matrix - if source is RGB and 'vector'=true, use this matrix; default "Rec709"
 +
##            otherwise 'matrix' is ignored (does not affect waveform or main image)
 +
## @ parade - if true, show RGB waveforms side-by-side;
 +
##            else (default), show RGB waveforms superimposed
 +
## @ bottom - if true, put scopes below video (default false)
 +
##
 +
function ScopeR(clip C, bool "shrink", bool "vector", string "matrix",
 +
\              bool "parade", bool "bottom")
 +
</div>
  
=== Deep color argument scaling functions ===
+
===== ScopeY =====
----
+
:* Simple waveform + vector scope. Accepts 8-bit, YUV only.
{{FuncDefH4|getTVBlack}}
+
:: Rotate waveform 90&deg; CCW and make brighter; rotate vector 180&deg;.
{{FuncDef|getTVBlack(int bits)}}
+
<div {{BoxWidthIndent|56|2}} >
: Return TV-black level for given bit depth
+
## @ shrink - if true, shrink clip+scopes & add side borders so
 
+
##              output size = input (within range 360_1440);
{{FuncDefH4|getFullscale}}
+
##            if false (default), height increases by 264 px
{{FuncDef|getFullscale(int bits)}}
+
## @ vector - if true (default), show Histogram("color2")
: Return integer fullscale value for given bit depth (mostly internal use)
+
##              (inverted so red is top-left)
   
+
## @ levels - if true, show Histogram("levels", 1.0); default false.
{{FuncDefH4|scff}}
+
## @ bottom - if true, put scopes below video (default false)
{{FuncDef|scff(int fs_in, int fs_out, float f, [bool ''cx''])}}
+
  ##
: Scale a value from one fullscale range to another
+
## * Smaller heights are faster to process; scopes look relatively bigger;
 +
##  (at height=512, scopes occupy the bottom half of the output;
 +
##    at 720, about 1/3; at 1080, 1/4)
 +
##
 +
function ScopeY(clip C, bool "shrink", bool "vector", bool "levels", bool "bottom")
 +
</div>
  
{{FuncDefH4|scbf}}
+
===== HistogramTurn =====
{{FuncDef|scbf(int bits_in, int bits_out, float f, bool ''cx''])}}
+
:* Classic [[Histogram]], waveform on top (or on bottom); supports RGB
: Scale a value from one bit depth to another
+
:: Rotate waveform 90&deg; CCW and make brighter.
 +
<div {{BoxWidthIndent|56|2}} >
 +
## @ parade - if true (default), show RGB waveforms side-by-side;
 +
##            else, show RGB waveforms superimposed
 +
## @ shrink - if true, shrink clip+waveform & add side borders so output size = input
 +
##            if false (default), height increases by 264 px
 +
## @ bottom - if true, put histogram below video (default false)
 +
##
 +
function HistogramTurn(clip C, bool "parade", bool "shrink", bool "bottom")
 +
</div>
  
{{FuncDefH4|scbx}}
 
{{FuncDef|scbx(int bits_in, int bits_out, float f)}}
 
: Scale a value from one bit depth to another; clamp output
 
  
{{FuncDefH4|scbs}}
+
{{BoldColor|#4F81BD|120|File history}}
{{FuncDef|scbs(int bits_in, int bits_out, float f, [int ''decimals''])}}
+
:see [[File:Utils-r41.avsi]].
: Scale a value from one bit depth to another; string result
+
 
+
{{FuncDefH4|scnf}}
+
{{FuncDef|scnf(clip S, clip T, float f, [bool ''cx''])}}
+
: Scale a value from source clip {{FuncArg|S}} for target clip {{FuncArg|T}}
+
 
+
{{FuncDefH4|sc8f}}
+
{{FuncDef|sc8f(clip T, float f, [bool ''cx''])}}
+
: Scale an 8-bit value for target clip {{FuncArg|T}}
+
 
+
{{FuncDefH4|sc8x}}
+
{{FuncDef|sc8x(clip T, float f)}}
+
: Scale an 8-bit value for target clip {{FuncArg|T}}; clamp output
+
 
+
{{FuncDefH4|sc8s}}
+
{{FuncDef|sc8s(clip T, float f, [int ''decimals''])}}
+
: Scale an 8-bit value for target clip {{FuncArg|T}}; string result
+
 
+
=== Utility filters ===
+
----
+
{{FuncDefH4|Cropd}}
+
{{FuncDef|Cropd(clip C, int x, int y, int wid, int hgt, [bool ''align'', int ''mod''])}}
+
: Show a diagnostic string on [[Crop]] failure; optionally enforce [[Mod]]
+
 
+
{{FuncDefH4|MatchColorFormat}}
+
{{FuncDef|MatchColorFormat(clip C, clip T, [string ''matrix'', bool ''matchbits'', bool ''dither''])}}
+
: Match color format of source {{FuncArg|C}} to template {{FuncArg|T}}
+
 
+
{{FuncDefH4|MatchAudioFormat}}
+
{{FuncDef|MatchAudioFormat(clip C, clip T, [bool ''allowresample''])}}
+
: Match audio properties of source {{FuncArg|C}} to template {{FuncArg|T}}
+
 
+
{{FuncDefH4|GBR2YUV}}
+
{{FuncDef|GBR2YUV(clip C, [bool ''yuva''])}}
+
: Transport RGB in YV24 &ndash;  G=>Y, B=>U, R=>V
+
 
+
{{FuncDefH4|YUV2GBR}}
+
{{FuncDef|YUV2GBR(clip C, [clip ''A'', bool ''rgb32''])}}
+
: Transport YV24 in RGB &ndash;  Y=>G, U=>B, V=>R
+
 
+
{{FuncDefH4|stack_to_wid}}
+
{{FuncDef|stack_to_wid(clip C, int wid, [clip ''R'', bool ''flip''])}}
+
: Stack clip {{FuncArg|C}} horizontally until it is at least {{FuncArg|wid}} wide
+
 
+
{{FuncDefH4|stack_to_hgt}}
+
{{FuncDef|stack_to_hgt(clip C, int hgt, [clip ''R'', bool ''flip''])}}
+
: Stack clip {{FuncArg|C}} vertically until it is at least {{FuncArg|hgt}} high
+
 
+
{{FuncDefH4|stack_to_size}}
+
{{FuncDef|stack_to_size(clip C, int wid, int hgt, [bool ''flip''])}}
+
: Stack clip {{FuncArg|C}} until it is {{FuncArg|wid}} x {{FuncArg|hgt}}
+
 
+
=== Color and overlay filters ===
+
----
+
{{FuncDefH4|LevelsPlus}}
+
{{FuncDef|LevelsPlus(clip ''C'',<br>
+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int input_low, float gamma, int input_high,<br>
+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int output_low, int output_high,<br>
+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bool ''coring'', bool ''dither'' )
+
}}
+
: Scale 0-255 [[Levels]] arguments to current bit depth
+
 
+
{{FuncDefH4|OverlayAligned}}
+
{{FuncDef|OverlayAligned(clip base, clip over, <br>
+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [int ''x'', int ''y'', clip ''mask'', float ''opacity'', string ''mode'', <br>
+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bool ''greymask'', string ''output'', bool ''ignore_conditional'', <br>
+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bool ''pc_range'', int ''align'', int ''borderwidth'', int ''bordercolor''])}}
+
: [[Overlay]] with support for {{FuncArg|align}} parameter and adding borders/letterboxing to inset clip
+
 
+
=== Timeline filters ===
+
----
+
{{FuncDefH4|Slip}}
+
{{FuncDef|Slip(clip C, int offset)}}
+
: "Slip" a clip in time.
+
 
+
{{FuncDefH4|ChangeSpeed}}
+
{{FuncDef|ChangeSpeed(<br>
+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; clip C, float factor, [bool ''pitchfix'', bool ''noblend''])}}<br>
+
{{FuncDefH4|ChangeAudioSpeed}}
+
{{FuncDef|ChangeAudioSpeed(<br>
+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; clip C, float factor, [bool ''pitchfix''])}}
+
: Change speed over a wide range with frame blending in fast forward by default.
+
 
+
=== Crop, resize and transform filters ===
+
----
+
{{FuncDefH4|ScaleSize}}
+
{{FuncDef|ScaleSize(clip C, float factor, int mod, <br>
+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [string ''sm'', string ''med'', string ''lg'', <br>
+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int ''thrSm'', int ''thrLg'', bool ''fade'', bool ''ident''])}}<br>
+
{{FuncDef|ScaleSize(clip C, float fwid, float fhgt, int mod, <br>
+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [string ''sm'', string ''med'', string ''lg'', <br>
+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int ''thrSm'', int ''thrLg'', bool ''fade'', bool ''ident''])}}
+
: Switch (or fade) between three [[Resize]] clips depending on scale factor
+
 
+
{{FuncDefH4|CropPanTilt}}
+
{{FuncDef|CropPanTilt(clip C, int wid, int hgt, [float ''pan'', float ''tilt''])}}
+
: Crop to size with smooth animated pan & tilt, expressed as percentage (center @ {{FuncArg|pan}}=0, {{FuncArg|tilt}}=0)
+
 
+
{{FuncDefH4|CropShift}}
+
{{FuncDef|CropShift(clip C, int wid, int hgt, [float ''off_x'', float ''off_y''])}}
+
: Crop to size with smooth animated pan & tilt, expressed as pixels (center @ {{FuncArg|off_x}}=0, {{FuncArg|off_y}}=0)
+
 
+
{{FuncDefH4|CropEx}}
+
{{FuncDef|CropEx(clip C, float wid, float hgt, [int ''mod'', <br>
+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int ''border'', string ''mode'', bool ''debug''])}}
+
: Symmetrically crop or expand a clip to ensure it is a certain size, with size forced to mod-4, mod-8 etc
+
 
+
{{FuncDefH4|Shift}}
+
{{FuncDef|Shift(clip C, float offh, float offv)}}
+
: Shift a clip up-down and left-right (sub-pixel precision);
+
 
+
{{FuncDefH4|ShiftUV}}
+
{{FuncDef|ShiftUV(clip C, [float ''ux'', float ''uy'', float ''vx'', float ''vy''])}}
+
: Shift Chroma relative to Luma
+
 
+
{{FuncDefH4|ShiftRedBlue}}
+
{{FuncDef|ShiftRedBlue(clip C, <br>
+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [float ''rx'', float ''ry'', <br>
+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; float ''bx'', float ''by'',<br>
+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; float ''rxd'', float ''ryd'', <br>
+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; float ''bxd'', float ''byd''])}}
+
: Shift and/or resize Red and Blue relative to Green
+
:{{Par2|rxd, ryd, bxd, byd|float|0.0}}
+
:: "delta" width & height
+
 
+
=== Debugging filters ===
+
----
+
{{FuncDefH4|bigsub}}
+
{{FuncDef|bigsub(clip C, string s, [, float ''sizeMult'', bool ''enable''])}}
+
: For clip identification &ndash; show a semitransparent text string, very large by default
+
 
+
{{FuncDefH4|EvalShow}}
+
{{FuncDef|EvalShow(clip C, string s)}}
+
: Execute a script snippet; show script & result on screen
+
 
+
{{FuncDefH4|vdubFM}}
+
{{FuncDef|vdubFM(clip C)}}
+
: Make changes needed to display on [http://sourceforge.net/p/vdfiltermod/ VirtualDub FilterMod]
+
 
+
{{FuncDefH4|ShowMask}}
+
{{FuncDef|ShowMask(clip C, clip M, [string ''mode'', float ''opacity''])}}
+
: Show a mask clip overlaid on another clip for visualization
+
:{{Par2|mode|string|""}}
+
:: One of <code>(""|"luma"|"cyan")</code>
+
 
+
{{FuncDefH4|ColorbarsHD2}}
+
{{FuncDef|ColorbarsHD2([int ''width'', int ''height'', bool ''rgb_out'', int ''bits_out'', bool ''dither''])}}
+
: Return [[ColorBarsHD]] with small changes (1280x720, TV-range, 29.97 fps, 1 hour long, audio tone @ -18dB, 48kz)
+
 
+
{{FuncDefH4|Grayramp}}
+
{{FuncDef|Grayramp(clip T, [int ''height'', bool ''dither''])}} <br>
+
{{FuncDef|Grayramp([int ''width'', int ''height'', bool ''rgb_out'', int ''bits_out'', bool ''dither''])}}
+
: Return grayscale ramp
+
 
+
{{FuncDefH4|VideoScopes}}
+
{{FuncDef|VideoScopes(clip C, [bool ''squeeze''])}}
+
: Show waveform + vectorscope
+
 
+
{{FuncDefH4|Analyze}}
+
{{FuncDef|Analyze(clip C)}}
+
: Print color channel statistics on the screen; auto RGB / YUV (cf. [[ColorYUV]](analyze=true)
+
 
+
{{FuncDefH4|HistogramOverlay}}
+
{{FuncDef|HistogramOverlay(clip B, clip F, [bool "autocrop", int "align",<br>
+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int "x", int "y", int "wid", int "hgt", int "margin",<br>
+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; float "opacity", string "mode", bool "pc_range")])}}
+
: Overlay a user-supplied histogram clip
+
 
+
{{FuncDefH4|HistogramTurn}}
+
{{FuncDef|HistogramTurn(clip C)}}
+
: Classic [[Histogram]], waveform on top
+
 
+
{{FuncDefH4|Histogram8}}
+
{{FuncDef|Histogram8(clip C, [string ''mode'', float ''factor''])}}
+
: 8-bit Histogram for deep color
+
 
+
{{FuncDefH4|ShowChannels}}
+
{{FuncDef|ShowChannels(clip C, [bool ''analyze''])}}
+
: Show original & 3 channels in quad split
+
 
+
{{FuncDefH4|ShowFrameNumberAligned}}
+
{{FuncDef|ShowFrameNumberAligned(<br>
+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; clip C, [bool ''scroll'', int ''offset'', <br>
+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; float ''x'', float ''y'', string ''font'', int ''size'', <br>
+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int ''text_color'', int ''halo_color'', <br>
+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; float ''font_width'', float ''font_angle'', <br>
+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; float ''opacity'', int ''align''])}}
+
: [[ShowFrameNumber]] with support for {{FuncArg|opacity}} and {{FuncArg|align}}
+
 
+
{{FuncDefH4|StackTwoAcrossCropped}}
+
{{FuncDef|StackTwoAcrossCropped(clip A, clip B, [clip ''S'', <br>
+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int ''border'', float ''pan'', int ''wid'',<br>
+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string ''titleA'', string ''titleB'', int ''align''])}}
+
: Make side-by-side split clip (normally, for comparison or preview purposes)
+
 
+
</div>
+
  
=== Changes ===
 
----
 
<div style="max-width:62em" >
 
{|border=1 cellspacing=1 cellpadding=4
 
|-
 
| v0.41 May-2017
 
| Published
 
|}
 
 
</div>
 
</div>
  
Line 306: Line 316:
 
[[Category:Borders_and_Cropping]]
 
[[Category:Borders_and_Cropping]]
 
[[Category:Deep_color_tools]]
 
[[Category:Deep_color_tools]]
 +
[[Category:Avisynthplus]]

Latest revision as of 09:27, 26 November 2017

AVS+ utilities

Download: Utils-r41.avsi


Some of the most useful functions (a short selection)

Contents

[edit] Deep Color Argument Scaling Functions

[edit] sc8x
For example, if clip C's bit depth = 10, C.sc8x(255) == 255 × 2(10-8) == 1023.
See also, sc8s – same as sc8x but with String result, suitable for use in MaskTools expressions
## @ T - clip with target bit depth
## @ returns int for int formats, float for 32-bit float
##
function sc8x(clip T, float f)

[edit] Utility Filters

[edit] ToRGB
  • Convert from anything to planar RGB[A]
Attempts YUVRGB conversion with best possible quality;
hides the details of conversion from Interleaved to Planar.
## @ matrix   - ignored if not converting from YUV; default "Rec601"
## @ bits_out - output bit depth, one of (8|10|12|14|16); default same as source
## @ A - if supplied, becomes the alpha channel of the resulting clip;
##       overrides any existing alpha channel.
##       * if 'A' is RGBA or YUVA, the A channel is used;
##       * if 'A' YUV or Y-only,   the Y channel is used;
##       * if 'A' == "none", any existing alpha channel is removed;
##       * if 'A' == "add", a new opaque alpha channel is added;
##       * else, 'A' is ignored.
##
function ToRGB(clip C, string "matrix", int "bits_out", clip "A")
[edit] To444
  • Convert from anything to YUV[A]444
Attempts RGBYUV conversion with best possible quality;
hides the details of conversion from Interleaved to Planar.
## @ matrix   - ignored if not converting from RGB; default "Rec601"
## @ bits_out - output bit depth, one of (8|10|12|14|16); default same as source
## @ A - if supplied, becomes the alpha channel of the resulting clip;
##       overrides any existing alpha channel.
##       * if 'A' is RGBA or YUVA, the A channel is used;
##       * if 'A' YUV or Y-only,   the Y channel is used;
##       * if 'A' == "none", any existing alpha channel is removed;
##       * if 'A' == "add", a new opaque alpha channel is added;
##       * else, 'A' is ignored.
##
## Return YUV(A)444, max 16-bit (no float output)
##
function To444(clip C, string "matrix", int "bits_out", clip "A")
[edit] To16bit
  • Convert from anything to best equivalent 16-bit version; no RGBYUV conversions
## @ A - if supplied, becomes the alpha channel of the resulting clip;
##       overrides any existing alpha channel.
##       * if 'A' is RGBA or YUVA, the A channel is used;
##       * if 'A' YUV or Y-only,   the Y channel is used;
##       * else, 'A' is ignored.
##
## Returns:
##   any RGB(A) -> RGB(A)P16
##   any 444    -> YUV(A)444P16
##   any 422    -> YUV(A)422P16
##   any 420    -> YUV(A)420P16
##   any Yxx    -> YxxP16 // no alpha  
##
function To16bit(clip C, clip "A")
[edit] To8bit
  • Convert from anything to 'best' (v2.6.x compatible) equivalent 8-bit version
Automatically converts Planar RGB to RGB24/RGB32; removes any alpha channel on YUV.
## @ dither  - if true, add dither when applicable; default false
##
## Returns:
##   any RGBA -> RGB32
##   any RGB  -> RGB24
##   any 444  -> YV24
##   any 422  -> YUY2
##   any 420  -> YV12
##   any Yxx  -> Y8
##   YV411 (no change)
## (no YUVA output, so save your alpha channel elsewhere)
##
function To8bit(clip C, bool "dither")
[edit] ToVdubFM
## @ dither - if true, reduce bit depth to 8 bit with dithering if applicable;
##            default false
##
## vdubFM does not currently (AFAIK) support all AVS+ color spaces; 
## ToVdubFM does minimally-destructive translation
## per docs, vdubFM accepts:
##      10-bit 422 (v210 interleaved)
##      16-bit 422, 444, 420 (planar)
##      16-bit RGBA
## this filter returns:
##       8-bit formats unchanged, except YV411->YV420
##      10-bit 422 (planar, not interleaved)
##      16-bit 422 (planar)
##      16-bit RGBA
##
function ToVdubFM(clip C, bool "dither")
[edit] MatchColorFormat
  • Match color format of source C to template T
Useful when temporarily changing color format and to splice disparate clips together.
## @ matrix    - ignored if not converting between RGB<>YUV; default "Rec601"
## @ keepbits  - if true, retain original bit depth; 
##               else (default) force bit depth to match 'T'
## @ dither    - if true, add dither when converting to lower bit depth; default false
##
function MatchColorFormat(clip C, clip T, string "matrix", 
\                         bool "keepbits", bool "dither")
[edit] MatchAudioFormat
  • Match audio properties of source C to template T
For ease of splicing, interleaving etc.
##  Properties matched:
##  number of channels (see note), bit depth, sample rate
##
## AudioChannels handling:
##   if 'T' has no audio, returns 'C'.KillAudio;
##   if 'C' has no audio, copies silenced audio from 'T';
##   if 'T' and 'C' have the same channel count, no change is made;
##   if 'T' has 1 channel, returns 'C'.ConvertToMono;
##   if 'T' has 2 channels and 'C' has 1, returns 'C' with split mono;
##   otherwise, an error is raised (manual intervention is needed)
##
## @ allowresample - if true, resample audio to match template if needed;
##                   if false (the default), use AssumeSampleRate,
##                   which may affect audio/video sync.
##
function MatchAudioFormat(clip C, clip T, bool "allowresample")
[edit] remove_gamma
  • Remove sRGB gamma transfer function (if bit depth > 8)
Improves appearance of certain filters like Resize; must call restore_gamma before final output; requires MaskTools v2.2.x
## @ enable - default true; if false, do nothing (bypass)
function remove_gamma(clip C, bool enable)
[edit] restore_gamma
  • Apply standard gamma transfer function (if bit depth > 8)
Reverses effect of remove_gamma.
## @ enable - default true; if false, do nothing (bypass)
function restore_gamma(clip C, bool enable)

[edit] Color And Overlay Filters

[edit] LevelsPlus
coring=false by default.
## @ input_x, output_x - now Float to allow fractional values
## @ coring - unlike 'legacy' Levels, 'coring' now defaults to false
## @ chroma - if true (default) process chroma like Levels; else bypass YUV chroma
##
function LevelsPlus(clip C, 
\             float input_low, float gamma, float input_high,
\             float output_low, float output_high, 
\             bool "coring", bool "dither", bool "chroma")

[edit] Crop, Resize And Transform Filters

[edit] ScaleSize
  • Switch (or fade) between three Resize clips depending on scale factor.
Resizers may be user-specified; default resizers are gamma-aware.
  • default 'small' (< 65%) resizer: gamma-aware BicubicResize (b=-0.5, c=0.25)
  • default 'medium'   resizer:       gamma-aware Spline64Resize
  • default 'large' (> 133%) resizer: gamma-aware GaussResize (p=50)
## @ fwid  - new width
## @ fhgt  - new height
##             (if 'fwid' <= 0, it is calculated from 'fhgt' and aspect ratio)
##             (if 'fhgt' <= 0, it is calculated from 'fwid' and aspect ratio)
##             (if both <= 0, an error is raised)
## @ mod   - new size modulo; if <= 0, 
##             'mod'=1 if source is RGB or YUV 4:4:4 or Y-only; else 'mod'=2
##
## (see script for more, advanced options)
##
function ScaleSize(clip C, float fwid, float fhgt, int mod, 
\             string "sm", string "med", string "lg",  
\             float "thrSm", float "thrLg", bool "fade", bool "ident", bool "gamma")
[edit] CropEx
  • Symmetrically crop or expand a clip to ensure it is a certain size, with size forced to mod-4, mod-8 etc.
Quick & easy way to splice or stack disparate clips together.
## @ wid, hgt - New desired width & height (will be rounded to nearest 'mod')
## @ mod      - Mod value; one of (1|2|4|8|16|32); default 2
## @ border   - Border color; default 0 (black border)
## @ mode     - Expand method: (extend|mirror|blur|border) 
##               default/fallback="border"
## @ align    - @see Subtitle ("number pad notation"); position clip within frame.
##              Default 5 (centered)
## @ dx, dy   - Shift output in x/y direction. Positive = right/down. Default 0. 
##              Note output shift rounded to nearest mod-2 unless 'mod'=1.
##
function CropEx(clip C, float wid, float hgt, int "mod",   
\             int "border", string "mode", 
\             int "align", int "dx", int "dy", bool "debug")

[edit] Debugging Filters

[edit] EvalShow
  • Evaluate a script snippet; display the script and its result on screen.
## @ s - a snippet of AviSynth code; any string allowed as an argument to Eval. 
## @ size, align - cf. Subtitle. 'size' is quite small by default; 
##                 you may prefer size=24. Disable subtitle w/ size = 0.
## @ opacity     - 1.0 = opaque text, 0.0 = transparent. Default 0.7
##
function EvalShow(clip C, string s, float "size", int "align", float "opacity")
[edit] Grayramp
  • Return grayscale ramp clip w/ same specs as template clip T
Useful for measuring luma response curve when used in combination with HistogramTurn.
See script for ColorRampEx – ramp between any two colors.
## @ T      - Any color format (8, 10, 12, 14 or 16-bit);
##            determines all properties except Height. 
## @ height - default 80
## @ zigs   - if true, 8 pixels on left and right reverse ramp direction;
##            useful for determining whether clipping has occurred.
## @ stack  - if true, stack on top of clip 'T';
##            resulting audio is taken from 'T'
## @ noise  - if > 0, add fixed, random noise; range 0_4, default 0
##
function Grayramp(clip T, int "height", bool "zigs", bool "stack", int "noise")
[edit] ScopeR
  • Show waveform + vectorscope; accepts RGB or YUV
Rotate waveform 90° CCW and make brighter; rotate vector 180°.
## @ shrink - if true, shrink clip+scopes & add side borders so output size = input;
##            if false (default), height increases by 264 px 
## @ vector - if true, show Histogram("color2") (inverted so red is top-left)
## @ matrix - if source is RGB and 'vector'=true, use this matrix; default "Rec709"
##            otherwise 'matrix' is ignored (does not affect waveform or main image)
## @ parade - if true, show RGB waveforms side-by-side;
##            else (default), show RGB waveforms superimposed
## @ bottom - if true, put scopes below video (default false)
##
function ScopeR(clip C, bool "shrink", bool "vector", string "matrix", 
\               bool "parade", bool "bottom")
[edit] ScopeY
  • Simple waveform + vector scope. Accepts 8-bit, YUV only.
Rotate waveform 90° CCW and make brighter; rotate vector 180°.
## @ shrink - if true, shrink clip+scopes & add side borders so 
##              output size = input (within range 360_1440);
##            if false (default), height increases by 264 px 
## @ vector - if true (default), show Histogram("color2") 
##              (inverted so red is top-left) 
## @ levels - if true, show Histogram("levels", 1.0); default false.
## @ bottom - if true, put scopes below video (default false)
##
## * Smaller heights are faster to process; scopes look relatively bigger; 
##   (at height=512, scopes occupy the bottom half of the output; 
##    at 720, about 1/3; at 1080, 1/4)
##
function ScopeY(clip C, bool "shrink", bool "vector", bool "levels", bool "bottom")
[edit] HistogramTurn
  • Classic Histogram, waveform on top (or on bottom); supports RGB
Rotate waveform 90° CCW and make brighter.
## @ parade - if true (default), show RGB waveforms side-by-side;
##            else, show RGB waveforms superimposed 
## @ shrink - if true, shrink clip+waveform & add side borders so output size = input
##            if false (default), height increases by 264 px 
## @ bottom - if true, put histogram below video (default false)
##
function HistogramTurn(clip C, bool "parade", bool "shrink", bool "bottom")


File history

see File:Utils-r41.avsi.
Personal tools