Avsresize

From Avisynth wiki
Revision as of 05:35, 23 October 2020 by Reel.Deal (Talk | contribs)

Jump to: navigation, search
Abstract
Author sekrit-twc
Version r4
Download avsresize_r4.7z
Category Resize
License Open source
Discussion Doom9 Forum


Contents

Description

z.lib resizers for AviSynth+

Requirements


Syntax and Parameters

z_ConvertFormat

Scaling, colorspace conversion, and depth conversion.

z_ConvertFormat (clip clip, int "width", int "height", str "pixel_type", string "colorspace_op", string "chromaloc_op", bool "interlaced", float "src_left", float "src_top", float "src_width", float "src_height", string "resample_filter", float "filter_param_a", float "filter_param_b", string "resample_filter_uv", float "filter_param_a_uv", float "filter_param_b_uv", string "dither_type", string "cpu_type", float "nominal_luminance", bool "approximate_gamma")


clip   =
Input clip.


int  width =
int  height =
Output width and height in pixels.


string  pixel_type =
Output pixel type ("YV12", "YUV420P16", etc.).
Bit Depth Grey YUV420 YUVA420 YUV422 YUVA422 YUV444 YUVA444 RGB RGBA
8 Y8 YV12
YUV420
YUV420P8
YUVA420
YUVA420P8
YV16
YUV422
YUV422P8
YUVA422
YUVA422P8
YV24
YUV444
YUV444P8
YUVA444
YUVA444P8
RGBP
RGBP8
RGBAP
RGBAP8
10 Y10 YUV420P10 YUVA420P10 YUV422P10 YUVA422P10 YUV444P10 YUVA444P10 RGBP10 RGBAP10
12 Y12 YUV420P12 YUVA420P12 YUV422P12 YUVA422P12 YUV444P12 YUVA444P12 RGBP12 RGBAP12
14 Y14 YUV420P14 YUVA420P14 YUV422P14 YUVA422P14 YUV444P14 YUVA444P14 RGBP14 RGBAP14
16 Y16 YUV420P16 YUVA420P16 YUV422P16 YUVA422P16 YUV444P16 YUVA444P16 RGBP16 RGBAP16
32 Y32 YUV420PS YUVA420PS YUV422PS YUVA422PS YUV444PS YUVA444PS RGBPS RGBAPS
All colorspaces are planar. "YUV9" and "YV411" ("YUV411", "YUV411P8") were committed from table above. See AviSynth+ color formats table.


string  colorspace_op =
Colorspace operation description.
Format is "matS[:transS[:primS[:rangeS]]]=>matD[:transD[:primD[:rangeD]]]"
Example JPEG to MPEG: "170m:709:709:f=>709:709:709:l"
There is keyword "auto" for source matrix, transfer, primaries, range. When it's used the corresponding input frame properties are used, if such frame properties don't exist either an error is raised or default matrix and color range are used.
There is keyword "same" for destination matrix, transfer, primaries, range. When it's used the corresponding source value is applied for destination too so there is no conversion.
See examples for more information.
MATRIX COEFFICIENTS TRANSFER CHARACTERISTICS COLOR PRIMARIES PIXEL RANGE
"rgb" "709" "709" "limited"
"709" "unspec" "unspec" "l"
"unspec" "470m" "470m" "full"
"fcc" "470bg" "470bg" "f"
"470bg" "601" "170m"
"170m" "240m" "240m"
"240" "linear" "film"
"ycgco" "log100" "2020"
"2020ncl" "log316" "st428"
"2020cl" "xvycc" "st431-2"
"chromancl" "srgb" "st432-1"
"chromacl" "2020_10" "jedec-p22"
"ictcp" "2020_12" Compatibility aliases
Compatibility aliases "st2084" "xyz" same as "st428"
"601" same as "470bg" "std-b67" "dci-p3" same as "st431-2"
"2020" same as "2020ncl" Compatibility aliases "display-p3" same as "st432-1"
"2020" same as "2020_10"
see tables on VapourSynth resize documentation


string  chromaloc_op =
Chroma location operation description.
Format is "[locS]=>[locD]"
There is keyword "auto" for source chromaloc_op. When it's used the corresponding input frame property is used, if such frame property doesn't exist default chromaloc is used.
There is keyword "same" for destination chromaloc_op. When it's used the corresponding source value is applied for destination too so there is no conversion.
See examples for more information.
Chroma location table, names in parenthesis are compatibility aliases:
  • "left" ("mpeg2") | "center" ("jpeg" and "mpeg1") | "top_left"
Example JPEG to MPEG2: "center=>left"


bool  interlaced = false
Whether to use interlaced mode (default: false)


float  src_left =
float  src_top =
float  src_width =
float  src_height =
Optional crop rectangle in the input frame.


string  resample_filter =
Resampling modes: "point" | "bilinear" | "bicubic" | "spline16" | "spline36" | "spline64" | "lanczos"


