Page 1 of 6 in Perceptual optimization
Block energy
You'll want firstQuantization and the quantization parameter (QP)
In Brief:
Block energy is the sum of squared deviations from a block's mean: zero for a constant block, larger with more contrast. Encoders can use it as a simple measure of how much a block varies.
Centered block energy measures how much the sample values in a block vary around their mean. It is the sum of squared deviations, so a constant block has zero energy and a higher-contrast block has more. Encoders can use it as a simple activity measure.
energy = Σ (pixel − mean)² = Σ pixel² − (Σ pixel)² / N
See it
Move the slider. The left block splits into a constant component, its mean, and the deviations from that mean. Energy is the sum of squares of the right-hand panel only. The last readout shows how a mode-1-style adaptive quantization (AQ) formula responds to this energy, as a quantization parameter (QP) offset. It is a teaching model, not a prediction of the QP x264 would give a real macroblock.
Block
Constant part
Deviations
above the mean below it. Stronger color is a larger deviation; gray is zero.
Standard deviation
Energy
log2(energy)
Illustrative AQ offset
aq-mode 1 formula to 64 luma samples by rescaling its reference energy, and floors the energy at 1 as x264 does. For the real calculation see Adaptive quantization in x264.What to take from it
- For a fixed sample count, energy and variance differ only by a constant factor. Divide energy by N to compare variation across block sizes. A uniform brightness shift leaves it unchanged: a flat white block and a flat black block both have zero energy. That is a property of the measure, not a claim that the eye is equally sensitive at every brightness.
- It equals a transform-domain sum. With an orthonormal discrete cosine transform (DCT), centered energy equals the sum of the squares of every coefficient except the constant one. So it can be computed straight from pixels, with no transform. Codec integer transforms need attention to their scaling.
- A logarithm turns multiplicative changes into additive ones. Doubling contrast multiplies energy by 4, which adds exactly 2 to log2(energy), and QP is itself a logarithmic scale: step size doubles every 6. At zero energy the logarithm is undefined, which is why formulas floor the energy first.
- It ignores arrangement. An edge and a noise pattern can have the same energy but differ in how well they hide a particular error. Activity-based AQ uses energy as a rough cue, not as a complete model of visibility.
Sources
Read 2026-11-13, at the commits linked.
- x264 at commit c24e06c (GitHub mirror):
ac_energy_mb, which measures a macroblock including chroma, the mode 1 formula and its floor at 1. - Not checked or cited: the statements about what the eye notices, which are general and were not taken from a source read for this page. The identity with transform coefficients is standard mathematics. The numbers in the demo are computed by the page itself.