26

I'm using VirtualDub for encoding with those settings. resize algorithms

However I record my stuff in 1920x1080 and resize it down to 1280x720. Now the question: which algorithm should I choose when making a balanced quality vs. file-size decision?

I always went with Lanczos because that's what was pre-configured. Those descriptions don't really help me at all in my question.

3 Answers 3

37

TL;DR

When sampling down: Use Lanczos or Spline filtering.

When sampling up: Use Bicubic or Lanczos filtering.

These are based on material I've read over the years, and from what I've seen used in the industry. The recommendations may vary depending on content type and application area.

Why does it matter?

It could be argued that the resizing filters don't matter that much when you downscale a video. More importantly, they have an impact on the quality when upscaling, because you need to generate data where there isn't in the first place.

These filters all have only a marginal impact on file size. You therefore shouldn't worry about huge differences there.

Fact is, as always when encoding video, that the result heavily depends on the source material. You can't always predict the result, but just see what works best for you.

Different algorithms

As an example, here's bicubic vs. bilinear interpolation:

     enter image description here

See that bicubic interpolation results in smoother edges? That's a very general statement … but you can find an overview of image scaling algorithms here.

  • Bilinear interpolation uses a 2x2 environment of a pixel and then takes the average of these pixels to interpolate the new value. It's not the best algorithm, but rather fast.

  • Bicubic interpolation uses a 4x4 environment of a pixel, weighing the innermost pixels higher, and then takes the average to interpolate the new value. It's – as far as I'm concerned – the most popular.

  • Area averaging uses a mapping of source and destination pixels, averaging the source pixels with regards to the fraction of destination pixels that are covered. According to this page, it should produce better results when downsampling.

  • Spline and sinc interpolation use higher-order polynomials and are therefore harder to compute than bicubic interpolation. I don't think the overall increase in processing time is worth using them.

  • Lanczos resampling involves a sinc filter as well. It is more computationally expensive but usually described as very high quality and can be used for up- and downsampling.

  • hqx as well as 2xSaI filters are used for pixel-art scaling (e.g. game emulators). I don't think there's a good reason for using them in video.

Jeff Atwood's comparison

It turns out Jeff Atwood did a comparison of image interpolation algorithms. His rule of thumb was to use bicubic interpolation for downsampling and bilinear interpolation when upsampling. That said, this is not what is typically recommended for video encoding – and some commenters have raised doubts about Atwood's expertise in the field.

However, he also mentioned that …

Reducing images is a completely safe and rational operation. You're simply reducing precision and resolution by discarding information. Make the image as small as you want, and you have complete fidelity-- within the bounds of the number of pixels you've allowed. You'll get good results no matter which algorithm you pick. (Well, unless you pick the nave Pixel Resize or Nearest Neighbor algorithms.)

Other examples

Here are some more examples of image interpolation algorithms, including the ones I mentioned above.

I also found documents (scene rules) from the video encoding scene that explicitly ban bicubic filtering for downsampling. Instead, they endorse Lanczos, Spline, or "Blackman" resampling.

12
  • 3
    FWIW I wouldn't consider Jeff Atwood an expert in image processing, and in that article he doesn't examine anything other than bilinear, nearest neighbour or (one particular variant of) bicubic. Most people would agree his recommendation to use bilinear when enlarging is a bad one. Commented Sep 26, 2015 at 3:39
  • 1
    @thomasrutter Thanks. I agree with you—back when I wrote this, I probably didn't know as much about image processing as I do now. I guess I'll remove the reference to that article and find some other source.
    – slhck
    Commented Sep 26, 2015 at 7:51
  • 1
    @Lex Scene rules seem to recommend spline 64 and 32. My recommendations are based on what folks in the video encoding and testing domain are using — and here, Lanczos is preferred. Most people aren't pixel peeping though, and there does not seem to be a strong interest in animated videos … Perhaps you could do a quick visual test and compare with svt.github.io/vivict?
    – slhck
    Commented May 17, 2022 at 18:26
  • 1
    @Lex There's github.com/svt/vivict (Node.js-based) and github.com/svt/vivictpp (C++-based) which both do the same thing. As for recommendations on filters, this is where my experience is limited (Bicubic/bilinear/default Lanczos has been fine for my work). I'd probably just run my own tests and look at the output. As for the ffmpeg implementation, I would have to check the source code. Same for Lanczos. Perhaps you could ask on the ffmpeg-devel mailing list or on video.stackexchange.com for details?
    – slhck
    Commented May 18, 2022 at 11:11
  • 1
    @Lex There is no prebuilt version, as the developers are using Linux. I found a similar tool here that seems to have Windows binaries though: github.com/pixop/video-compare
    – slhck
    Commented May 18, 2022 at 14:24
17

I found a good image that documents some of this.

enter image description here

Full size version here.

In general you want a mild sharpening effect when making a larger image into a smaller one, and a mild blurring effect when making a smaller image into a larger one. The MadVR filter set defaults to Lanczos for upscaling and bicubic for downscaling.

4

You are converting 3x3 original pixels to 2x2 target pixels.

If you want to keep sharp lines choose Lanczos or something that uses more surrounding pixels to not blur sharp lines (like fur or reflections)

Otherwise area average etc (also bilinear/trilinear) would suffice.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .