libheif icon indicating copy to clipboard operation
libheif copied to clipboard

x265: don't apply tune by default

Open 0n-s opened this issue 1 year ago • 2 comments

x265 tunes are intended for specific types of content or objectives (e.g. the specific characteristics of animations or better scores on metrics). They are not general purpose & should only be explicitly applied by the user. The only sane default tune is no tune.

In particular, the ssim tune libheif defaults to completely disables psychovisual RD which harms perceptual fidelity in favor of better SSIM scores.

0n-s avatar Dec 14 '24 08:12 0n-s

Like my other comment (on #1424), do you have metrics on single image vs image sequence? It might (or might not) be a breaking change to adjust defaults at the library level, but we could provide alternative tuning suggestions in documentation or in the example applications.

bradh avatar Dec 14 '24 23:12 bradh

Frankly, I find it preposterous that the burden of proof is on me to show that the default settings of x265 are generally better than the almost certainly mindless, or at least misguided, non-default x265 tuning of libheif (please do not impulsively reply to this characterization before reading the quote at the very end of my comment). But it's easy enough, so here's 2 samples (video & still). I didn't do it with libheif since I can't figure out how to disable the tune parameter entirely there, so it's all with FFmpeg, plus additional parameters to match libheif's other settings. The only difference is the lack of a container format, really.

Here's a sample of ParkJoy (available here). In order: -tune ssim, & without -tune ssim; all other parameters are equivalent.

https://github.com/user-attachments/assets/9b0f61c4-1880-4a9d-ba4a-bad437e53c3a

https://github.com/user-attachments/assets/555848be-1bda-4522-9d0b-38539e11b472

Notice the bark of the trees in the foreground, the grass, & the trees in the background, which all look much more blurry with -tune ssim.

Sizes for these:

1788K normal.h265
1764K ssim.h265

I tried to match the bitrate as much as I could for those.

Here's 10164842933.jpg from the KonIQ-10k IQA database, decoded to PNG. Again, first -tune ssim, then without -tune ssim, but all other settings are the same.

ssim normal

Here, notice the bottom left, & the bottom right, both of which are lower quality & smoothed out with -tune ssim.

Sizes for these:

104K normal.h265
 96K ssim.h265

This was encoded a bit differently from the above because instead of trying to match bitrates, I tried to match quality (as in -q to heif-enc).

These results are to be expected, really. I mentioned in the OP that the only sane default tune is no tune, & that's not my specific opinion, that's just the conclusion one comes to from x265's docs on them:

The psnr and ssim tune options disable all optimizations that sacrafice metric scores for perceived visual quality (also known as psycho-visual optimizations). By default x265 always tunes for highest perceived visual quality but if one intends to measure an encode using PSNR or SSIM for the purpose of benchmarking, we highly recommend you configure x265 to tune for that particular metric.

0n-s avatar Dec 15 '24 14:12 0n-s