float  filter_param_a =
float  filter_param_b =
First and second parameter to resampler.
Example Bicubic (Mitchell-Netravali): resample_filter="bicubic", filter_param_a=0.333, filter_param_b=0.333
Example 4-tap Lanczos: resample_filter="lanczos", filter_param_a=4


string  resample_filter_uv =
Resampling mode for chroma.


float  filter_param_a_uv =
float  filter_param_b_uv =
First and second parameter to chroma resampler.


string  dither_type = "none"
Dithering type: "none" | "ordered" | "random" | "error_diffusion"


string  cpu_type =
CPU type, names in parenthesis are compatibility aliases:
  • "none" | "avx" | "avx_e" ("ivy") | "avx2" | "avx512f | "avx512_skx" ("skx") | "avx512_clx" | "avx512_pmc" ("cannon") | "avx512_snc" ("ice")


float  nominal_luminance = 100.0
Nominal peak luminance in cd/m^2 when converting HDR content to RGB Linear.


bool  approximate_gamma = true
Evaluating transfer functions at reduced precision.


Frame Properties

  • The name of the frame properties that are read and set are: _ChromaLocation, _ColorRange, _Matrix, _Transfer, _Primaries
  • The frame properties read and set the corresponding numerical index of the parameters. For example: matrix "709" has numerical index `1` and the frame property have value of `1`.
  • See examples for more information.


Resizers

z.lib compatibility wrappers with same syntax as built-in resizers.

z_PointResize (clip, int "target_width", int "target_height", float "src_left", float "src_top", float "src_width", float "src_height", string "chromaloc_op", string "dither")
z_BilinearResize (clip, int "target_width", int "target_height", float "src_left", float "src_top", float "src_width", float "src_height", string "chromaloc_op", string "dither")
z_BicubicResize (clip, float "b", float "c", int "target_width", int "target_height", float "src_left", float "src_top", float "src_width", float "src_height", string "chromaloc_op", string "dither")
z_LanczosResize (clip, int "target_width", int "target_height", float "src_left", float "src_top", float "src_width", float "src_height", int "taps", string "chromaloc_op", string "dither")
z_Lanczos4Resize (clip, int "target_width", int "target_height", float "src_left", float "src_top", float "src_width", float "src_height", int "taps", string "chromaloc_op", string "dither")
z_Spline16Resize (clip, int "target_width", int "target_height", float "src_left", float "src_top", float "src_width", float "src_height", string "chromaloc_op", string "dither")
z_Spline36Resize (clip, int "target_width", int "target_height", float "src_left", float "src_top", float "src_width", float "src_height", string "chromaloc_op", string "dither")
z_Spline64Resize (clip, int "target_width", int "target_height", float "src_left", float "src_top", float "src_width", float "src_height", string "chromaloc_op", string "dither")



clip   =
A clip to process. All planar formats are supported.


float  b = 0.0
float  c = 0.5
Parameters for z_BicubicResize only.
b and c can be used to tweak the filter’s behavior. For upscaling, it is recommended to use values that satisfy the equation b + 2c = 1.
Roughly speaking, raising B will cause blurring and raising C will cause ringing.
  • b=1.0, c=0.0 : B-Spline
  • b=0.0, c=0.0 : Hermite
  • b=1/3, c=1/3 : Mitchell-Netravali cubic filter
  • b=0.0, c=0.5 : Catmull-Rom spline (default)
  • b=0.0, c=0.75 : VirtualDub's "Precise Bicubic"
  • b=0.0, c=1.0 : Sharp Bicubic
Hermite is often considered one of the best choices for downscaling, as it produces only minimal artifacts, at the cost of slight blurriness.[1]


int  target_width =
The width of the output.


int  target_height =
The height of the output.


float  src_left = 0.0
Cropping of the left edge.


float  src_top = 0.0
Cropping of the top edge.


float  src_width = Source width
If > 0.0 it sets the width of the clip before resizing.
If <= 0.0 it sets the cropping of the right edges before resizing.


float  src_height = Source height
If > 0.0 it sets the height of the clip before resizing.
If <= 0.0 it sets the cropping of the bottom edges before resizing


int  taps =
Parameter for z_LanczosResize only.
Controls the filter’s number of lobes, or taps. Increasing the number of lobes improves sharpness at the cost of increased ringing.
You might occasionally see the tap count appended to the filter name to clarify the exact filter used, e.g. Lanczos2 for 2 taps.
For downscaling, higher tap counts might help in suppressing Moiré effects.


string  chromaloc_op = "left=>left"
Chroma location operation description.
Format is "[locS]=>[locD]"
Chroma location table, names in parenthesis are compatibility aliases:
  • "left" ("mpeg2") | "center" ("jpeg" and "mpeg1") | "top_left"
Example JPEG to MPEG2: "center=>left"


