Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

Domains: forum.doom9.org / forum.doom9.net / forum.doom9.se

 

Go Back   Doom9's Forum > General > Newbies

Reply
 
Thread Tools Search this Thread Display Modes
Old 8th November 2025, 21:57   #1  |  Link
Lan4
Registered User
 
Join Date: Dec 2022
Posts: 74
Where can I read more about AQ?

Where can I read more about AQ and its modes in the X264 codec?
Lan4 is offline   Reply With Quote
Old 9th November 2025, 06:57   #2  |  Link
microchip8
ffx264/ffhevc author
 
microchip8's Avatar
 
Join Date: May 2007
Location: /dev/video0
Posts: 2,034
http://www.chaneru.com/Roku/HLS/X264_Settings.htm

and for x265 - https://x265.readthedocs.io/en/master/cli.html
microchip8 is offline   Reply With Quote
Old 9th November 2025, 16:17   #3  |  Link
Lan4
Registered User
 
Join Date: Dec 2022
Posts: 74
Thanks for the reply, but the links don't provide a detailed description of AQ's functions. In fact, there's no description at all, just a list of functions.
Lan4 is offline   Reply With Quote
Old 9th November 2025, 17:04   #4  |  Link
microchip8
ffx264/ffhevc author
 
microchip8's Avatar
 
Join Date: May 2007
Location: /dev/video0
Posts: 2,034
I could be wrong, but I don't think there's extensive description on how each AQ mode works. Read the code?
microchip8 is offline   Reply With Quote
Old 9th November 2025, 18:10   #5  |  Link
Selur
.
 
Selur's Avatar
 
Join Date: Oct 2001
Location: Germany
Posts: 7,853
https://mailman.videolan.org/piperma...ly/009403.html
https://huyunf.github.io/blogs/2017/...daptive_quant/
might be interesting
__________________
Hybrid here in the forum, homepage, its own forum
Selur is offline   Reply With Quote
Old 9th November 2025, 18:35   #6  |  Link
microchip8
ffx264/ffhevc author
 
microchip8's Avatar
 
Join Date: May 2007
Location: /dev/video0
Posts: 2,034
Good find, Selur! Especially second link!
microchip8 is offline   Reply With Quote
Old 9th November 2025, 20:23   #7  |  Link
Lan4
Registered User
 
Join Date: Dec 2022
Posts: 74
Selur: Thanks for the original data.
I still have doubts about how AQ works, because other descriptions have given different information. I'll share my thoughts. By default, the quantizer transfers data too strongly from monotonic regions to complex regions. AQ constrains this data transfer. Therefore, if there are few monotonic regions, weak AQ constraint is required, and therefore the AQ strength should be set to a small value less than 1. If there are many monotonic regions, strong AQ constraint is required, and therefore a large AQ strength greater than 1 should be set.
AQ mode=2 is two-step constraint, for more accurate work, in short.
Is this correct, or can you correct me?
Lan4 is offline   Reply With Quote
Old 14th November 2025, 05:42   #8  |  Link
hello_hello
Registered User
 
Join Date: Mar 2011
Posts: 5,062
The x264 Animation preset sets AQ strength to 0.6 by default.
For the Grain tuning it's 0.5.
For the Film tuning (or no tuning) it's 1.0.
For the Still Image tuning it's 1.2.

Based on that, and the explanation on the x264 wiki, I've always understood that when there's less variation in detail throughout the picture, the AQ strength can be lower than when there's a lot of variation.

http://www.chaneru.com/Roku/HLS/X264...tm#aq-strength
Adaptive Quantization Strength
Default: 1.0
Sets the strength of AQ bias towards low detail ('flat') macroblocks.


I vaguely remember playing around with the AQ strength for animation years ago and deciding to keep it at 1.0, because if I remember correctly, there was more likely to be banding in gradients when using lower AQ strengths. The background in this image is the sort of thing I'm referring to.

hello_hello is offline   Reply With Quote
Old 16th November 2025, 09:21   #9  |  Link
GeoffreyA
Donor
 
Join Date: Jun 2024
Location: South Africa
Posts: 659
I stand to be corrected, but AQ does at the frame level what DCT and quantisation do within a macroblock. As DCT groups coefficients by low and high frequencies, quantisation reducing the latter more aggressively, AQ redistributes bits from more complex (HF) macroblocks to flatter (LF) ones by lowering quantisers, in inverse proportion to AQ strength. In other words, the frame-level quantiser varies according to each macroblock's detail. Since the frame's budget is constrained, increasing the quality of one region lowers that of others.

AQ mode 3 performs this bias towards dark as well as flatter blocks.
GeoffreyA is offline   Reply With Quote
Old 16th November 2025, 12:27   #10  |  Link
Z2697
Registered User
 
Join Date: Aug 2024
Location: Between my two ears
Posts: 940
Quote:
Originally Posted by Lan4 View Post
I still have doubts about how AQ works, because other descriptions have given different information.
Let's not forget higher QP = lower quality
Z2697 is offline   Reply With Quote
Old 16th November 2025, 12:31   #11  |  Link
Z2697
Registered User
 
Join Date: Aug 2024
Location: Between my two ears
Posts: 940
variance is different than frequency though, better distinguish them better. (my bad english)
Z2697 is offline   Reply With Quote
Old 16th November 2025, 13:00   #12  |  Link
GeoffreyA
Donor
 
