Log in

View Full Version : Adaptive quantization in x264


thesnowman
31st May 2013, 09:40
Hello, All

Can anybody help me with the topic question? More precisely, there are 2 paramters aq-mode and aq-strength.
Second, one as far as I understand just sets how influential adaptive quantization will be. And first one has 3 modes 2 of which (variance and autovariance) actually perform AQ.

I have next 3 command lines to produce 3 differently encoded videos:
1) --aq-mode 0 --tune=psnr --no-psy
2) --aq-mode 1 --aq-strength 1.5
3) --aq-mode 2

and common parameters for each case are:
--crf 35 --rc-lookahead 0 --aq-mode 0 --subme 1 --bframes=2 --keyint=90 --no-scenecut --b-adapt 0 --trellis 0 --tune=psnr --weightp 0 --ref 1 --no-psy
As you can see I disable some features and force some other things here. This is done for tests.

As a result I have 3 different videos. 2nd and 3rd are ususally smaller in size. But i can't really see that smooth areas are less blocky (well maybe in some cases) but generally i can't find a big difference between those videos. However, sometimes I notice high frequency things, usually near the borders (e.g. edge of a man figure and background).

Maybe I use parameters in a wrong way? Also is there a way to actually produce videos of same size, but with subjective quality better instead of what I get ( smaller size but hard to see difference). Are any video sequences suitable for this method or should I choose some specific to see the difference?

Thanks in advance!

detmek
31st May 2013, 13:08
Also is there a way to actually produce videos of same size, but with subjective quality better instead of what I get ( smaller size but hard to see difference).
Thanks in advance!
Use 2-pass encoding.

LoRd_MuldeR
31st May 2013, 13:35
If you want to compare these settings visually, you have to ensure that all files have the exactly same size (i.e. same average bitrate).

Otherwise you are comparing apples and oranges! So, as detmek pointed out, better use 2-Pass mode.

The (more difficult) alternative would be to use CRF mode and, for each configuration, find the highest possible CRF that just gives "accaptble" quality - then compare resulting file sizes.

BTW: Yes, --aq-mode enables or disables AQ, while --aq-strength controls the strength of the effect. Also the "mode 1" variant is the standard one, while "mode 2" is more experimental.

(As far is I know, "mode 2" was found to improve SSIM results a lot, but whether it actually improves the perceived quality is up for debate - details (http://git.videolan.org/gitweb.cgi?p=x264.git;a=commit;h=88b35c2d3bd86b42059e27db365752da9f2cd032))

thesnowman
31st May 2013, 15:57
Thanks guys

I actually forgot to mention that i also use --crf X. It is also same for all 3 types of encoding. And I still receive different sizes (with AQ on(1st &2nd modes) and off (0 mode).

Using a 2 pass method is a possible solution but, 1) time consuming and 2) it is still hard to say how should I change crf (or any other parameters) to get same size, even after having done 1st pass :-(

LoRd_MuldeR
31st May 2013, 18:01
Thanks guys

I actually forgot to mention that i also use --crf X. It is also same for all 3 types of encoding. And I still receive different sizes (with AQ on(1st &2nd modes) and off (0 mode).

Because CRF in no way guarantees that you get a specific file size! So that is not surprising at all. Just use 2-Pass when you need to hit a specific size ;)

Also, when changing other influential settings, such as the AQ mode, the same CRF value isn't even guaranteed to give the same quality.

Many people are confused about this, but the CRF value is not an absolute quality measure. The meaning of a specific CRF value depends on your other settings!

All you know is: The same CRF value roughly gives the same quality for different sources, as long as no other parameters are changed...

Using a 2 pass method is a possible solution but, 1) time consuming and 2) it is still hard to say how should I change crf (or any other parameters) to get same size, even after having done 1st pass :-(

It's just not possible to know the CRF that hits a specific size beforehand. Again: Use 2-Pass when 2-Pass is needed...

If you use CRF mode, you state: "I know which CRF value approximately gives the desired quality and I don't care about the exact file size."

Though, after a 2-Pass encode has completed, x264 will output the final rate-factor, i.e. the CRF value that would have resulted in the desired file size (average bitrate).

thesnowman
4th June 2013, 13:30
Thanks LoRd_MuldeR I know that with CRF I only specify approximate quality.

Regarding "final rate-factor", just to be sure that I've understood you correctly:

1) First I should run something like --aq-mode 1 --pass 1
2) Then run --pass 2 --bitrate <bitrate from step1>

?

Asmodian
4th June 2013, 20:38
No, final rate-factor is the --crf value that would have resulted in the bitrate specified.

1) Run something like --aq-mode 1 --pass 1
2) Then run --aq-mode 1 --pass 2 --bitrate <desired bitrate>

After pass 2 is done it tells you the rate factor (crf value) that would give you the same size file if you ran a single pass crf encode with the same settings on the same video. I wouldn't actually run that encode though as it the results would be almost identical to the already completed second pass.

To test the different --aq-modes you should run three two pass encodes:

1a) --aq-mode 0 --tune=psnr --no-psy --pass 1
1b) --aq-mode 0 --tune=psnr --no-psy --pass 2 --bitrate X
2a) --aq-mode 1 --aq-strength 1.5 --pass 1
2a) --aq-mode 1 --aq-strength 1.5 --pass 2 --bitrate X
3a) --aq-mode 2 --pass 1
3b) --aq-mode 2 --pass 2 --bitrate X

Always use the same value for X. Do not use crf encoding at all when comparing x264 settings.

thesnowman
5th June 2013, 10:12
Thanks a lot for clarification.

By the way, is any type of content usually benefits from AQ ?
Maybe there are types of video sequences which are good for AQ and others are better to be encoded without it?

Thanks

JEEB
5th June 2013, 12:17
Most content, if not all of it, generally benefits from AQ. Two very glaring examples are the two commonly used testing clips parkrun and park_joy (available at derf's sample collection (http://media.xiph.org/video/derf/), for example). So far even "next-gen" encoders that do not implement AQ generally tend to do badly with it :) .

turab
5th June 2013, 17:18
AQ basically means the encoder is able to use different amounts of compression for different parts of a frame. That doesn't mean it can't use the same amount compression throughout if that happens to be ideal.

sneaker_ger
5th June 2013, 20:56
By the way, is any type of content usually benefits from AQ ?
Maybe there are types of video sequences which are good for AQ and others are better to be encoded without it?

--aq-mode 1 is x264's default, btw.

LoRd_MuldeR
7th June 2013, 00:42
AQ basically means the encoder is able to use different amounts of compression for different parts of a frame. That doesn't mean it can't use the same amount compression throughout if that happens to be ideal.

However here "ideal" means whatever the AQ algorithm considers ideal. That is not necessarily the same as "ideal with respect to human perception" or "ideal with respect to your favorite quality metric".

Anyway, the AQ algorithm in x264 works very well for most content and the Tuning system lowers the AQ strength for the type of content where that makes sense (cartoon-like animations).

thesnowman
11th June 2013, 11:10
Just encoded 2 videos (parkrun and park_joy) - results are pretty impressive. I guess because of a lot of high-frequency type of content.