Deblocking and boundary strength
Each block is transformed and quantized on its own, so two neighboring blocks can come back with different errors. Where they meet, the difference shows as a small step along the block grid. A deblocking filter smooths across a block edge when the step there looks like such an artifact, and leaves it alone when it looks like part of the picture.
Artifact or edge?
The filter never sees the source, so it has to judge from what the decoder has too. First, how the two blocks were coded gives the edge a boundary strength (bS): whether it may be filtered at all, and with which filter. Then the reconstructed pixels decide, line by line. One line of pixels crosses the edge: p0 and q0 touch the edge, p1 and q1 are the next ones out. In H.264's filter, as x264 implements it, a line is changed only if it passes three tests:
|p0 - q0| < alpha |p1 - p0| < beta |q1 - q0| < beta
A small step between two smooth sides passes: quantization could have made it. A large step fails the first test, and a busy side fails one of the others. Both thresholds come from tables indexed by the quantization parameter (QP), and they rise with it, because a coarser quantizer leaves larger steps.
Try it on the cat
The cat is coded in 4×4 blocks at the quantizer step that QP nominally stands for, then filtered. Boundary strength is fixed, not on a slider: the picture is four intra macroblocks, so the 16-pixel edges between them have strength 4 and the 4×4 edges inside them strength 3. QP sets the quantizer and, through the tables, the thresholds. Both offsets sets the two offsets of x264's --deblock option to one value: each unit moves both table indexes by 2, and the alpha index also selects the normal filter's clipping limit. Error is the mean squared error against the source, in squared 8-bit levels: the average of the squared pixel differences, zero when the pictures are identical. The Changed panel marks in teal every pixel the filter altered.
common/deblock.c at the commit under Sources, for luma only. The picture is treated as four intra macroblocks: the 16-pixel macroblock edges get the strong filter and the 4×4 edges inside them get the normal filter at strength 3. Block edges are drawn only on the Changed panel (macroblock edges heavier), so any grid in the other panels is in the pixels. Mean squared error does not measure how visible the grid is.For this cat:
- At QP 34 with both offsets at 0, the filter changed 331 of the 1,024 pixels, and the error fell from 42.50 to 39.41. The filter was not given the source; many of the steps it smoothed were errors.
- Filtering more did not always bring the picture closer to the source. At QP 34 the lowest error was with both offsets at +1 (38.99). At +6 the filter changed 444 pixels and raised the error to 44.93, above the unfiltered 42.50. At −6 it changed 47 pixels and left the error at 42.41.
- At QP 16 with both offsets at 0, the filter changed 59 pixels and the error rose slightly, from 1.03 to 1.05. The thresholds there are 4 and 2. Both tables are zero below index 16, and a zero threshold switches the filter off.
Boundary strength in x264
The demo held fixed how the two blocks were coded, which says how likely an edge is to hold an artifact. x264 gives each 4-pixel piece of an edge a boundary strength from 0 to 4. For progressive video and the luma filters, the first row that applies is the one used; the demo reaches only the top two:
| bS | When | Filter |
|---|---|---|
| 4 | Macroblock edge, either side intra | Strong |
| 3 | Edge inside an intra macroblock | Normal |
| 2 | Either block has nonzero levels | Normal |
| 1 | Different reference frames or motion | Normal |
| 0 | None of these | None |
"Different motion" means the two motion vectors differ by a full pixel or more horizontally (the vertical limit is a parameter). Strengths 1 to 3 share the normal filter and differ in a clipping limit, read from a third table by strength and index: p0 and q0 may move by at most that limit, plus one for each side that is itself smooth. The strong filter has no such limit and can rewrite three pixels on each side.
The settings
- x264
--deblock alpha:betasets the two offsets, each from −6 to 6, default 0:0; one number sets both.--no-deblockturns the filter off. The film and touhou tunings use −1:−1, grain −2:−2, stillimage −3:−3 and animation 1:1. The ultrafast preset and the fastdecode tuning turn it off. - x265
--deblock tC:betatakes two offsets in the same range, default 0:0, and--no-deblockturns its filter off. Its animation tuning uses 1:1.
Trade-offs
- The filter can smooth real low-contrast detail. Fine texture whose steps fall under the thresholds at a block edge is treated like an artifact. Negative offsets leave more of it alone, which is the direction x264's film and grain tunings take.
- The decoder must run the same filter. x264 writes the two offsets into the slice header, and the filtered frame is the one both sides keep as a reference, as Why the encoder contains a decoder showed. What that does to prediction is the subject of Why filtering inside the loop helps prediction.
Sources
Read 2026-11-15, at the commits linked.
- x264 at commit c24e06c (GitHub mirror): in
common/deblock.c, the alpha table, the beta table, the clipping table,deblock_edge_luma_cwith its three tests and the clipped change to p0 and q0, the strong filter,deblock_strength_c(strength 2, strength 1, strength 0), the table index, QP plus offset, the clipping limit read at the alpha index and the zero-threshold exit, the averaged QP at a macroblock edge and the strong filter chosen there, edges skipped with the 8×8 transform; strength 3 inside an intra macroblock; inencoder/encoder.c, the filter switched off for a slice at low QP, each offset doubled, the offsets written to the slice header, the range −6 to 6 and the call that filters a finished row; incommon/base.c, the defaults,--deblockwith one number setting both,--no-deblock, the tunings film, animation, grain, stillimage, touhou, fastdecode and the ultrafast preset; both options in the command-line list. - x265 at commit 4191822, options only: the filter on by default and the offsets starting at zero,
--deblock, the range, the animation tuning, the fast-decode tuning turning it off and both options in the command-line list. - Not checked: the H.264 specification text for the filter (the page describes x264's code); chroma filtering, interlaced coding and the vertical motion limit; x265's filter and the deblocking filter in AV1; how visible the grid is with and without the filter, which this demo does not measure.