Avsresize
From Avisynth wiki
Abstract | |
---|---|
Author | sekrit-twc |
Version | r21 |
Download | avsresize_r21.7z |
Category | Resize |
License | Open source |
Discussion | Doom9 Forum |
Contents |
Description
z.lib resizers for AviSynth+
Requirements
- AviSynth+ x86/x64
- Supported color formats: Y8, YV12, YV16, YV24
- All planar formats (8/10/12/14/16/32-bit, YUV/RGB with or without alpha) are supported.
Syntax and Parameters
z_ConvertFormat
Scaling, colorspace conversion, and depth conversion.
- z_ConvertFormat (clip clip, int "width", int "height", string "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", bool "use_props", bool "scene_referred")
- clip =
- Input clip.
- clip =
- int width =
- int height =
- Output width and height in pixels.
- int width =
- string pixel_type =
- Output pixel type ("YV12", "YUV420P16", etc.).
- string pixel_type =
Bit Depth Grey YUV420 YUVA420 YUV422 YUVA422 YUV444 YUVA444 RGB RGBA 8 Y8 YV12
YUV420
YUV420P8YUVA420
YUVA420P8YV16
YUV422
YUV422P8YUVA422
YUVA422P8YV24
YUV444
YUV444P8YUVA444
YUVA444P8RGBP
RGBP8RGBAP
RGBAP810 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 omitted 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.
- string colorspace_op =
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" "prophoto" Compatibility aliases "st2084" Compatibility aliases "601" same as "470bg" "std-b67" "xyz" same as "st428" "2020" same as "2020ncl" "prophoto" "dci-p3" same as "st431-2" 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"
-
- Chroma location table, names in parenthesis are compatibility aliases:
- Example JPEG to MPEG2:
"center=>left"
- string chromaloc_op =
- bool interlaced = false
- Whether to use interlaced mode.
- bool interlaced = false
- float src_left = 0.0
- float src_top = 0.0
- float src_width = Source width
- float src_height = Source height
- Optional crop rectangle in the input frame.
- float src_left = 0.0
- string resample_filter = "bicubic"
- Resampling modes:
"point" | "bilinear" | "bicubic" | "spline16" | "spline36" | "spline64" | "lanczos"
- Resampling modes:
- string resample_filter = "bicubic"
- 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
- Default for "bicubic":
filter_param_a=0.0, filter_param_b=0.5
- Default for "lanczos":
filter_param_a=3
- float filter_param_a =
- string resample_filter_uv = resample_filter
- Resampling mode for chroma.
- string resample_filter_uv = resample_filter
- float filter_param_a_uv = filter_param_a
- float filter_param_b_uv = filter_param_b
- First and second parameter to chroma resampler.
- float filter_param_a_uv = filter_param_a
- string dither_type = "none"
- Dithering type:
"none" | "ordered" | "random" | "error_diffusion"
- Dithering type:
- string dither_type = "none"
- 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")
- CPU type, names in parenthesis are compatibility aliases:
- string cpu_type =
- float nominal_luminance = 100.0
- Nominal peak luminance in cd/m^2 when converting HDR content to RGB Linear. More info here.
- float nominal_luminance = 100.0
- bool approximate_gamma = true
- Evaluating transfer functions at reduced precision.
- bool approximate_gamma = true
- int use_props =
- Whether to read and set frame properties:
- -1: If frame properties are supported - if every option of
colorspace_op
andchromaloc_op
are specified and different than "auto", 0, otherwise 1.
If frame properties are not supported - 0. - 0: If frame properties are supported - only set frame properties.
- 1: Read and set frame properties.
- 2: Save properties of the source clip as frame properties:
z_ChromaLocation, z_ColorRange, z_Matrix, z_Transfer, z_Primaries
.
Every option ofcolorspace_op
andchromaloc_op
must be specified and different than "auto". - 3: Save properties of the source clip as frame properties:
z_ChromaLocation, z_ColorRange, z_Matrix, z_Transfer, z_Primaries
.
Frame properties_ChromaLocation, _ColorRange, _Matrix, _Transfer, _Primaries
must exist.
Frame properties_Matrix, _Transfer, _Primaries
must have values different than 2 (unspec). - 4: Use z_xxx frame properties as target values.
z_xxx frame properties are removed after the colorspace conversion.
- -1: If frame properties are supported - if every option of
- Whether to read and set frame properties:
- int use_props =
use_props=0
is faster thanuse_props=1
use_props=2
is faster thanuse_props=3
- Example
use_props=2
anduse_props=4
z_ConvertFormat(pixel_type="rgbp", colorspace_op="709:709:709:l=>rgb:linear:709:f", chromaloc_op="left=>left", use_props=2) z_ConvertFormat(pixel_type="yv12", use_props=4)
- Example
use_props=3
anduse_props=4
- Example
z_ConvertFormat(pixel_type="rgbp", colorspace_op="709:709=>rgb:linear", use_props=3) z_ConvertFormat(pixel_type="yv12", use_props=4)
- bool scene_referred = false
- Whether to use scene-referred transfer function (default false).
- bool scene_referred = false
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`. - 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
Resizers
z.lib compatibility wrappers with the same syntax as the 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", bool "interlaced")
- 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", bool "interlaced")
- z_BicubicResize (clip, int target_width, int target_height, float "b", float "c", float "src_left", float "src_top", float "src_width", float "src_height", string "chromaloc_op", string "dither", bool "interlaced")
- 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", bool "interlaced")
- 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", bool "interlaced")
- 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", bool "interlaced")
- 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", bool "interlaced")
- 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", bool "interlaced")
- clip =
- A clip to process. All planar formats are supported.
- clip =
- int =
target_width
: the width of the output.
- int =
- int =
target_height
: the height of the output.
- int =
- float b = 0.0
- float c = 0.5
- Parameters for
z_BicubicResize
only. b
andc
can be used to tweak the filter’s behavior. For upscaling, it is recommended to use values that satisfy the equationb + 2c = 1
.- Roughly speaking, raising B will cause blurring and raising C will cause ringing.
b=1.0, c=0.0
: B-Splineb=0.0, c=0.0
: Hermiteb=1/3, c=1/3
: Mitchell-Netravali cubic filterb=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]
- B/C splines by Nicolas Robidoux:
b=0.3782, c=0.3109
: Robidouxb=0.2620, c=0.3690
: RobidouxSharpb=0.6796, c=0.1602
: RobidouxSoft
- Note: these numbers are rounded, exact values can be found here and here
- Didée's method to resize 1080p content to 720p:
b=-0.5, c=0.25
[2] [3]
- Parameters for
- float b = 0.0
- float src_left = 0.0
- Cropping of the left edge.
- float src_left = 0.0
- float src_top = 0.0
- Cropping of the top edge.
- float src_top = 0.0
- 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_width = Source width
- 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
- float src_height = Source height
- int taps = 3
- 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.
- Parameter for
- int taps = 3
- 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"
-
- Chroma location table, names in parenthesis are compatibility aliases:
- Example JPEG to MPEG2:
"center=>left"
- string chromaloc_op = "left=>left"
- string dither = "none"
- Dithering type:
"none" | "ordered" | "random" | "error_diffusion"
- Dithering type:
- string dither = "none"
- bool interlaced = false
- Whether to use interlaced mode.
- bool interlaced = false
Examples
YUV⟷RGB Conversion
- 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() # omit if source is already planar RGB z_ConvertFormat(pixel_type="YUV420P8", colorspace_op="rgb:709:709:full=>709:709:709:limited")
Note: RGB input must be planar, use ConvertToPlanarRGB().
Changing Colorimetry
- SD NTSC Rec. 601 to HD Rec. 709
AviSource("blah.avi") # let's assume the source is a NTSC DVD clip z_ConvertFormat(colorspace_op="470bg:601:170m:full=>709:709:709:full")
- SD PAL Rec. 601 to HD Rec. 709
AviSource("blah.avi") # let's assume the source is a PAL DVD clip z_ConvertFormat(colorspace_op="470bg:601:470bg:full=>709:709:709:full")
- Rec. 709 SDR to Rec. 2020 SDR
AviSource("blah.avi") # let's assume the source is BT709 SDR z_ConvertFormat(colorspace_op="709:709:709:full=>2020:2020:2020:full")
- Rec. 709 SDR to Rec. 2020 HLG HDR
AviSource("blah.avi") # let's assume the source is BT709 SDR z_ConvertFormat(colorspace_op="709:709:709:full=>2020ncl:std-b67:2020:full")
- Rec. 2020 SDR to Rec. 709 SDR
AviSource("blah.avi") # let's assume the source is BT2020 SDR z_ConvertFormat(colorspace_op="2020:2020:2020:full=>709:709:709:full")
- Note that the examples above use full=>full since it does not truncate the brightest and darkest pixels, as opposed to limited=>limited. [4].
- To learn more about matrix, transfer, and primaries and its different names, see this post on Doom9.
Linear Light Downscaling
In the following examples, the source is first converted to linear light RGB, then resized and converted back to the original format.
By default approximate_gamma=true
, you can set it to false but the speed decrease dramatically and it's probably not worth it.
Also note that scaling in linear light could easily lead to increased/or even create haloing. The chance is very high when using spline36 as the resample filter [5].
- HD (Rec709) content:
z_ConvertFormat(pixel_type="RGBPS", colorspace_op="709:709:709:limited=>rgb:linear:709:full", resample_filter="spline36") z_ConvertFormat(width=1280, height=720, pixel_type="YUV420P16", colorspace_op="rgb:linear:709:full=>709:709:709:limited", resample_filter="spline36")
- SD NTSC content:
z_ConvertFormat(pixel_type="RGBPS", colorspace_op="470bg:601:170m:limited=>rgb:linear:170m:full", resample_filter="spline36") z_ConvertFormat(width=320, height=240, pixel_type="YUV420P16", colorspace_op="rgb:linear:170m:full=>470bg:601:170m:limited", resample_filter="spline36")
- SD PAL content:
z_ConvertFormat(pixel_type="RGBPS", colorspace_op="470bg:601:470bg:limited=>rgb:linear:470bg:full", resample_filter="spline36") z_ConvertFormat(width=320, height=240, pixel_type="YUV420P16", colorspace_op="rgb:linear:470bg:full=>470bg:601:470bg:limited", resample_filter="spline36")
- JPEG (e.g. pictures):
z_ConvertFormat(pixel_type="RGBPS", colorspace_op="601:601:470bg:full=>rgb:linear:470bg:full", chromaloc_op="center=>center", resample_filter="spline36") z_ConvertFormat(width=480, height=360, pixel_type="YUV420P16", colorspace_op="rgb:linear:470bg:full=>601:601:470bg:full", chromaloc_op="center=>center", resample_filter="spline36")
- RGB content:
z_ConvertFormat(pixel_type="RGBPS", colorspace_op="rgb:srgb:709:full=>rgb:linear:709:full", resample_filter="spline36") z_ConvertFormat(width=1280, height=720, pixel_type="RGBP16", colorspace_op="rgb:linear:709:full=>rgb:srgb:709:full", resample_filter="spline36")
Changelog
Version Date Changes
r21 2023/02/15 - changes by StvG - throw error if IsFieldBased()=true and interlaced=false/use_props=1; - resizer wrappers: added parameter interlaced; - changed behavior of interlaced=true - previously it force use_props=0; now it doesn't have effect when use_props=1.
r20 2023/01/30 - changes by StvG - not read "_FieldBased" frame prop when use_props=0; - added ProPhotoRGB (TomArrow).
r19 2022/08/17 - changes by StvG - fixed the behavior when missing frame property; - the matrix between yuv<->grey isn't silently changed anymore.
r18 2022/08/15 - changes by StvG - fixed output frame properties when use_props=0 and colorspace_op/chromaloc_op not specified.
r17 2022/08/13 - changes by StvG - use_props=-1 improved a bit more.
r16 2022/08/09 - changes by StvG - improved use_props=-1; - throw error when use_props=0 and _FieldBased/_Field > 0; - added support for interlaced clips: when interlaced=true, always use_props=0.
r15 2022/08/06 - changes by StvG - relaxed restrictions for use_props=0; - added scene_referred parameter (default false).
r14 2022/04/18 - changes by StvG - fixed regression (r12) when reading frame properties (use_props=3/4).
r13 2022/04/14 - changes by StvG - zimg@dd4c4df; - use_props= -1: If frame properties are supported - if every option of colorspace_op and chromaloc_op (for src/dst colorspace with subsampling w/h > 0) are specified and different than "auto", 0, otherwise 1.
r12 2021/11/21 - changes by StvG - changed use_props type from bool to int.
r11 2021/11/18 - changes by StvG - added parameter use_props (whether to read and set frame properties) - zimg 3.0.3.
r10 2021/08/12 - changes by StvG - do not set matrix frame property when source matrix frame property is undef and color family is not changed - zimg@bf73dbe.
r9 2021/06/30 - changes by StvG - do not use the same color range for the destination when frame property available and source/destination color family is different; - set the correct color range frame property value for destination YUV 32-bit.
r8 2021/06/29 - changes by StvG - changed MT mode to MT_MULTI_INSTANCE
r7 2021/06/23 - changes by StvG - fixed frame properties reading.
r6 2021/05/31 - changes by StvG - registered as MT_NICE_FILTER - read frame properties from every frame (previously only from the first frame) - zimg@8d0b839.
r5 2020/10/30 - changes by StvG - use chromaloc frame property (when available) for the legacy resizers.
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
External Links
- Doom9 Forum - 8bit or greater (AviSynth+) linear/gamma light aware resizing?
- Doom9 Forum - HDRTools vs DitherTools vs ColorMatrix
Back to External Filters ←