Log in

View Full Version : x264 deblock


mindbomb
23rd November 2011, 20:07
what is a good rule of thumb for x264 deblock settings?

before someone refers me to mp4guy's five year old thread, I'm under the impression that a lot of the deblocking stuff has been overhauled since then, and I am not sure if it is still valid now.

There seems to be 2 schools of thought on it, one that is very conservative, saying you should stick close to 0 0, moving only to -1 -1 if there is a lot of grain because x264 has a really spot on deblock system. The other school of thought seems to be that you should generally use very negative values to give the impression of higher quality, like -3 -3 and -2 -2, because x264's baseline deblock setting is way too high. These 2 views are fundamentally at odds. I feel the latter is more popular.

I'm wondering which is school of thought is more accurate given a technical understanding of how x264 works.

And does resolution and bitrate also factor into this? I'm thinking that with 480p video, you are more likely to be able to see blocks so a more positive value closer to 0 0 is desired. Is this true?

Thanks.

LoRd_MuldeR
23rd November 2011, 21:26
I suggest to have a look at the x264's tuning system:

It uses -1:-1 for "film", 1:1 for "animation" and -2:-2 for "grain". That should be good starting point for your own experiment, depending on the nature of your source. -3:-3 sounds a bit aggressive to me.

Also keep in mind that the H.264 deblocking filter is adaptive anyway. If you spend enough bitrate, there is less work for the deblocking filter to do...

(About resolution: "low resolution" video generelly is more sensitive to compression artifacts than "HD" video, because the artifacts get "amplified" when the video is upscaled to fill the screen)

Thunderbolt8
23rd November 2011, 22:52
hm how is -3 -3 more aggressive than -2 -2 or -1 -1? doesnt the lower number mean lower deblocking strength so less attempts to use deblocking?

LoRd_MuldeR
23rd November 2011, 23:04
hm how is -3 -3 more aggressive than -2 -2 or -1 -1? doesnt the lower number mean lower deblocking strength so less attempts to use deblocking?

I mean that it is a rather "aggressive" attempt to improve sharpness/details at the cost of blockyness.

mindbomb
24th November 2011, 00:22
I'm totally with you Lord Mulder.
I asked a few people about their thoughts beforehand, and independently, all of them thought -3 -3 was the best and synonymous with high quality.
I was taken aback by this, since I don't believe I've ever read anything that indicated to do this, and decided to make this thread.

*.mp4 guy
24th November 2011, 05:38
I believe a small history lesson is in order.

Before aq or other psy ops were implemented in x264, default settings lead to a very very plastic, denoised look. One of the first and most successful workarounds was lowering alpha and beta deblocking, -3:-3 became popular because it was the lowest deblocking could generally be set without getting blocks everywhere. Additionally many (all) cqm's block less then the flat matrix, which makes the default deblocking settings wasteful (deblocking blocks that aren't there is bad) so "back in the day" it became common practice to lower deblocking as far as you could.

Counter-intuitively aq and psy-rd etc. lower the need for messing with deblocking, since h.264 deblocking is adaptive. The areas that were comonly muddied up by deblocking are often encoded at quantization levels where deblocking no-longer activates, additionally the "detail" preserved by psy heuristics combats the blurring produced by deblocking.

There are other aspects of the story, such as deadzones and the way x264 models rate-distortion curves in relation to cqm's, but I don't care to editorialize all of the developments. IIRC there are a few threads that show the discussions with people on all sides of every issue, the strength of certain consensus that still exist speaks volumes about the realities of the situation when the debates originally occurred. One of the reasons that people probably still stick with some of the old advice is because of the huge amount of spurious opposition that it encountered when it was originally formed, which casts all future opposition to IE lowered deblocking in a bad light.

Currently I wouldn't suggest altering deblock settings from default unless you encounter a specific problem, IE you need low bitrate grain retention (its a bad idea imo, but some people want it).

mindbomb
24th November 2011, 11:04
Thanks for that great post mp4guy.

cyberbeing
25th November 2011, 06:32
The heat map from the following page may also be of interest:

http://www.birds-are-nice.me/programming/ponymath.shtml

It shows the effect of deblock values on SSIM with an ultra low bitrate anime encode.

The top 9 ranked values were as follows (top to bottom):

deblock -3:-1
deblock -3:2
deblock -3:0
deblock -3:1
deblock -1:0
deblock -2:-2
deblock -2:0
deblock -3:-3 | deblock -2:-3

Ranked dead last in 36th place was --deblock 2:1

Just keep in mind that SSIM alone says nothing about how it actually looked perceptually, but interesting none the less considering the negative value bias and the default value of --tune animation (--deblock 1:1) ranking near the bottom.

