Avsresize

From Avisynth wiki
(Difference between revisions)
Jump to: navigation, search
(r6 update)
(r21)
 
(30 intermediate revisions by 3 users not shown)
Line 2: Line 2:
 
{{Filter3
 
{{Filter3
 
|1=[https://github.com/sekrit-twc sekrit-twc]
 
|1=[https://github.com/sekrit-twc sekrit-twc]
|2=r6
+
|2=r21
|3=[https://cloud.owncube.com/s/KfAcEpqkMPSdagr/download avsresize_r6.7z]
+
|3=[https://web.archive.org/web/20230215081928if_/https://files.videohelp.com/u/223002/avsresize_r21.7z avsresize_r21.7z]
 
|4=Resize  
 
|4=Resize  
 
|5=Open source
 
|5=Open source
Line 14: Line 14:
 
== Requirements ==
 
== Requirements ==
 
* [[AviSynth+]] x86/x64
 
* [[AviSynth+]] x86/x64
* Supported color formats: [[RGB24]], [[RGB32]], [[Y8]], [[YV12]], [[YV16]], [[YV24]]
+
* 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.
 
**All [[planar]] formats (8/10/12/14/16/32-bit, YUV/RGB with or without alpha) are supported.
 
<br>
 
<br>
Line 22: Line 22:
 
===z_ConvertFormat===
 
===z_ConvertFormat===
 
Scaling, colorspace conversion, and depth conversion.
 
Scaling, colorspace conversion, and depth conversion.
:{{Template:FuncDef|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")}}
+
:{{Template:FuncDef|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")}}
 
<br>
 
<br>
 
::{{Par2| |clip| }}
 
::{{Par2| |clip| }}
Line 112: Line 112:
 
|RGBAPS
 
|RGBAPS
 
|-
 
|-
! colspan="10"| All colorspaces are planar. "YUV9" and "YV411" ("YUV411", "YUV411P8") were committed from table above. See [[Avisynthplus_color_formats#Color_Format_Table|AviSynth+ color formats table]].  
+
! colspan="10"| All colorspaces are planar. "YUV9" and "YV411" ("YUV411", "YUV411P8") were omitted from table above. See [[Avisynthplus_color_formats#Color_Format_Table|AviSynth+ color formats table]].  
 
|}
 
|}
 
<br>
 
<br>
Line 191: Line 191:
 
|"ictcp"
 
|"ictcp"
 
|"2020_12"
 
|"2020_12"
|Compatibility aliases
+
|"prophoto"
 
|
 
|
 
|-
 
|-
 
|Compatibility aliases
 
|Compatibility aliases
 
|"st2084"
 
|"st2084"
|"xyz" same as "st428"
+
|Compatibility aliases
 
|
 
|
 
|-
 
|-
 
|"601" same as "470bg"
 
|"601" same as "470bg"
 
|"std-b67"
 
|"std-b67"
|"dci-p3" same as "st431-2"
+
|"xyz" same as "st428"
 
|
 
|
 
|-
 
|-
 
|"2020" same as "2020ncl"
 
|"2020" same as "2020ncl"
 +
|"prophoto"
 +
|"dci-p3" same as "st431-2"
 +
|
 +
|-
 +
|
 
|Compatibility aliases
 
|Compatibility aliases
 
|"display-p3" same as "st432-1"
 
|"display-p3" same as "st432-1"
Line 214: Line 219:
 
|
 
|
 
|-
 
|-
! colspan="4"| see tables on [http://www.vapoursynth.com/doc/functions/resize.html VapourSynth resize documentation]  
+
! colspan="4"| see tables on [http://www.vapoursynth.com/doc/functions/video/resize.html VapourSynth resize documentation]  
 
|}
 
|}
 
<br>
 
<br>
Line 228: Line 233:
 
<br>
 
<br>
 
::{{Par2|interlaced|bool|false}}
 
::{{Par2|interlaced|bool|false}}
::Whether to use interlaced mode (default: false)
+
:::Whether to use interlaced mode.
 
<br>
 
<br>
::{{Par2|src_left|float| }}
+
::{{Par2|src_left|float|0.0}}
::{{Par2|src_top|float| }}
+
::{{Par2|src_top|float|0.0}}
::{{Par2|src_width|float| }}
+
::{{Par2|src_width|float|Source width}}
::{{Par2|src_height|float| }}
+
::{{Par2|src_height|float|Source height}}
 
:::Optional crop rectangle in the input frame.
 
:::Optional crop rectangle in the input frame.
 
<br>
 
<br>
::{{Par2|resample_filter|string| }}
+
::{{Par2|resample_filter|string|"bicubic"}}
 
:::Resampling modes: <code>"point" | "bilinear" | "bicubic" | "spline16" | "spline36" | "spline64" | "lanczos"</code>
 
:::Resampling modes: <code>"point" | "bilinear" | "bicubic" | "spline16" | "spline36" | "spline64" | "lanczos"</code>
 
<br>
 
<br>
Line 244: Line 249:
 
:::Example Bicubic (Mitchell-Netravali): <code>resample_filter="bicubic", filter_param_a=0.333, filter_param_b=0.333</code>
 
:::Example Bicubic (Mitchell-Netravali): <code>resample_filter="bicubic", filter_param_a=0.333, filter_param_b=0.333</code>
 
:::Example 4-tap Lanczos: <code>resample_filter="lanczos", filter_param_a=4</code>
 
:::Example 4-tap Lanczos: <code>resample_filter="lanczos", filter_param_a=4</code>
 +
:::Default for "bicubic": <code>filter_param_a=0.0, filter_param_b=0.5</code>
 +
:::Default for "lanczos": <code>filter_param_a=3</code>
 
<br>
 
<br>
::{{Par2|resample_filter_uv|string| }}
+
::{{Par2|resample_filter_uv|string|resample_filter}}
 
:::Resampling mode for chroma.
 
:::Resampling mode for chroma.
 
<br>
 
<br>
::{{Par2|filter_param_a_uv|float| }}
+
::{{Par2|filter_param_a_uv|float|filter_param_a}}
::{{Par2|filter_param_b_uv|float| }}
+
::{{Par2|filter_param_b_uv|float|filter_param_b}}
 
:::First and second parameter to chroma resampler.
 
:::First and second parameter to chroma resampler.
 
<br>
 
<br>
Line 260: Line 267:
 
<br>
 
<br>
 
::{{Par2|nominal_luminance|float|100.0}}
 
::{{Par2|nominal_luminance|float|100.0}}
:::Nominal peak luminance in cd/m^2 when converting HDR content to RGB Linear.
+
:::Nominal peak luminance in cd/m^2 when converting HDR content to RGB Linear. More info [https://github.com/sekrit-twc/zimg/blob/93f8504a67373d428158219eb3aca0455e4c20ca/src/zimg/api/zimg.h#L595 here].
 
<br>
 
<br>
 
::{{Par2|approximate_gamma|bool|true}}
 
::{{Par2|approximate_gamma|bool|true}}
 
:::Evaluating transfer functions at reduced precision.
 
:::Evaluating transfer functions at reduced precision.
 +
<br>
 +
::{{Par2|use_props|int|}}
 +
:::Whether to read and set frame properties:
 +
:::*-1: If frame properties are supported - if every option of <code>colorspace_op</code> and <code>chromaloc_op</code> are specified and different than "auto", 0, otherwise 1. <br> 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: <code>z_ChromaLocation, z_ColorRange, z_Matrix, z_Transfer, z_Primaries</code>. <br> Every option of <code>colorspace_op</code> and <code>chromaloc_op</code> must be specified and different than "auto".
 +
:::*3: Save properties of the source clip as frame properties: <code>z_ChromaLocation, z_ColorRange, z_Matrix, z_Transfer, z_Primaries</code>. <br> Frame properties <code>_ChromaLocation, _ColorRange, _Matrix, _Transfer, _Primaries</code> must exist. <br> Frame properties <code>_Matrix, _Transfer, _Primaries</code> must have values different than 2 (unspec).
 +
:::*4: Use z_xxx frame properties as target values. <br> z_xxx frame properties are removed after the colorspace conversion.
 +
<br>
 +
:::<code>use_props=0</code> is faster than <code>use_props=1</code>
 +
:::<code>use_props=2</code> is faster than <code>use_props=3</code>
 +
:::Example <code>use_props=2</code> and <code>use_props=4</code>
 +
<div style="margin-left: 6em; max-width: 87em">
 +
<pre>
 +
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)
 +
</pre>
 +
</div>
 +
:::Example <code>use_props=3</code> and <code>use_props=4</code>
 +
<div style="margin-left: 6em; max-width: 87em">
 +
<pre>
 +
z_ConvertFormat(pixel_type="rgbp", colorspace_op="709:709=>rgb:linear", use_props=3)
 +
z_ConvertFormat(pixel_type="yv12", use_props=4)
 +
</pre>
 +
</div>
 +
<br>
 +
::{{Par2|scene_referred|bool|false}}
 +
:::Whether to use scene-referred transfer function (default false).
 
<br>
 
<br>
  
Line 269: Line 305:
 
*The name of the frame properties that are read and set are: <code>_ChromaLocation, _ColorRange, _Matrix, _Transfer, _Primaries</code>
 
*The name of the frame properties that are read and set are: <code>_ChromaLocation, _ColorRange, _Matrix, _Transfer, _Primaries</code>
 
*The frame properties read and set the corresponding numerical index of the parameters. For example: matrix <code>"709"</code> has numerical index `1` and the frame property have value of `1`.
 
*The frame properties read and set the corresponding numerical index of the parameters. For example: matrix <code>"709"</code> has numerical index `1` and the frame property have value of `1`.
*See [[#Examples|examples]] for more information.
+
*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:
 +
<pre>
 +
#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
 +
</pre>
  
 
<br>
 
<br>
  
 
===Resizers===
 
===Resizers===
z.lib compatibility wrappers with same syntax as [[Resize|built-in resizers]].
+
z.lib compatibility wrappers with the same syntax as the [[Resize|built-in resizers]].
:{{Template:FuncDef|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")}}
+
:{{Template:FuncDef|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")}}
  
:{{Template:FuncDef|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")}}
+
:{{Template:FuncDef|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")}}
  
:{{Template:FuncDef|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")}}
+
:{{Template:FuncDef|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")}}
  
:{{Template:FuncDef|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")}}
+
:{{Template:FuncDef|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")}}
  
:{{Template:FuncDef|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")}}
+
:{{Template:FuncDef|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")}}
  
:{{Template:FuncDef|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")}}
+
:{{Template:FuncDef|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")}}
  
:{{Template:FuncDef|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")}}
+
:{{Template:FuncDef|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")}}
  
:{{Template:FuncDef|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")}}
+
:{{Template:FuncDef|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")}}
 
<br>
 
<br>
 
<br>
 
<br>
 
::{{Par2| |clip| }}
 
::{{Par2| |clip| }}
 
:::A clip to process. All planar formats are supported.
 
:::A clip to process. All planar formats are supported.
 +
<br>
 +
::{{Par2||int| }}
 +
:::<code>target_width</code>: the width of the output.
 +
<br>
 +
::{{Par2||int| }}
 +
:::<code>target_height</code>: the height of the output.
 
<br>
 
<br>
 
::{{Par2|b|float|0.0}}
 
::{{Par2|b|float|0.0}}
Line 307: Line 364:
 
:::*<code>b=0.0, c=1.0</code> : Sharp Bicubic
 
:::*<code>b=0.0, c=1.0</code> : 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.[https://guideencodemoe-mkdocs.readthedocs.io/encoding/resampling/#mitchell-netravali-bicubic]
 
:::Hermite is often considered one of the best choices for downscaling, as it produces only minimal artifacts, at the cost of slight blurriness.[https://guideencodemoe-mkdocs.readthedocs.io/encoding/resampling/#mitchell-netravali-bicubic]
<br>
+
:::B/C splines by Nicolas Robidoux:
::{{Par2|target_width|int| }}
+
:::*<code>b=0.3782, c=0.3109</code> : Robidoux
:::The width of the output.
+
:::*<code>b=0.2620, c=0.3690</code> : RobidouxSharp
<br>
+
:::*<code>b=0.6796, c=0.1602</code> : RobidouxSoft
::{{Par2|target_height|int| }}
+
:::Note: these numbers are rounded, exact values can be found [https://legacy.imagemagick.org/discourse-server/viewtopic.php?f=22&t=19823&start=30 here] and [https://github.com/mpv-player/mpv/issues/2637 here]
:::The height of the output.
+
:::Didée's method to resize 1080p content to 720p: <code>b=-0.5, c=0.25</code>  [https://forum.doom9.org/showthread.php?p=1579385#post1579385] [https://forum.doom9.org/showthread.php?p=1748922#post1748922]
 
<br>
 
<br>
 
::{{Par2|src_left|float|0.0}}
 
::{{Par2|src_left|float|0.0}}
Line 328: Line 385:
 
:::If <= 0.0 it sets the cropping of the bottom edges before resizing
 
:::If <= 0.0 it sets the cropping of the bottom edges before resizing
 
<br>
 
<br>
::{{Par2|taps|int| }}
+
::{{Par2|taps|int|3}}
 
:::Parameter for <code>z_LanczosResize</code> only.
 
:::Parameter for <code>z_LanczosResize</code> only.
 
:::Controls the filter’s number of lobes, or taps. Increasing the number of lobes improves sharpness at the cost of increased ringing.  
 
:::Controls the filter’s number of lobes, or taps. Increasing the number of lobes improves sharpness at the cost of increased ringing.  
Line 344: Line 401:
 
:::Dithering type: <code>"none" | "ordered" | "random" | "error_diffusion"</code>
 
:::Dithering type: <code>"none" | "ordered" | "random" | "error_diffusion"</code>
 
<br>
 
<br>
 +
::{{Par2|interlaced|bool|false}}
 +
:::Whether to use interlaced mode.
 +
<br>
 +
 
==Examples==
 
==Examples==
'''HD YUV 4:2:0 Rec. 709 to 16-bit RGB:'''
+
===YUV⟷RGB Conversion===
 +
*'''HD YUV 4:2:0 Rec. 709 to 16-bit RGB:'''
 
  AviSource("blah.avi")  
 
  AviSource("blah.avi")  
 
  z_ConvertFormat(pixel_type="RGBP16", colorspace_op="709:709:709:limited=>rgb:709:709:full")
 
  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):'''
+
*'''RGB to 8-bit YV12 (YUV 4:2:0 Rec. 709):'''
 
  AviSource("blah.avi")  
 
  AviSource("blah.avi")  
  ConvertToPlanarRGB()
+
  ConvertToPlanarRGB() # omit if source is already planar RGB
 
  z_ConvertFormat(pixel_type="YUV420P8", colorspace_op="rgb:709:709:full=>709:709:709:limited")
 
  z_ConvertFormat(pixel_type="YUV420P8", colorspace_op="rgb:709:709:full=>709:709:709:limited")
 
Note: RGB input must be planar, use [[Convert|ConvertToPlanarRGB()]].
 
Note: RGB input must be planar, use [[Convert|ConvertToPlanarRGB()]].
  
  
'''Frame properties:'''
+
===Changing Colorimetry===
*If colorspace_op is not defined and there are frame properties, they are used for default source values.
+
*'''SD NTSC Rec. 601 to HD Rec. 709'''
*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).
+
AviSource("blah.avi") # let's assume the source is a NTSC DVD clip
*If colorspace_op is defined and you want to use the frame property for a source value, use "auto".
+
z_ConvertFormat(colorspace_op="470bg:601:170m:full=>709:709:709:full")
*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.
+
*'''SD PAL Rec. 601 to HD Rec. 709'''
*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:
+
AviSource("blah.avi") # let's assume the source is a PAL DVD clip
<pre>
+
z_ConvertFormat(colorspace_op="470bg:601:470bg:full=>709:709:709:full")
#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
+
</pre>
+
  
 +
*'''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. [https://forum.doom9.org/showthread.php?p=1906754&highlight=full#post1906754].
 +
* To learn more about matrix, transfer, and primaries and its different names, see [https://forum.doom9.org/showthread.php?p=1897824#post1897824 this post on Doom9].
 
<br>
 
<br>
 +
 +
===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.<br>
 +
By default <code>approximate_gamma=true</code>, you can set it to false but the speed decrease dramatically and it's probably not worth it.<br>
 +
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 [https://forum.doom9.org/showthread.php?p=1948138#post1948138].
 +
 +
 +
*'''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")
 +
 +
<br>
 +
 
== Changelog ==
 
== Changelog ==
 
  Version      Date            Changes<br>
 
  Version      Date            Changes<br>
 +
r21          2023/02/15      - changes by [https://forum.doom9.org/showthread.php?p=1982991#post1982991 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.<BR>
 +
r20          2023/01/30      - changes by [https://forum.doom9.org/showthread.php?p=1982087#post1982087 StvG]
 +
                              - not read "_FieldBased" frame prop when use_props=0;
 +
                              - added ProPhotoRGB (TomArrow).<br>
 +
r19          2022/08/17      - changes by [https://forum.doom9.org/showthread.php?p=1973326#post1973326 StvG]
 +
                              - fixed the behavior when missing frame property;
 +
                              - the matrix between yuv<->grey isn't silently changed anymore.<br>
 +
r18          2022/08/15      - changes by [https://forum.doom9.org/showthread.php?p=1973192#post1973192 StvG]
 +
                              - fixed output frame properties when use_props=0 and colorspace_op/chromaloc_op not specified.<br>
 +
r17          2022/08/13      - changes by [https://forum.doom9.org/showthread.php?p=1973142#post1973142 StvG]
 +
                              - use_props=-1 improved a bit more.<br>
 +
r16          2022/08/09      - changes by [https://forum.doom9.org/showthread.php?p=1972971#post1972971 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. <br>
 +
r15          2022/08/06      - changes by [https://forum.doom9.org/showthread.php?p=1972716#post1972716 StvG]
 +
                              - relaxed restrictions for use_props=0;
 +
                              - added scene_referred parameter (default false).<br>
 +
r14          2022/04/18      - changes by [https://forum.doom9.org/showthread.php?p=1967682#post1967682 StvG]
 +
                              - fixed regression (r12) when reading frame properties (use_props=3/4).<br>
 +
r13          2022/04/14      - changes by [https://forum.doom9.org/showthread.php?p=1967463#post1967463 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.<br>
 +
r12          2021/11/21      - changes by [https://forum.doom9.org/showthread.php?p=1957876#post1957876 StvG]
 +
                              - changed use_props type from bool to int.<br>
 +
r11          2021/11/18      - changes by [https://forum.doom9.org/showthread.php?p=1957643#post1957643 StvG]
 +
                              - added parameter use_props (whether to read and set frame properties)
 +
                              - zimg 3.0.3.<br>
 +
r10          2021/08/12      - changes by [https://forum.doom9.org/showthread.php?p=1949669#post1949669 StvG]
 +
                              - do not set matrix frame property when source matrix frame property is undef and color family is not changed
 +
                              - zimg@bf73dbe.<br>
 +
r9          2021/06/30      - changes by [https://forum.doom9.org/showthread.php?p=1946523#post1946523 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.<br>
 +
r8          2021/06/29      - changes by [https://forum.doom9.org/showthread.php?p=1946427#post1946427 StvG]
 +
                              - changed MT mode to [[MT_MULTI_INSTANCE]]<br>
 +
r7          2021/06/23      - changes by [https://forum.doom9.org/showthread.php?p=1945780#post1945780 StvG]
 +
                              - fixed frame properties reading.<br>
 
  r6          2021/05/31      - changes by [https://forum.doom9.org/showthread.php?p=1943908#post1943908 StvG]
 
  r6          2021/05/31      - changes by [https://forum.doom9.org/showthread.php?p=1943908#post1943908 StvG]
                               - registered as [[MT_NICE_FILTER]]
+
                               - registered as MT_NICE_FILTER
 
                               - read frame properties from every frame (previously only from the first frame)
 
                               - read frame properties from every frame (previously only from the first frame)
 
                               - zimg@8d0b839.<br>
 
                               - zimg@8d0b839.<br>
Line 429: Line 569:
 
!!width="150px"| Download
 
!!width="150px"| Download
 
!!width="150px"| Mirror
 
!!width="150px"| Mirror
 +
|-
 +
!r21
 +
|[https://forum.doom9.org/showthread.php?p=1982991#post1982991 avsresize_r21.7z]
 +
|[https://web.archive.org/web/20230215081928if_/https://files.videohelp.com/u/223002/avsresize_r21.7z avsresize_r21.7z]
 +
|-
 +
!r20
 +
|[https://forum.doom9.org/showthread.php?p=1982087#post1982087 avsresize_r20.7z]
 +
|[https://web.archive.org/web/20230130075804if_/https://files.videohelp.com/u/223002/avsresize_r20.7z avsresize_r20.7z]
 +
|-
 +
!r19
 +
|[https://forum.doom9.org/showthread.php?p=1973326#post1973326 avsresize_r19.7z]
 +
|[https://web.archive.org/web/20220818022554if_/https://files.videohelp.com/u/223002/avsresize_r19.7z avsresize_r19.7z]
 +
|-
 +
!r18
 +
|[https://forum.doom9.org/showthread.php?p=1973192#post1973192 avsresize_r18.7z]
 +
|[https://web.archive.org/web/20220815000722if_/https://files.videohelp.com/u/223002/avsresize_r18.7z avsresize_r18.7z]
 +
|-
 +
!r17
 +
|[https://forum.doom9.org/showthread.php?p=1973142#post1973142 avsresize_r17.7z]
 +
|[https://web.archive.org/web/20220813203417if_/https://files.videohelp.com/u/223002/avsresize_r17.7z avsresize_r17.7z]
 +
|-
 +
!r16
 +
|[https://forum.doom9.org/showthread.php?p=1972971#post1972971 avsresize_r16.7z]
 +
|[https://web.archive.org/web/20220810145814if_/https://files.videohelp.com/u/223002/avsresize_r16.7z avsresize_r16.7z]
 +
|-
 +
!r15
 +
|[https://forum.doom9.org/showthread.php?p=1972716#post1972716 avsresize_r15.7z]
 +
|[https://web.archive.org/web/20220806144931if_/https://files.videohelp.com/u/223002/avsresize_r15.7z avsresize_r15.7z]
 +
|-
 +
!r14
 +
|[https://forum.doom9.org/showthread.php?p=1967682#post1967682 avsresize_r14.7z]
 +
|[https://web.archive.org/web/20220419113153if_/https://files.videohelp.com/u/223002/avsresize_r14.7z avsresize_r14.7z]
 +
|-
 +
!r13
 +
|[https://forum.doom9.org/showthread.php?p=1967463#post1967463 avsresize_r13.7z]
 +
|[https://web.archive.org/web/20220415100326if_/https://files.videohelp.com/u/223002/avsresize_r13.7z avsresize_r13.7z]
 +
|-
 +
!r12
 +
|[https://forum.doom9.org/showthread.php?p=1957876#post1957876 avsresize_r12.7z]
 +
|[https://web.archive.org/web/20211121225346if_/https://files.videohelp.com/u/223002/avsresize_r12.7z avsresize_r12.7z]
 +
|-
 +
!r11
 +
|[https://forum.doom9.org/showthread.php?p=1957643#post1957643 avsresize_r11.7z]
 +
|[https://web.archive.org/web/20211118222533if_/https://files.videohelp.com/u/223002/avsresize_r11.7z avsresize_r11.7z]
 +
|-
 +
!r10
 +
|[https://forum.doom9.org/showthread.php?p=1949669#post1949669 avsresize_r10.7z]
 +
|[https://web.archive.org/web/20210813212341if_/https://files.videohelp.com/u/223002/avsresize_r10.7z avsresize_r10.7z]
 +
|-
 +
!r9
 +
|[https://forum.doom9.org/showthread.php?p=1946523#post1946523 avsresize_r9.7z]
 +
|[https://web.archive.org/web/20210721045904if_/https://files.videohelp.com/u/223002/avsresize_r9.7z avsresize_r9.7z]
 +
|-
 +
!r8
 +
|[https://forum.doom9.org/showthread.php?p=1946427#post1946427 avsresize_r8.7z]
 +
|[https://web.archive.org/web/20210721050245if_/https://files.videohelp.com/u/223002/avsresize_r8.7z avsresize_r8.7z]
 +
|-
 +
!r7
 +
|[https://forum.doom9.org/showpost.php?p=1945780&postcount=163 avsresize_r7.7z]
 +
|[https://web.archive.org/web/20210625201951if_/https://files.videohelp.com/u/223002/avsresize_r7.7z avsresize_r7.7z]
 
|-
 
|-
 
!r6
 
!r6
 
|[https://cloud.owncube.com/s/KfAcEpqkMPSdagr/download avsresize_r6.7z]
 
|[https://cloud.owncube.com/s/KfAcEpqkMPSdagr/download avsresize_r6.7z]
|[https://web.archive.org/web/20210606012435if_/https://files.videohelp.com/u/223002/avsresize_r6.7z vsresize_r6.7z]
+
|[https://web.archive.org/web/20210606012435if_/https://files.videohelp.com/u/223002/avsresize_r6.7z avsresize_r6.7z]
 
|-
 
|-
 
!r5
 
!r5

Latest revision as of 09:29, 15 February 2023

Abstract
Author sekrit-twc
Version r21
Download avsresize_r21.7z
Category Resize
License Open source
Discussion Doom9 Forum


Contents

[edit] Description

z.lib resizers for AviSynth+

[edit] 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.


[edit] Syntax and Parameters

[edit] 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.


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 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.
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"
Example JPEG to MPEG2: "center=>left"


bool  interlaced = false
Whether to use interlaced mode.


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.


string  resample_filter = "bicubic"
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
Default for "bicubic": filter_param_a=0.0, filter_param_b=0.5
Default for "lanczos": filter_param_a=3


string  resample_filter_uv = resample_filter
Resampling mode for chroma.


float  filter_param_a_uv = filter_param_a
float  filter_param_b_uv = filter_param_b
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. More info here.


bool  approximate_gamma = true
Evaluating transfer functions at reduced precision.


int  use_props =
Whether to read and set frame properties:
  • -1: If frame properties are supported - if every option of colorspace_op and chromaloc_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 of colorspace_op and chromaloc_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.


use_props=0 is faster than use_props=1
use_props=2 is faster than use_props=3
Example use_props=2 and use_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 and use_props=4
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).


[edit] 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


[edit] 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.


int   =
target_width: the width of the output.


int   =
target_height: the height of the output.


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]
B/C splines by Nicolas Robidoux:
  • b=0.3782, c=0.3109 : Robidoux
  • b=0.2620, c=0.3690 : RobidouxSharp
  • b=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]


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 = 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.


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"


bool  interlaced = false
Whether to use interlaced mode.


[edit] Examples

[edit] 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().


[edit] 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.


[edit] 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")


[edit] 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


[edit] Archived Downloads

Version Download Mirror
r21 avsresize_r21.7z avsresize_r21.7z
r20 avsresize_r20.7z avsresize_r20.7z
r19 avsresize_r19.7z avsresize_r19.7z
r18 avsresize_r18.7z avsresize_r18.7z
r17 avsresize_r17.7z avsresize_r17.7z
r16 avsresize_r16.7z avsresize_r16.7z
r15 avsresize_r15.7z avsresize_r15.7z
r14 avsresize_r14.7z avsresize_r14.7z
r13 avsresize_r13.7z avsresize_r13.7z
r12 avsresize_r12.7z avsresize_r12.7z
r11 avsresize_r11.7z avsresize_r11.7z
r10 avsresize_r10.7z avsresize_r10.7z
r9 avsresize_r9.7z avsresize_r9.7z
r8 avsresize_r8.7z avsresize_r8.7z
r7 avsresize_r7.7z avsresize_r7.7z
r6 avsresize_r6.7z avsresize_r6.7z
r5 avsresize_r5.7z avsresize_r5.7z
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


[edit] 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