Log in

View Full Version : XviD quant distribution question


Anacondo
5th February 2004, 18:39
Hi!

Before starting, I'd like to thank the XviD team for their efforts and their time creating this great codec. I've been using DIVX since version 3.11, but then I decided to test XviD 1.0 beta and never looked back. I'm very satisfied with the results.

I have no problems whatsoever with XviD. The reason of my post is plain curiosity and will of knowledge. I'm doing a 1CD rip of Solaris using gamr's 20040201 build. I saw the option 1st pass full quality and decided to give it a try (as I used to have very good results with beta3 and 1st pass only) using the following: HVS-Good matrix, Adaptative Quant, QPel, GMC, B-VOPs 2-1.50-1.00, Motion SP 6, VHQ 4, Chroma motion, Trellis, default quant range (1-31). I'm using a zone for the movie with chroma optimizer enabled and a zone for credits with quant16. I was expecting a decent filesize, as source is quite good, and the result was just 354MB. Quality was very good for the size, but I decided to run a full 2 pass encode to let the codec do his job properly.

Same settings this time except HVS-Best matrix (as I supposed I had plenty of room to optimize quality) and discard 1st pass, no full quality. VHQ 1 for 1st pass and 4 for second, target filesize 647000KB. At 66% it seems I'll hit the target size accurately, and the XviD Status window looks like this:

http://anacondo.tecnosfera.org/mierdas/xvidstatus.png

My idea from what I've read on this forums is that XviD will use Quant values of 1 in case the encode is undersized (correct me if i'm wrong). I also believe that decoding quant1 frames requires more processing power, and looking at the graph I started to wonder. ¿Why using quant1 at all when there are a lot of quant3 and quant4 frames? I mean, if it's all about inflating filesize, why doing this when other than quant2 are in use? ¿Why not "abuse" of quant2 instead and introduce quant1 only to hit desired size? I can see that only B frames get assigned a quant4, and only I and P frames get quant1. ¿Can I change this behaviour to what I described above by removing the use of B frames? ¿Is it worth it (quality-wise)? ¿Or is this just the way it works and I'm talking plain nonsense?

My AVS script is:

loadplugin("c:\archiv~1\gordia~1\mpeg2dec3.dll")
loadplugin("c:\archiv~1\gordia~1\undot.dll")
mpeg2source("c:\solaris\solaris.d2v",idct=5)
crop(4,74,714,426)
undot()
lanczosresize(544,288)

Thanks in advance.

Koepi
5th February 2004, 20:01
I admit that I tended to say "yes" to your last question before the script ;)

The graph shows that everything is perfect alright, that's the way it's supposed to look like. Nothing wrong there.

You should try to not use adaptive quant. Also using MPEG matrix can give you a quality boost with less q1 frames.

I know, not exactly what you want to hear,
but I hope this helps.

regards
Koepi

Anacondo
5th February 2004, 20:24
Originally posted by Koepi
I admit that I tended to say "yes" to your last question before the script ;)
:D

You should try to not use adaptive quant.
Thanks for the advice. I'll try that.

Also using MPEG matrix can give you a quality boost with less q1 frames.
But I'm using an MPEG-Custom matrix (HVS Best). Isn't it one of the best around for quality?


BTW, the encode already finished and looks fantastic. Thanks again for this great codec!

Bear
5th February 2004, 20:39
What's the resolution?

vinkes
5th February 2004, 20:45
I did an encode of solaris some time ago too. I think this is one of the most compressable movies I know. I believe I got a firstpass of something like 450mb - 500mb (!), I used koepi 240603 xvid build with b-frames, vhq4 etc etc.
So I think you'll be able to encode this movie at good 1cd quality(mpeg, no filtering, high res (704x288)).

Anacondo
5th February 2004, 20:47
Originally posted by Bear
What's the resolution?
544x288 anamorphic (704x288)

Bear
5th February 2004, 20:57
I think HVS Best is pretty good choice. I encode most of my movies by using this martix.

Soulhunter
5th February 2004, 22:03
You can limit the minimum quantizer and/or lower the B-VOP quantizer...

Try n' see what you get... ;)

Bye

Anacondo
5th February 2004, 22:12
I think HVS Best is pretty good choice. I encode most of my movies by using this martix.
Yup, it always gave me good results, too. I believe it's the best along with Andreas 78er when aiming for quality?

Originally posted by Soulhunter
You can limit the minimum quantizer and/or lower the B-VOP quantizer...