Dark Shikari
25th November 2011, 07:58
SSIM doesn't take into account visual energy, which is exactly what deblocking mainly affects (from a psy perspective).

gyth
25th November 2011, 15:11
Have you considered augmenting SSIM to account for visual energy?
Is that something that would be possible/useful?

mindbomb
25th November 2011, 16:19
dark shikari, im curious to know what you recommend for deblock settings?

you did a lot of work on x264's deblock filter, right?

Dark Shikari
25th November 2011, 19:22
dark shikari, im curious to know what you recommend for deblock settings?

you did a lot of work on x264's deblock filter, right?The deblocking filter is defined by the spec. "Working on it" means, at most, making it go fast.

There have been rigorous visual tests of the deblocking filter: one I recall showed a bimodal distribution, with the majority of viewers in a Gaussian distribution centered around 0,0, and a significant minority preferring no deblocking. However, this is probably not too relevant to x264, as the reason "no deblock" can look better is it can help fake sharpness in a blurry encoder.

All else equal, I don't think it matters too much.

Have you considered augmenting SSIM to account for visual energy?
Is that something that would be possible/useful?

This is what psy-RD is, but it's a hack.

mindbomb
28th November 2011, 03:17
http://www.mediafire.com/?er1rh5a38vc1x

So here there are 3 files, the original ts, and 2 encodes, one with -3 -3 and one with 0 0 deblock.

I think the greater deblocking strength helps make parts of the video look more constant rather than flickering, but I've been looking at these too long, I don't even know anymore.

cyberbeing
28th November 2011, 12:40
The -3:-3 encode looks better to my eyes since it's ever so slightly sharper with better grain retention from the source (what you are seeing as flickering), and it appears the areas of complexity are getting a lower quantizier (higher bitrate). The 0:0 encode seems to be giving more bitrate than needed to flat areas, since the areas of complexity were slightly blurred by deblocking. Your bitrate is high enough with these nearly static scenes, that there isn't much blocking to begin with.

mindbomb
28th November 2011, 18:08
well, if that is true, i am seriously confused.
That wasn't even a film, it was shot digitally, so I don't think it even qualifies for the -1 -1 of tune film.

LoRd_MuldeR
28th November 2011, 18:20
See the remark here:
http://forum.doom9.org/showpost.php?p=1346193&postcount=2

cyberbeing
28th November 2011, 18:29
It's better to think of --tune film as the 'content with similar properties to live-action movies' setting, rather than literally film. Lower deblock and higher psy-trellis helps with detail retention/sharpness.

It's not uncommon for --tune film to yield good results on detailed anime sources as well. Remember that the tune settings are just there for simplicity, not to act as absolutes.

mindbomb
28th November 2011, 21:33
to me, the lowered deblocking strength and higher psy trellis seem to be features that would help with the grainy look of films, and i guess CG too cause of that post.

If it were to help almost everything, why wouldn't it just be used by default?

nibus
28th November 2011, 23:28
http://www.mediafire.com/?er1rh5a38vc1x

So here there are 3 files, the original ts, and 2 encodes, one with -3 -3 and one with 0 0 deblock.

I think the greater deblocking strength helps make parts of the video look more constant rather than flickering, but I've been looking at these too long, I don't even know anymore.

The -3 encode does seem slightly more detailed in some areas, especially the falling debris. But it's pretty close. You might notice it more on HD content.

Marin85
29th November 2011, 00:03
If it were to help almost everything, why wouldn't it just be used by default?
I don't think it is meant to "help almost everything", it has merely suggestive character. There are for instance movies like Avatar where you will not get away with only (-1,-1) at some scenes, no matter what you do. As for the whole psy stuff (and by this I mean psy trellis and psy rdo), I am sure there are people who are not big fans of it. One of the reasons is because it tends to introduce artifacts - a common one is part of the eyebrow being separated from the eyebrow, which is ridicolous by itself. It does not happen that often and it is probably barely noticeable, but I think some encoders would be annoyed by that fact if they spot such a thing on their encodes. IMHO, one could safely replace psy-trellis by some slight non-linear sharpening in avisynth.

PS: still nuking whales? :p

mindbomb
29th November 2011, 00:39
so, i feel like this thread has come full circle.

What exactly would be the rule of thumb?

use tune film most of the time?
stick close to the defaults?
stick close to -3 -3, the weakest of the most reasonable deblocking strength choices?

I thought the default deblock made the right cheek look a little better in that clip btw, with as I said before, a more stable look to it.

Asmodian
29th November 2011, 02:38
My rule of thumb is to just use --tune to set deblock. :p

I have noticed when trying to compare encode settings that I can get myself trained to notice any particular artifact. What I mean is that if I notice an artifact and start playing with settings to improve it and then come back later I will often see a new artifact that my change in settings made worse but I didn't notice because I was fixated on the first one.

