Resizing is a very complex topic. However, for simple downscaled encodes, one doesn't need to know very much information. As such, this page will only cover the necessities for downscaling. Those interested in knowing more about resampling should refer to the Irrational Encoding Wizardry's guide's resampling page for more information.

You can, however, check the later subchapters for some slightly more advanced topics such as descaling and rescaling or chroma resampling and shifting, both of which are absolute necessities to know about when encoding anime.

# Downscaling

For downscaling, the go-to resizer is a spline36 resizer:

resize = src.resize.Spline36(1280, 720, dither_type="error_diffusion")


The parameters here should be straightforward: simply adjust width and height as necessary. Don't worry about dither_type="error_diffusion" yet, simply leave this as-is; all it does is make for a nicer looking output. The explanation for this parameter can be found in the dithering chapter.

## Finding target dimensions

The desired dimensions for standard resolutions should be fairly known for 16:9 content: $$3840\times2160$$ for 2160p, $$1920\times1080$$ for 1080p, $$1280\times720$$ for 720p.

However, most films aren't made in this aspect ratio. A more common aspect ratio would be 2.39:1, where the video is in $$2048\times858$$. Consumer products are usually in the aforementioned resolutions, so it's more likely to see something like $$1920\times804$$ after black bars are cropped.

Going from this to 720p gets us exactly $$1280\times536$$:

\begin{align} w &= \frac{720}{1080}\times1920=1280 \\ h &= \frac{720}{1080}\times804 =536 \end{align}

However, this won't always be the case. Let's say your source is in $$1920\times806$$:

\begin{align} w &= \frac{720}{1080}\times1920=1280 \\ h &= \frac{720}{1080}\times806 =537.\overline{3} \end{align}

Obviously, we can't resize to $$537.\overline{3}$$, so we need to find the closest height with the lowest aspect ratio error. The solution here is to divide by two, round, then multiply by two again:

$h = \mathrm{round}\left( \frac{720}{1080} \times 806 \times \frac{1}{2} \right) \times 2 = 538$

In Python:

height = round(1280 / src.width / 2 * src.height) * 2


Now, we feed this to our resize:

resize = src.resize.Spline36(1280, height, dither_type="error_diffusion")


Alternatively, if our source was cropped on the left and right instead of top and bottom, we do:

width = round(720 / src.height / 2 * src.width) * 2


If you (understandably) don't want to bother with this, you can use the zresize wrapper in awsmfunc:

resize = awf.zresize(src, preset=720)


With the preset option, you don't have to bother calculating anything, just state the target resolution (in height) and it'll determine the correct dimensions for you.