From Avisynth wiki
(Difference between revisions)
Jump to: navigation, search
Line 67: Line 67:
* Also, for an example of a 4:3 capture warped to fit on a 16:9 screen see [ WarpTest2.jpg].
* Also, for an example of a 4:3 capture warped to fit on a 16:9 screen see [ WarpTest2.jpg].
* There is a bug in {{Template:FuncDef3|WarpedResize}} with [[YV12]] sources – see [ here] ( for a report. Use the following script to work around the problem:
* There is a bug in {{Template:FuncDef3|WarpedResize}} with [[YV12]] sources (fixed in v0.3.5.0) – see [ here] ( for a report. Use the following script to work around the problem:
<div {{BoxWidthIndent|56|1}} >
<div {{BoxWidthIndent|56|1}} >
  ## fix WarpedResize YV12 chroma bug; make warp arguments optional  
  ## fix WarpedResize YV12 chroma bug; make warp arguments optional  

Latest revision as of 20:37, 26 June 2020

Author Tom Barry
Version v0.3.5.0
Download SimpleResize-
Category Resize
License GPLv2
Discussion Doom9 Thread


[edit] Description

SimpleResize is an AviSynth plugin with 4 resizing filters:

  • SimpleResize will do a very simple 2 tap linear interpolation. It is unfiltered which means it will not soften much.
  • WarpedResize will do a non-linear stretch/squeeze in both the horizontal and vertical dimensions. This can be useful when you want to change the aspect ratio of a video clip and have it mostly distorted at the top, bottom, and side edges. This is mostly experimental but I added it because it required few code changes and almost zero performance penalty. See the Examples section below.
  • InterlacedResize and InterlacedWarpedResize work like SimpleResize and WarpedResize but are designed to operate on interlaced source, without either blending even/odd data or messing up the coordinates because of the even/odd line offsets. Theoretically these can lose a small amount of vertical detail or confuse a subsequent deinterlace or IVTC function but so far in my own testing I have not found it to be a problem. So if you intend to keep your video in interlaced form, certainly use these. And if you are downsizing you may find that doing the InterlacedResize first before a more costly deinterlacing step can give you a small performance advantage on other material. But this is still experimental. YMMV.

[edit] Requirements

  • MMX capable CPU
    • It will run faster on SSE2 capable CPU's if the target width is a multiple of 8 pixels and if the data starts on an 8 pixel boundary. I don't know if prior Clip() commands affect this or not.

[edit] Syntax and Parameters

SimpleResize (clip, int, int)
InterlacedResize (clip, int, int)
WarpedResize (clip, int, int, float, float)
InterlacedWarpedResize (clip, int, int, float, float)

clip   =
Input clip.

int   =
int   =
width, height: target width and height.

float   =
float   =
hWarp, vWarp: horizontal and vertical warp factors. These are decimal number, usually between .8 and 1.3 that determine how non-linear you really want the output to be.
  • Values above 1.0 cause the output image to be stretched more in the middle and squeezed at the edges. Values below 1.0 will do the reverse.
  • Specifying 1.0 for either of them will do a linear resize in that dimension, just as you would get using SimpleResize.
  • Values far from 1.0 will give some very strange results. See the "Notes to Mathematicians" below.
One reason to use WarpedResize would be when you have a clip with a 16:9 aspect ratio and want to resize it for a 4:3 aspect ratio display without either clipping off valuable info or having to display black bars. (or vice versa).

  • Note: all parameters are unnamed and do not have a default so they must be specified.

[edit] Examples

[edit] SimpleResize

  • Assume you have a 1920x1080 clip that you want to resize to 1280x720.
SimpleResize(1280,720) # (width, height)

[edit] WarpedResize

  • An example image of using WarpedResize for this can be seen in WarpTest.jpg. This image was from a short HDTV digital capture that was at a 1280x720 resolution, a 16:9 aspect ratio. It was downsized and warped to a 640x480 4:3 aspect ratio using the following script command:
WarpedResize(640, 480, 1.15, 0.95) # (width, height, hWarp, vWarp)
  • Also, for an example of a 4:3 capture warped to fit on a 16:9 screen see WarpTest2.jpg.
  • There is a bug in WarpedResize with YV12 sources (fixed in v0.3.5.0) – see here ( for a report. Use the following script to work around the problem:
## fix WarpedResize YV12 chroma bug; make warp arguments optional 
function WarpedResize2(clip C, int width, int height, float "hWarp", float "vWarp")
    \   "WarpedResize2: source must be YV12")     
    Assert(width % 4 == 0, 
    \   "WarpedResize2: 'width' arg must be mod 4")
    Assert(height % 4 == 0, 
    \   "WarpedResize2: 'height' arg must be mod 4")
    hWarp = Default(hWarp, 1.0)
    vWarp = Default(vWarp, 1.0)
    U = C.UToY .WarpedResize(width / 2, height / 2, hWarp, vWarp)
    V = C.VToY .WarpedResize(width / 2, height / 2, hWarp, vWarp)
    Y = C      .WarpedResize(width, height, hWarp, vWarp)
    return YToUV(U, V, Y)
  • Squeezing aspect ratio: 21:9→16:9
Here is a comparison of adapting a widescreen image to a narrower target format, starting with Resize+AddBorders:
Sintel frm6291 aspect 1 letterbox.jpg
next, Crop:
Sintel frm6291 aspect 2 crop.jpg
and finally, WarpedResize:
Sintel frm6291 aspect 3 warp.jpg
(the numbers across the bottom have been added for illustration purposes)

generated with:

## source = 1690x720
Subtitle("9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9", 
\       align=2, size=Height*0.12, font="Courier New",
\       text_color=$99ffff00, halo_color=$ff000000)
WarpedResize2(1280, 720, hWarp=1.28) 

[edit] Notes to Mathematicians: (and questions)

Imagine the screen was dimensions that went from -1.0 to 1.0. We'll only consider the horizontal dimension for the moment and only the right hand half of the screen. Assume we want to calculate the value of an output pixel at location x, where 0 <= x <=1.

The output value will be the source value from the input screen with the same dimensions, at location s. Right now I'm just calculating s = (1-w) * x^3 + w * x, where w is the warp factor mentioned above (Later note: w = 2 - warp factor, for compat with first release). This gets the job done and produces smooth numbers from 0 to one, without too much distortion as long as w is close to 1.0.

The same formula is reflected for the left half of the screen.

The warp equations are designed to:

  • Always be rising but yield results from 0 to 1
  • Have a first derivative that doesn't go to 0 or infinity, at least close to the center of the screen
  • Have a curvature (absolute val of 2nd derivative) that is small in the center and smoothly rises towards the edges. We would like the curvature to be everywhere = 0 when the warp factor = 1

Now, as near as I can tell the curvature is more or less just the absolute value of the second derivative. So if we wanted the curvature to be small when x = 0 and to grow toward the edges, what could be a useful warp function? The above function already represents a change since V 0.1 but I'm still not so sure it's the best.

It is easy to drop in another warp function. And there is no performance penalty either way because it's just calculated and tabled at startup. After that it runs at the same speed as SimpleResize.

Anyone have any ideas? (Anybody care about this part?)

[edit] Changelog

Version       Date            Changes
v0.3.5.0 2020/06/17 - Changes by Asd-g - Fixed memory leak - Fixed WarpedResize YV12 processing v0.3.4.0 2020/05/18 - Changes by Asd-g - Update to AviSynth+'s v8 interface - x64 version: used the original source code and just replaced 32-bit registers with 64-bit registers - Compiled with MSVC 2019 (Clang 10), x86 and x64 build included v0.3.3.0 2003/01/16 - AviSynth 2.5 YV12 support, AvisynthPluginit2 v0.3.2.0 2002/09/16 - Fix horizontal chroma shift bug v0.3.1.0 2002/07/29 - Removed 4x horizontal pixel count requirement v0.3.0.0 2002/02/04 - Added InterlacedResize & InterlacedWarpedResize functions v0.2.0.0 2002/01/29 - Additional SSE2 & SSEMMX optimizitions, Better warp formula v0.1.0.0 2002/01/20 - Initial release

[edit] Archived Downloads

Version Download Mirror
v0.3.5.0 SimpleResize- SimpleResize-
v0.3.4.0 SimpleResize- SimpleResize-

[edit] External Links

Back to External Filters

Personal tools