This gets really hard over an entire movie as you often improve one scene at the expense of another. I think closely studying still frames often does more harm than good - that isn't how you actually watch the movie and the artifacts that stand out in stills are not necessarily the same ones that stand out during normal watching.

mindbomb
29th November 2011, 03:42
yea, i think I will start doing that seeing as the tune presets are widely recommended.

Just one last question, to return to what was brought up before, when to use tune film?

ie, do movies that are shot digitally benefit from tune film?

if so, then when not to use tune film? just outside animation?

Asmodian
29th November 2011, 05:13
I use tune film on most real world video, if it is a softer or low detail source I might not tune.

I usually encode at a low crf (17-19), at different bit rates and sources your mileage may vary. ;)

nm
29th November 2011, 13:05
if so, then when not to use tune film? just outside animation?

If you have a grainy/noisy source and want to keep all the noise, use --tune grain. If you have clean cel animation, use --tune animation. In other cases --tune film is usually the right choice. Even for Pixar-style CGI animation.

mindbomb
29th November 2011, 22:24
also, on that point, the tune setting should not be used at low bitrates, correct?
and if so, what defines a low bitrate?
specifically wondering about the case for 480p.

asarian
28th August 2014, 20:04
So, does x264, ran with lossles -QP 0, do deblocking too? Cuz I'm looking at my intermediate source (which still has 50 hours to go), and it's quite, quite blocky still.

Or is deblocking with -QP 0 disabled altogether?

foxyshadis
28th August 2014, 22:52
Deblocking is generally disabled with qp below 4-8, depending on your deblock settings. It's always disabled for qp 0 and lossless. (Not the same thing, you have to use --lossless for full lossless.)

If you're seeing blockiness with qp 0 then your source is to blame, because there's no way x264 can add blocking artifacts at that point.

vivan
28th August 2014, 22:59
It's always disabled for qp 0 and lossless. (Not the same thing, you have to use --lossless for full lossless.)x264 doesn't have --lossless option and --qp 0 is lossless.
You're probably talking about x265 (which has --lossless option and --qp 0 there is not lossess).

foxyshadis
28th August 2014, 23:05
Whoops, yep, I'm an idiot.

asarian
29th August 2014, 02:14
If you're seeing blockiness with qp 0 then your source is to blame, because there's no way x264 can add blocking artifacts at that point.

Thanks! :) Kinda makes sense too, come to think of it (else it wouldn't be lossless).

F J Walter
4th September 2014, 08:00
There's a fair bit of misinformation around about what the deblock parameters actually do. After studying the source and reading a paper about the h.264 deblocking, I can tell you some things that aren't true:

- Many claim that the alpha and beta parameter are a *strength* and a *threshold*. This is not true. Simply speaking, they are both thresholds, which act on the deblocking algorithm in different ways. To put it more accurately, however, these parameters don't affect the thresholds directly by instead provide an *offset* to the QP (quantization) value used when calculating an appropriate threshold based on the QP. Every +1 is actually *two* QP: A +1 offset picks thresholds as if the QP was 2 higher, a +3 offset picks thresholds as if the QP was 6 higher.

- There is no such thing as "increasing or decreasing the deblocking strength" with this parameter. Instead, you are tweaking the in-built algorithm which decides whether a sharp edge is an unwanted artefact, or if it's a wanted detail. This does have the side effect of shifting the bias between smoothing fewer unwanted edges vs smoothing more details you don't want smoothed.

Internally, picking deblocking thresholds is playing a game of "hmmmm how much do you reckon this is a real edge and how much do you reckon this is blocking caused by low quality encode". You can never be correct 100% of the time, you can only make an educated guess. The default (0,0) is tuned (based on various assumptions made in the development of h.264) to the best possible guess, statistically, for a wide range of video content and self-adjusts according to QP for each block. Adjusting from the default (0,0) just adds a bias to this self-adjustment. This WILL make the guesses less accurate as an overall rule, but shifts the bias between different problems: too many true edges wrongly detected as blocks, and not enough blocks detected. If you decide that wrongly filtering an edge that isn't a block is a lot worse than not filtering an edge that is a block, then you can bias the deblocking thresholds such that it's more likely to err towards thinking something is a true edge rather than a block. This is essentially what lowering the alpha adjustment does: it increases the chance of any given block being missed by the block detection and thus skipping filtering.

Decreasing ALPHA decreases the chance a given edge will be determined to be an unwanted artifact, based on how sharp the edge is at the border of the block, and thus leaves more edges.
Decrease BETA decreases the chance a given edge will be determined to be an unwanted artifact, based on how variation exists inside the block away from the boundary - if it's flatter inside the block then the edge is more likely to be an unwanted artifact - and thus leaves more edges where there is noise/detail inside the block.