View Full Version : Confused about Quant/Quality/PSNR/SSIM
huang_ch
15th June 2006, 14:17
As I'm doing more test with x264 these days, those terms confused me these days. Could anyone help to explain them? Or point to any article/post? Thanks.
1. Const Quant(QP?) vs Const Quality: What's the definition of Quant & Quality? After reading some posts, I've the understanding of Quant is the original complexcity of the frame itself, regardless you encoded it or not. Right? But what about the quality? How better it is encoded?
2. Const Quality: it requires me to assign a value, such as 24. But with different other settings(such as b-frames), the final PSNR/SSIM can be various, the difference can be even less/higher 2.0. Why the quality is not keep constant? My understanding is that since I assign to encode with --crf 24, the final output should be kept at a rather similar quality regardless what other options I add, other options should only impact the bitrate.
3. Also about const quality: I've also get, for example, a much higher PSNR with --crf25 than --crf24 with different options. (Even --crf26 can be a bit higher than --crf23) Why?
4. Is there any method to set an appropriate qpmin/pqmax? I've tried to use 1 pass and look at the result and try to set one. Is it the right way?
DarkZell666
15th June 2006, 16:24
1. It's just like XviD, a quantizer is a mathematical degradation of the picture. Quality, is a VERY subjective term, and even if quantizers and quality are linked, they aren't bound to vary the same way.
To put it simple : constant QP (alias quantizer) applies a constant mathematical degradation to each type of frame, whereas constant quality can degrade complex scenes/frames more, because quality variations are less perceptible in those areas (even if usually we can notice them at some point, just call it constant visual degradation, lol). Constant quality will give an overall qp similar but usually higher than constant QP.
Why the quality is not keep constant?
Simply because some options allow for more (or less) precise calculations, and the codec won't degrade the picture in the same way (wether you use much b-frames or not for example). Why ? Because the value you use to initiate the crf mode (24 for ex.) is only nominal, and if you allow the codec to analyse the frames a bit better (with better options) it might decide that the frames aren't as complex as it might have thought with "bad" settings. (sorry, better and bad are subjective concepts too :p)
There are easy switches to set minqp and maxqp ... --minqp 18 --maxqp 28 for example (or was it --qpmax and --qpmin ? can't remember). I-frames will have a QP of minqp/ipratio (ipratio being > 1) for pframes having a QP of minqp.
And, beware of PSNR ... PSNR is a mathematical approach to quality-measuring. Maths and visual quality just don't mix :)
... same goes for SSIM ^^
huang_ch
16th June 2006, 02:02
Thanks a lot for your explanation.:D
1. It's just like XviD, a quantizer is a mathematical degradation of the picture. Quality, is a VERY subjective term, and even if quantizers and quality are linked, they aren't bound to vary the same way.
But how quality is defined in x264? Through another mathematical formula?
To put it simple : constant QP (alias quantizer) applies a constant mathematical degradation to each type of frame
So you mean if QP of two frames are 18 & 26, it may be both degrade by 2 to 20 & 28?(Just for a simple example:p) So basicaly I mean the encoder will encode each frame for a target QP, right?
whereas constant quality can degrade complex scenes/frames more, because quality variations are less perceptible in those areas (even if usually we can notice them at some point, just call it constant visual degradation, lol).
Is the encoder encoded for a target QP in Constant quality? If so, what the QP is calculated?
Simply because some options allow for more (or less) precise calculations, and the codec won't degrade the picture in the same way (wether you use much b-frames or not for example). Why ? Because the value you use to initiate the crf mode (24 for ex.) is only nominal, and if you allow the codec to analyse the frames a bit better (with better options) it might decide that the frames aren't as complex as it might have thought with "bad" settings. (sorry, better and bad are subjective concepts too :p)
That makes sense. Thanks.
There are easy switches to set minqp and maxqp ... --minqp 18 --maxqp 28 for example (or was it --qpmax and --qpmin ? can't remember). I-frames will have a QP of minqp/ipratio (ipratio being > 1) for pframes having a QP of minqp.
Sorry, I didn't mean to ask for the switch to set min/maxqp, but a method to determine the value to set in min/maxqp.
And in the log of x264, it prints two value of PSNR, one is average, another is global, which means more to the overall quality? gobal? How is the global calculated?
I can always having two videos, with average higher and global lower, how could this happen?
Audionut
16th June 2006, 07:28
Before you put effort into PSNR, remember that it is one of many quality assesments. And arguably not one of the best.
I am not sure why you want to get into the very technical explinations of x264.
IMHO, you would be better off, spending some time with the encoder.
Get some video. Say 1000 frames.
And encode it at a Constant Quantizer.
Start at say Quant 10, then 11, 12, 13, 14 etc, etc.
You can then get a "feel" as to how it works.
Very simple explination.
At each quantizer, the encoder will remove more details to gain more compression.
huang_ch
16th June 2006, 08:34
I am not sure why you want to get into the very technical explinations of x264.
Because I'm a technical man... I always feel that by knowing the details, I can have a better feeling of how it works and how could I handle it. This may be a profession habit. :p
IMHO, you would be better off, spending some time with the encoder.
Thanks for your suggestion, I also feel that I should take it easier.
DarkZell666
16th June 2006, 09:22
But how quality is defined in x264? Through another mathematical formula?
Pretty much indeed, this is why we can actually spot the differences some times, because eyes aren't made out of maths ;)
As for finding the optimal min/maxqp, I'd rather set minqp to 18 and maxqp to 28-30. Why ? minqp 18 because it's similar to XviD's quant 2, maxqp 28-30 because it's what quality I'm personnaly prepared to accept in high-bitrate scenes if needed ;) Leaving the defaults (10/51) is useless imho, it's just like telling XviD to use min quant. 1 and max quant. 31 ... it allows for too much quantizer (and quality) variations. I rather encode to something approaching "constant visual quality", which is what the crf mode tries to achieve in 1 pass (but the filesize isn't predictable of course).
For your other questions, I'm afraid I have some difficulties what you mean, sorry mate ^^' Read the document Sharktooth pointed you at in that other thread about ratecontrol, it's the best starting point :)
Note : I don't have a clue about what global and average psnr represent (or at least why they are different), I'll pass my turn :p
sysKin
16th June 2006, 09:57
But how quality is defined in x264? Through another mathematical formula?
It's not. That's the idea: quality is an outcome of a quantizer. Quantizer (qp) is defined, while quality kinda "works out" by itself.
QP has a direct effect on quality, but it's not the only factor which affects it. Different quantization methods (like trellis) and different motion estimation methods (like search pattern or RDO) indirectly affect quality too.
So you mean if QP of two frames are 18 & 26, it may be both degrade by 2 to 20 & 28?(Just for a simple example:p) So basicaly I mean the encoder will encode each frame for a target QP, right?
Yes.
Adaptive quantization can change quality on macroblock level rather than frame level, but vanilla x264 doesn't use it yet.
Is the encoder encoded for a target QP in Constant quality? If so, what the QP is calculated?
Not quite. Even if QP is constant, practical quality varies from frame to frame. x264's CRF mode will modulate QP a bit for more "constant" quality. I don't know the details how this is done.
And in the log of x264, it prints two value of PSNR, one is average, another is global, which means more to the overall quality? gobal? How is the global calculated?
I can always having two videos, with average higher and global lower, how could this happen?
average = {SUM log(SNR)} / {# of frames}
global = log ({SUM SNR} / {# of frames} )
The log scale is applied before taking mean in "average" case but after in "global" case.
GodofaGap
16th June 2006, 10:06
average = {SUM log(SNR)} / {# of frames}
global = log ({SUM SNR} / {# of frames} )
Perhaps should be added that global PSNR is a fairer way of measuring quality than average PSNR:
A normal encoder can recreate a pure black frame perfectly, which gives a PSNR score for that frame of inf ( log(inf) ), which on it's turn would make the average PSNR also inf. Global PSNR avoids that problem by looking at the whole video as one big frame.
huang_ch
16th June 2006, 13:11
minqp 18 because it's similar to XviD's quant 2
I'm just a bit wondering that in XviD's quant 2 mode, the real quant for each frame would probably be dynamically encoded in a range of 1~5, so maybe minqp 18 is not enough for those quant1 frames in XviD? Would that possible?
GodofaGap
16th June 2006, 13:29
No, in XviDs constant quant mode all I and P frames have the quant specified, and B-frames follow the qp-offset and ratio rules. So quant 2 really is quant 2.
Audionut
16th June 2006, 13:35
I think it's also worth pointing out that the difference between quant 1 & 2 in xvid is huge.
Where as say, the difference between quant 16 & 18 of x264 is not as huge.
huang_ch
16th June 2006, 16:29
I've tried to encode my video with Const Quant 18, and with the -v switch, I can see the stats of each frame, and all the frames are between 18~20, and it seems that almost all P frames(I didn't check frame by frame, just look through) is encoded as quant 18, B frames are encoded as 20, I frames are encoded as 15. How is this defined? Because from MeGUI, it won't let me assign ip/pb ratio when I choose Const Quant mode.
Also, I found this video obviously looks pretty good, so I think qpmin=18 is absolutely working for me. Thanks all of you guys.:)
But about the qpmax, I've tried to encode a cq-28, it obviously not good, the major problem is the blocking and aliased edge, does that mean I should try cq-27,26... until I think the quality is generally acceptable, so that value could be my qpmax?
imcold
16th June 2006, 19:09
try cq 22, still looks fine to me. Encode some short samples with various settings and see for yourself, what suits you the best ;)
Manao
16th June 2006, 20:18
I think it's also worth pointing out that the difference between quant 1 & 2 in xvid is huge.
Where as say, the difference between quant 16 & 18 of x264 is not as huge.The quantizer scale for ASP is linear, while AVC's is exponential. That means that between Q1 / Q2 in ASP, there's as much difference as between Q2 / Q4 ( or Q4 / Q8, or ... ) in ASP, or Q10 / Q16 ( or Q20 / Q26, or Q21 / Q27 ....) in AVC.
As for finding the optimal min/maxqp, I'd rather set minqp to 18 and maxqp to 28-30. Why ? minqp 18 because it's similar to XviD's quant 2, maxqp 28-30 because it's what quality I'm personnaly prepared to accept in high-bitrate scenes if neededAre you ready to accept it even if it means that low motion parts of the video will be encoded at a much higher qp than it would have been, if you hadn't capped the quantizer ? I think the rate control, on that part, knows what it's doing better.
Finally, But about the qpmax, I've tried to encode a cq-28, it obviously not good, the major problem is the blocking and aliased edge, does that mean I should try cq-27,26... until I think the quality is generally acceptable, so that value could be my qpmax?No, because of several reasons. A frame that looks bad at quantizer X doesn't mean that another frame at quantizer X would have looked bad. Secondly, a frame's quality depends _a lot_ on the quality on the preceding frames ( Q20 followed by Q40 will look quite better than Q30 Q30, for example ). You also have to consider what I pointed out earlier : sacrificing quality on, lets say, high action part of the movie, by not capping the quantizer, will lead to a better quality on the slow motion parts. Now, lets consider what the eye would see. On the fast action parts, there would be less details, no blocks ( thanks to the deblocking ), and the overall motion would hide the lack of detail from your eyes ( lest you do a screenshot, but that would be cheating, since it would be trying to show something your eyes don't see while playing it ). During the slow motion part, quality boost given by not capping the quantizer will improve sharpness and details, and you'll see them.
Finally, of course, all what I said implies that you're targetting a bitrate.
huang_ch
17th June 2006, 01:57
Manao, so I think you're suggesting to set qpmax to a not too low value, and let the encoder to decide what exactly the qp to use for encoding, right?
DarkZell666
19th June 2006, 10:17
Are you ready to accept it even if it means that low motion parts of the video will be encoded at a much higher qp than it would have been, if you hadn't capped the quantizer ? I think the rate control, on that part, knows what it's doing better.
Actually, yes :p simply because that's what my eyes prefer to see ;) Blockfest in high-motions scenes make me go dizzy xD
Caroliano
20th June 2006, 02:08
Actually, yes simply because that's what my eyes prefer to see Blockfest in high-motions scenes make me go dizzy xDThat is my opinion too. If I'm doing an high quality rip, the low motion parts will already be in very high quality for me. I'd rather put the bitrate in the parts that are hungry for them, not where it will have an very little efect.
And also there are the scenes that are just complex, not necessarily an high-motion scene. Still, the codec give high quantizers and you can perceive the degradation very well because the things are not moving fast.
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.