Try n' see what you get... ;)

Bye
I think I'll just deactivate V-BOPs and use a lower quant for the credits. Can anyone tell me if I have to redo 1st pass for this?

Thanks.

Soulhunter
5th February 2004, 22:49
Originally posted by Anacondo
I think I'll just deactivate V-BOPs and use a lower quant for the credits. Can anyone tell me if I have to redo 1st pass for this?
You mean deactivate B-VOP's ???

Your avg. quant. for I&P frames is lower than 2... :eek:

But your Avg. quant. is only about 2.6 because of your B-VOP settings... :rolleyes:

So, I would rather try to lower the B-VOP quant. ratio/offset !!!

You could try it with 1/1 settings, should give B-VOP's about quant. 3... ;)

Or even 1/0 settings, this should give B-VOP's about quant. 2... :)

Note: AFAIK, Quant. 2 B-VOP's are still smaller than q2 P-VOB's !!!


And limiting the min. quant. to 2 should also result in more q2 frames !!!

This should give a overall more constant/stable quality !!!


But that is just speculative thinking... ;)

I don't have encoded this source, not used your settings either... :p


And yes, you have to redo the 1st pass then !!!


Bye

mikeX
5th February 2004, 23:17
Shouldn't disabling B-VOPs theoretically give better quality (as long as I,P-VOPs remain @ quant 2)?

I mean AFAIK B-Frames are supposed to hurt quality but make the video much more compressable, thus often producing an overall gain in quality.
Since in this case you don't really need more compression, they can only hurt quality. :confused:

You could also keep the original resolution, or/and skip the 'undot()' filter

Soulhunter
5th February 2004, 23:32
Originally posted by mikeX
Shouldn't disabling B-VOPs theoretically give better quality (as long as I,P-VOPs remain @ quant 2)?

I mean AFAIK B-Frames are supposed to hurt quality but make the video much more compressable, thus often producing an overall gain in quality.
Since in this case you don't really need more compression, they can only hurt quality. :confused:
Ok, Ive edited my last post to make my idea more understandable... :D

For the "B-Frames hurt quality" thing...

Yes, maybe true for the standard settings !!!

Having a P-Frame @ q2 would give a B-Frame @ q4...

For my eyes a q4 B-VOP looks worse than a q2 P-VOP !!!

But a B-VOP @ q3 or even q2 looks really nice for me...


Disabling them would raise the avg. I&P quant !!!

Not sure if the result would be that good... :confused:

But as I said, its just speculative thinking...

Would be cool to see the results for both settings to depend them !!!


Bye

Anacondo
6th February 2004, 00:30
Originally posted by Soulhunter

You mean deactivate B-VOP's ???

Your avg. quant. for I&P frames is lower than 2... :eek:

But your Avg. quant. is only about 2.6 because of your B-VOP settings... :rolleyes:

So, I would rather try to lower the B-VOP quant. ratio/offset !!!

You could try it with 1/1 settings, should give B-VOP's about quant. 3... ;)

Or even 1/0 settings, this should give B-VOP's about quant. 2... :)

Note: AFAIK, Quant. 2 B-VOP's are still smaller than q2 P-VOB's !!!


And limiting the min. quant. to 2 should also result in more q2 frames !!!

This should give a overall more constant/stable quality !!!


But that is just speculative thinking... ;)

I don't have encoded this source, not used your settings either... :p


And yes, you have to redo the 1st pass then !!!


Bye

I see what you mean. With my current setting (no B-VOPs, no Lumi masking and quant8.25 for credits, everything else unchanged) XviD still uses quant1. At about 15% of encode avg quant for I-VOPs is 2.5 and for P-VOPs 2.2, average total reported to be 1.2 (very subtle to change of course). Max used quant is 3.

So average quant for I and P is higher now. But unless a quant2 B-VOP looks better than a P (how do you test that BTW?) quality should be better, shouldn't it? Because previously most of my frames (about 60%) were B-VOPs with an average quant of 3.5 and now are P-VOPs avg 2.2. If B-VOPs looks indistinguishable from P-VOPs, I might as well lower max B quant to 2 and thus lowering filesize while maintaining quality. Even if I restricted I&P to 2-31 I could save even more space and include the AC3 track. :D

But, then again, I don't know if a B-VOP looks better than a P at same quant, and I know that quality has something nothing to do with size (well, actually I know nothing, only what I've read here ;) ) but doesn't it make more sense disabling B-VOPs than lowering max quant for them in this circumstances? However, I'll test with max B quant of 2 when this finishes and report my results. Any more recommendations for this or default 2-1.50-1.00 is OK?