Join Date: Jun 2024
Location: South Africa
Posts: 659
Quote:
Originally Posted by Z2697 View Post
variance is different than frequency though, better distinguish them better. (my bad english)
Would variance be the right term for macroblock-to-macroblock quantiser variation? The terminology is a bit puzzling.
GeoffreyA is offline   Reply With Quote
Old 16th November 2025, 21:46   #13  |  Link
Z2697
Registered User
 
Join Date: Aug 2024
Location: Between my two ears
Posts: 940
Quote:
Originally Posted by GeoffreyA View Post
Would variance be the right term for macroblock-to-macroblock quantiser variation? The terminology is a bit puzzling.
The variance in this context is the "mathematical variance", not just the fact that there's variation.
Z2697 is offline   Reply With Quote
Old 17th November 2025, 09:17   #14  |  Link
GeoffreyA
Donor
 
Join Date: Jun 2024
Location: South Africa
Posts: 659
Quote:
Originally Posted by Z2697 View Post
The variance in this context is the "mathematical variance", not just the fact that there's variation.
I see. So it appears to be the deviation from the mean of a set of values.
GeoffreyA is offline   Reply With Quote
Old 17th November 2025, 10:05   #15  |  Link
Z2697
Registered User
 
Join Date: Aug 2024
Location: Between my two ears
Posts: 940
Sidenote, some time ago I said the "recent" SVT-AV1 variance-boost is similar to AQ1, just from the names and general idea in the showcase, but I haven't take a deeper look.
It does have more dials, so it could be more sophiscated. Though AQ1 (x264/5) is simple and elegant and works very well.

Anyways, whatever it is, we didn't have any equivalent of x264 AQ in SVT-AV1 before it, is what I wanted to say. I could be wrong, the "aq-mode" in SVT-AV1 and libaom does have "variance" in one of its options, but if it's the AQ we familiar with, why would variance-boost be needed? (and it's "mode 1", but "crf" requires "mode 2")
(me being lazy and don't want to read av1 code )

Last edited by Z2697; 17th November 2025 at 18:15.
Z2697 is offline   Reply With Quote
Old 17th November 2025, 10:36   #16  |  Link
GeoffreyA
Donor
 
Join Date: Jun 2024
Location: South Africa
Posts: 659
Simplicity tends to be best; and Dark Shikari was touched by genius, coming up with and implementing these techniques, not to mention mbtree, which takes a similar concept in the temporal direction.

It's a nightmare trying to decipher SVT-AV1's options. Certainly, we haven't seen this level of inspiration and ingenuity since x264, but it's too confusing; and if one encodes something, there's always doubt: were the settings right, would it handle the range of content well, or did we use the right fork?

Didn't variance-boost work analogously to AQ3, helping dark macroblocks?

Last edited by GeoffreyA; 17th November 2025 at 10:41.
GeoffreyA is offline   Reply With Quote
Old 17th November 2025, 18:33   #17  |  Link
Z2697
Registered User
 
Join Date: Aug 2024
Location: Between my two ears
Posts: 940
The essence of x264 AQ1 is just like, 3 or 4 lines of code (or even 2), depending on whether you think the strength multiplied with constant and the loop are lines of code or not.
Code:
strength = h->param.rc.f_aq_strength * 1.0397f;

for each macroblock {
uint32_t energy = ac_energy_mb( h, mb_x, mb_y, frame );
qp_adj = strength * (x264_log2( X264_MAX(energy, 1) ) - (14.427f + 2*(BIT_DEPTH-8)));
}
As you can see the more "ac energy" / variance / contrast a block has, the higher the QP is added to it, with a negative shift to balance the adjustments.

(ac_energy_mb function does not return the actual variance, it returns the value without the division by (n-1) at the end, if I read the code correctly)
Z2697 is offline   Reply With Quote
Old 17th November 2025, 19:25   #18  |  Link
GeoffreyA
Donor
 
Join Date: Jun 2024
Location: South Africa
Posts: 659
It's a surprisingly straightforward method. So, the QP adjustment is directly proportional to the energy of each macroblock.
GeoffreyA is offline   Reply With Quote
Old 19th November 2025, 21:34   #19  |  Link
Z2697
Registered User
 
Join Date: Aug 2024
Location: Between my two ears
Posts: 940
x265 changed AQ2 "constant" from 14 to 11 and "exponent" from 0.125 to 0.1 for claimed "better bit distribution".
According to my undisclosed test this is the main cause of "grain smearing" (as microchip8 describes it).
But I still prefer AQ1 even if the change is reverted.

Quote:
commit b72e2aef5a7fc445839e647a564970880333681d
Author: Santhoshini Sekar <santhoshini@multicorewareinc.com>
Date: Wed May 21 12:04:52 2014 +0530

aq: fine tune aq logic to distribute bits even better
Z2697 is offline   Reply With Quote
Old 20th November 2025, 19:01   #20  |  Link
GeoffreyA
Donor
 
Join Date: Jun 2024
Location: South Africa
Posts: 659
Well, one gets the impression that lots of adjustments in x265 were not of x264's calibre. I think the lower constant should result in higher QPs.
GeoffreyA is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:10.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.