Friday, May 23, 2008

Tipping the Lanczos Scale

What resolution is that PC screen of yours running?

No, I'm not trying to be rude or give you an inferiority complex, just make a point: ever watched a DVD or some crappy download, hit "fullscreen" and then recoiled at how awful the whole thing looks? Well, there's a multitude of factors that go into making a video file look good, but one of the most basic - that of upscaling - is one that whizzes by most people's notice. Effectively, you have a video file or image that's x number of pixels by y number of pixels, but you want to fill up your screen or zoom it in for some reason; when this happens, some scaling algorithm is used to multiply the pixels and "fill in the gaps" mathematically.

Outside of graphic artists, the concept of upscaling didn't mean crap to much of anybody until HDTVs - and also their cheaper, smaller equivalents, the high resolution desktop computer screen - started to sell in greater numbers. Hardware manufacturers started marketing upscaling DVD players that could "improve" the video quality dramatically compared to any NTSC or PAL output when coupled with an upscaled progressive output via DVI or HDMI, which promise to convert the SD signal to HD resolutions. Sound too good to be true? Well... it really is. See, modern HD monitors, LCD, DLP, pretty much anything that isn't a big honkin' CRT monitor, are by their nature a fixed resolution display. In my case, I have a 1680x1050 monitor. I can feed it a smaller or larger resolution, but the hardware in the monitor itself will simply scale the signal to 1680x1050. If it didn't, and I were to feed it a 720x480 DVD, I'd get a picture that literally only filled roughly 20% of the screen. Since virtually no monitor will do this without specific instructions to do so, it means that every single HD monitor on the market has a built in scaling algorithm and "improves" SD signals to the monitor's HD resolution anyway.

At face value, upscalers all do a relatively decent job at what they do. If they didn't, they wouldn't bother making the chipsets that performed the algorithms. Unfortunately, there's no magical chip that'll make a 480p DVD equal a 1080p Blu-Ray, because you can't replicate 6x the resolution from scaling alone. What scaling does is averages the pixels, and tries to guess what pixels "should" be between them at higher resolutions. A sharper scaling algorithm usually does this by adding more ringing or halos to the signal, which trick the eye into seeing detail when really it's basically more random noise. A softer algorithm won't look very sharp or impressive, but may be a closer representation of what the original low resolution signal looked like. Of course, you can't please everyone with the same algorithm, but somewhere along the line, HTPC users found a way to pick whatever it was they liked about upscaling and push it as far as they could.

FFDShow is, for all intents and purposes, a video codec pack that replaces your MPEG-4 (DivX/XviD) codec, MKV splitters, WMV decoders, and any other third party piece you have to use to decode any given video file. You can download it here, if you want to give it a try, just make sure when you open it to set "Raw Video" to "All" under the codecs tab. To check if it worked, open up a video file and see if a "FFv" icon appears in your taskbar. If you did, then congrats, you can now use FFDShow for all sorts of awesome things! Also, Media Player 8+ sucks balls. Just use the third party edit, Media Player Classic, here. After you've installed both of them, go into MPC's "Options", and on the "External Filters" tree, add "FFDShow Video Decoder" and set the priority to "Prefer". After doing this, damn near anything you play with MPC should go direct to FFDShow. You can also add the FFDShow Audio Decoder, but that's another can of worms I'm not going to touch for right now.

As an aside: VLC Media Player cannot use FFDShow. If you're already using VLC Player... well, frankly you probably already know where I'm heading with this, so just skip reading all of this crap and lulz at the attached picture below. If you'd stay with it despite knowing well enough to go beyond PowerDVD, you probably have your reasons.

Still with me? Okay... while watching a video, double click that FFv icon on your taskbar. There's a bajillion options, with one of my personal favorites being the option to add artificial film scratches, grain, and dirt under the "Noise" tab...

Hey, don't judge me 'till you've watched a grindhouse showing of Grand Theft Anal 10 and Throat Gaggers 14. It's a double feature and everything.

In all seriousness though, there's a lot of awesome things you can make FFDSHow do for you, and - most importantly - your DVDs. Yes, it also works with DivX and MKV downloads, and yes, I know you have plenty of them. Unfortunately, DivX... how to put this nicely... looks like festering shite? No, not quite, but you get the message. FFDShow does improve performance on MPEG-4 video pretty drastically, but the real reason it's become the HTPC darling that it is, without a doubt, is for its' high quality scaling algorithms. Bicubic, Lanczos, Spline - all very effective tools for making a sharp real-time upscale, if you have the CPU horsepower to back it all up.

The most popular method for DVD playback is more or less the following - keep in mind that you can actually move the check-boxes for these options up and down to your liking, with the first process being the top and working their way down...