Originally posted by mikeX

You could also keep the original resolution, or/and skip the 'undot()' filter


I'm thinking of doing a 1:1 encode at 704x288 instead of an AR one if Soulhunter's idea convinces me. :)


Thanks for the responses.

sysKin
6th February 2004, 04:05
Whatever you do about b-frames or quantization matrix, I seriously doubt it will make the quality any different ;)

Go for the highest resolution you can get :D

Radek

Soulhunter
6th February 2004, 19:31
Originally posted by Anacondo
So average quant for I and P is higher now. But unless a quant2 B-VOP looks better than a P (how do you test that BTW?)
Encode a sample with q2 B-VOP's and one without B-VOP's @ q2 !!!

Then depend them by watching... :D


Or make also screen shots to depend sample frames by fast skipping between them !!!

You can use Win-XP's (or any program's) slide show function for this... ;)

Originally posted by Anacondo
quality should be better, shouldn't it? I might as well lower max B quant to 2 and thus lowering filesize while maintaining quality. Meant the B-VOP ratio and offset here !!!

Originally posted by Anacondo
Even if I restricted I&P to 2-31 I could save even more space and include the AC3 track. :D Don't really know If this is true for the HVS Best matrix... :rolleyes:

But with MPEG matrix I find it very hard to see any significant difference between quant2 and quant1 encodes !!!


I would limit the min I,P,B quant to 2 and the B-VOP offset n' ratio to 1/1 !!!

And also a higher resolution as sysKin mentioned before...


See what you get with the 704x288 resolution...

If the avg. quant will be to high, you could also consider to change the B-VOP settings again !!!


But again its all a bit speculative... ;)

I usually do 5-10 encodes per movie till I find the perfect script n' settings for me !!!


Bye

Anacondo
6th February 2004, 22:40
Originally posted by Soulhunter
Encode a sample with q2 B-VOP's and one without B-VOP's @ q2 !!!

Then depend them by watching... :D

Or make also screen shots to depend sample frames by fast skipping between them !!!


Can I do this in something like VirtualDub, search for B-frames?


Meant the B-VOP ratio and offset here !!!


I think my concepts about this matter are not clear enough. I'll do some research here and learn how to use them properly.


I would limit the min I,P,B quant to 2 and the B-VOP offset n' ratio to 1/1 !!!

And also a higher resolution as sysKin mentioned before...

See what you get with the 704x288 resolution...


After further testing last night with and w/o q1-2 limited B-VOPs @ 544x288, I just did this: encode at 704x288 as sysKin recommended with default quant range and B-VOPs 2/1.0/1.0. Max used quant was 3 at 15% but I couldn't see the final avg quant, I was not at home at the end and the XviD status window dissapeared. Quant1 was still used, but much less than before. Quality is astonishing for 1CD and this res.


If the avg. quant will be to high, you could also consider to change the B-VOP settings again !!!

But again its all a bit speculative... ;)

I usually do 5-10 encodes per movie till I find the perfect script n' settings for me !!!


:eek: Well, 4 times is enough for me by now. I keep learning. Thanks everyone for the help!


Cheers.

Soulhunter
7th February 2004, 19:23
Originally posted by Anacondo
Can I do this in something like VirtualDub, search for B-frames? IIRC, that does not work when you have used packed-bitstrem... :(

But you can use ffdshow's OSD "frame-type-info" and its in-build capture function to do this... ;)
Originally posted by Anacondo
I think my concepts about this matter are not clear enough. I'll do some research here and learn how to use them properly.
Its not that complicate... :)
B-VOP quant = (VOP q before B-VOP + VOP q after B-VOP : 2) * quant ratio + quant offset
So for a fixed quant 2 encode this means...
B-VOP quant = (2 + 2 : 2) * quant ratio + quant offset
If you want to have quant 2 B-VOP's use this...

quant ratio = 1
quant offset = 0
(2 + 2 : 2) * 1 + 0 = 2
If you want to have quant 3 B-VOP's use this...

quant ratio = 1
quant offset = 1
(2 + 2 : 2) * 1 + 1 = 3
So you can figure out this "Max used quant = 3" thing now ... ;)


Bye

Anacondo
8th February 2004, 12:52
Thanks! It all makes much more sense now :D

Cheers.