string  dither = "none"
Dithering type: "none" | "ordered" | "random" | "error_diffusion"


Examples

HD YUV 4:2:0 Rec. 709 to 16-bit RGB:

AviSource("blah.avi") 
z_ConvertFormat(pixel_type="RGBP16", colorspace_op="709:709:709:limited=>rgb:709:709:full")


RGB to 8-bit YV12 (YUV 4:2:0 Rec. 709):

AviSource("blah.avi") 
ConvertToPlanarRGB()
z_ConvertFormat(pixel_type="YUV420P8", colorspace_op="rgb:709:709:full=>709:709:709:limited")

Note: RGB input must be planar, use ConvertToPlanarRGB().


Frame properties:

  • If colorspace_op is not defined and there are frame properties, they are used for default source values.
  • If colorspace_op is not defined and there are no frame properties or they are not supported, default values are used as before (there are default values for matrix, range and chromaloc).
  • If colorspace_op is defined and you want to use the frame property for a source value, use "auto".
  • If colorspace_op is defined and you use "auto" without frame property, the default value for that argument will be used if exist.
  • If you use "auto" for argument with frame property that has value of 2 (unspec) and use anything different than "same" for destination, error will be raised.
  • If you use "auto=>same" for matrix/transfer/primaries with frame property 2 (unspec) and you want to make colorspace conversion, error will be raised. For example:
#transfer property has value of 2
#primaries 709 (1)
#input yv12
z_convertformat(pixel_type="rgbp", colorspace_op="auto:auto:709=>rgb:same:470bg") # error raised
#z_convertformat(pixel_type="rgbp", colorspace_op="auto:709:709=>rgb:709:470bg") # ok
#z_convertformat(pixel_type="rgbp", colorspace_op="auto:709:auto=>rgb:same:470bg") # ok
#z_ConvertFormat(colorspace_op="auto:auto=>same:470bg") # error
#z_ConvertFormat(colorspace_op="auto:auto:auto:auto=>same:same:same:f") # ok


Changelog

Version      Date            Changes
r4 2020/10/21 - changes by StvG - fixed crashing when avs+ doesn't support frame properties; - set _SARNum and _SARDen properties; - read the input frame property _ChromaLocation if available; - do not process clips with frame property _FiledBased > 0.
r3 2020/10/15 - changes by StvG - removed parameter prefer_props; - added keyword "auto" for source matrix, transfer, primaries, range. When it's used the corresponding input frame properties are used, if such frame properties don't exist either an error is raised or default matrix and color range are used; - added keyword "auto" for source chromaloc_op. When it's used the corresponding input frame property is used, if such frame property doesn't exist default chromaloc is used.
r2 2020/10/14 - changes by StvG - added keyword 'same' for destination matrix, transfer, primaries, range, chromaloc_op. - When it's used the source value (argument or frame property) is used for destination too.
r1g 2020/10/03 - changes by StvG - added parameter prefer_props; read and set _ChromaLocation, _ColorRange, _Matrix, _Transfer, _Primaries frame properties; added chromaloc_op parameters - bottom_left and bottom.
r1f 2020/08/25 - changes by StvG - added @Losko patch, zimg v3.0.1, added support for frame properties.
r1e 2020/04/23 - changes by StvG - update to zimg@8815111; - z_ConvertFormat: added pixel type RGBP8, RGBAP8, YUV444, YUV444P8, YUVA444P8, YUV422, YUV422P8, YUVA422P8, YUV420, YUV420P8 , YUVA420P8, YUV411, YUV411P8 - added version.
2020/04/08 - changes by StvG - update to zimg@5896a26 - z_ConvertFormat: add "cpu_type", "nominal_luminance", and "approximate_gamma" parameters - z_ConvertFormat: remove "gauss", "lanczos4", "blackman", and "sinc" compatibility aliases - z_ConvertFormat: remove "dv" compatibility alias from chromaloc_op - resizers: add "chromaloc_op" and "dither" parameters - resizers: remove z_BlackmanResize(), z_GaussResize(), and z_SincResize() compatibility aliases.
r1d 2018/03/21 - ...............
r1 2016/10/29 - initial release


Archived Downloads

Version Download Mirror
r4 avsresize_r4.7z avsresize_r4.7z
r3 avsresize_r3.7z avsresize_r3.7z
r2 avsresize_r2.7z avsresize_r2.7z
r1g avsresize_r1g.7z avsresize_r1g.7z
r1f avsresize_r1f.7z avsresize_r1f.7z
r1e avsresize_r1e.7z avsresize_r1e.7z
2020/04/08 avsresize.7z avsresize_20200408.7z
r1d avsresize-r1d.7z avsresize-r1d.7z


External Links

  • Doom9 Forum - 8bit or greater (AviSynth+) linear/gamma light aware resizing?
  • Doom9 Forum - HDRTools vs DitherTools vs ColorMatrix




Back to External Filters

Personal tools