AVISYNTH - Everyone's favorite professional video freeware editor, now in real time!

POSTPROCESSING - Let FFDShow automatically fix compression artifacts.

BLUR & NR - Use "Denoise 3D" and other options to get rid of video noise.

RESIZE & ASPECT - Select your resolution, algorithm, and additional sharpening.

Sounds like the perfect crime, doesn't it? Well... it is and isn't. See, the big issue I have with this concept is the inclusion of the Blur & NR tab. DVDs are compressed, and thus have compression artifacts. I can't argue that. The idea here is that if you use the DeNoise3D setting in low incriments (say 1.0,0,4.0 even) you'll smooth out the compression noise hiding in the chroma (color) channel, without actually smearing out any detail in the luma (gray scale) channel. If this we're true, it'd be the perfect... but chroma contains valid color information, including natural film grain and the like, so even on the above setting, if you're prone to temporal NR smearing you're doing more harm to most DVDs than good. While DivX looks like shit no matter what you do, and smearing its' fine detail out isn't going to disturb much, the majority of DVDs on the market are... well, maybe not spectacular, but they still have more detail than they do noise.

Applying NR - even after the upscale - is also kinda' redundant, if we consider that DVDs are already heavily compressed, and thus smoothed out plenty of "noise" before you ever saw it! Softening and then sharpening has a logical argument if you haven't already compressed the hell out of the video, but really, softening an already heavily softened consumer release is nothing short of pants on head retardation.

So, how well does that scaling bullshit work, anyway?

CLAMP's Clover music video R2 DVD single. These lossless PNGs are because I love you.

On the top, BICUBIC, on the bottom, LANCZOS (3 taps), with zero settings changed aside from 'accurate rounding' checked. There's no artificial sharpening at work here aside from Lanczos doing its' thing. Both were set to 1280x720 (and cropped for ease of comparison/bandwidth saving), and rendered in real time with a Pentium 4, 3.4 ghz CPU. I went with Bicubic as a starting point because it's the best resize function built into WMV9 Render, and as is probably similar to the scaling method that overlay settings use on a less than Godly video card during overlay mode. It's considered a decent scaling algorithm by most, but Lanczos is probably the de-facto reason to bother fiddling with FFDShow in the first place.

The first thing that jumps out and cock-slaps me is the fact that Bicubic gets very blocky around the facial and hair outlines. The irises are much smoother and less pixelated on the Lanczos scale. Also check out the hand painted details in the background: what looks like a fuzzy mess in Bicubic looks hand painted and textured with Lanczos. The nose is again sharper on Lanczos, and probably the nicest thing is that they both have roughly the same amount of ringing - a natural side-effect of upscaling, but something present on pretty much every DVD on the market to begin with. You could sharpen the living hell out of this even further, but when you start doing it with EE or even the built in sharpness controls, all you're really doing is adding EE. And EE is bad.

The only downside is that Lanczos has produced a slightly noisier image, with noise around the earing and eyelashes even easier to spot with all that lovely sharpening going on. This is, unfortunately, the sacrifice you make my sharpening video. Personally I'd rather see a little bit of noise, even compression artifacts, if it means I can maximize the crisp look of the picture overall. If you don't like seeing that much detail, FFDShow even has blurring options as part of the upscale, and you bet softening out the chroma will help alleviate some noise. Personally I like noise, as it usually represents stuff that was more or less squeezed out of the master to begin with, but I'm trying to encourage you all to play with the settings, so I'll leave it at that. The last thing I need is someone going "Kentai, your settings look like ass! Shut the fuck up and go back to showing us porn! And make me a sammich, bitch." or whatever.

Upping the taps in Lanczos will mathematically produce a sharper image, but I'll be honest in saying that the returns after 3 taps are totally negligible and really just eat up additional CPU cycles in terms of performance. If you have a quad core beast and want to go for 10 taps, by all means, give it a shot. There's also SPLINE, hands down the greatest upscaling algorithm ever designed in performance to CPU cycle ratio: it actually produces crisper results than even a 4 tap Lanczos scale, and manages to do so without producing as much noise. I do not know how the hell it does it, but man, it is awesome, and you all will see it in action one of these days via a future Kentai Films DVD release, I promise. Unfortunately, my 3.4 ghz psuedo-dual core can't keep up, so I'm keeping at a 720p scale with Lanczos until I upgrade... which likely won't be any time soon.

Hopefully this public service announcement for the FFDShow IS the Shiz foundation has been an enlightening and entertaining experience. Remember, you're not an anal retentive and hopeless weirdo, as long as you turn out to be right in the end.

No comments: