View Full Version : any benefit in mod8 over mod4?
I am about to encode one of my DVDs. After cropping, I am left with a mod4 resolution. I can overcrop it by 4px and get to mod8.
I am just wondering if mod8 would have any benefit or advantage over mod4.
akupenguin
5th April 2009, 05:11
No. To maximize compression, minimize the amount of padding needed to fill mod16. So (res%16)==14 is better than (res%16)==12 is better than (res%16)==8.
Thanks for your reply akupenguin. Please forgive my "non-technical" self.
If I'm understanding you correctly, mod4 will give me better compression than mod8? You lost me somewhere in the middle of your reply :)
I know the best option would be mod16 but it's too much of an overcrop for me to be happy. That's why I am trying to figure out what my next best option is.
J_Darnley
5th April 2009, 10:00
Not necessarily. Akupenguin said you need to minimise padding. Video frames are padded horizontally and vertically up to the next mod16 value. Lets say you encode a video that is almost 160 pixels wide, 152px is mod8 and 156 and 148px are both mod4 but 148 requires more padding than 152 or 156 so it is worse than both. 152 requires more padding than 156 so it is worse than 156. So 148 is worse than 152 which is worse than 156. (This is ignoring mod2 values)
Oh OK. I think I understand it now. So basically there are times when mod4 is better than mod8 and other times where the reverse is true. It all depends on which resolution is closest to the next mod16 value.
Thanks for the help you guys :)
Manao
5th April 2009, 13:48
Do note that akupenguin is talking about compression efficiency. With a constant quantizer, 156x160 will be more efficient than 152x160, but 152x160 will take less bits.
Do note that akupenguin is talking about compression efficiency. With a constant quantizer, 156x160 will be more efficient than 152x160, but 152x160 will take less bits.
Hehe. Figures that once you think you understand it all, it gets more complicated ;)
So you are saying that with a 2-pass encode, 156x160 is better than 152x160? And with a CRF encode, it would be the other way around?
What do you mean by "will take less bits" and why would that be better than worrying about getting the best compression efficiency?
I am officially confused once again.
LoRd_MuldeR
6th April 2009, 01:45
So you are saying that with a 2-pass encode, 156x160 is better than 152x160? And with a CRF encode, it would be the other way around?
Nope! When encoding at a constant quantizer "taking less bits" means that you'll get a smaller file. In 2-Pass mode it means that you'll get better quality at the same file size.
152x160 contains less pixels than 156x160, so it will take less bits to encode. Internally both are padded to mod16. 152x160 is padded with 8 pixels, 156x160 with 4 pixels.
So you pay bits for pixels that you'll never see! Still encoding at 156x160 will take even more bits than 152x160, because the "real" pixels cost more bits than the padded ones.
If you only look at the total bit cost, then 156x160 costs more bits than 152x160, but you must take into account that in the 152x160 version you get fewer pixels to see!
Regarding the pixels you actually get to see, 156x160 takes less "bits per visible pixel" than 152x160. Hence it compresses more efficient...
In short: For a 2-Pass encode the 152x160 version will look better than 156x160, for a constant quantizer encode 152x160 will give a smaller file than the 156x160 version.
However you cannot say that 152x160 is a "better" choice than 156x160, as 152x160 simply shows less pixels to the viewers. It's a trade-off..
Thanks for the detailed explanation LoRd_MuldeR. It's starting to make more sense to me now.
So what's more important... having better compression or having better quality? I'd say quality. I mean, after all, I'm using x264 for the quality.
156x160 is mod4 and has better compression than 152x160... but 152x160 is mod8 and has better quality. I don't fully understand what "compression" means. But quality is quality so I guess I'll go with that.
LoRd_MuldeR
7th April 2009, 13:04
I don't fully understand what "compression" means. But quality is quality so I guess I'll go with that.
Better "compression" means that fewer bits are needed for the same number of visible pixels. Padded pixles cost bits, although they'll never be visible. Hence they hurt compression efficiency! The 152x160 version has less visible pixels (and more padded ones), so it compresses less efficient. The 156x160 version has more visible pixels (and less padded ones), so it it compresses more efficient. Anyway, all these considerations are "per visible pixel" only! If you look at the total bit cost, then 156x160 will cost more bits than 152x160. That's because both are padded to 160x160 internally, but 156x160 contains more "real" pixels (and less padded ones). And "real" pixels cost even more bits than padded ones, as padding is done in a way that keeps the additional bit cost for the padded pixels as low as possible.
So what's more important... having better compression or having better quality?
Decide yourself. I personally would probably crop it down to 144x160. Anyway I doubt you'll be able to see the difference in quality between 156x160 and 152x160 ;)
Only a test encode can give you a clear answer...
slavickas
7th April 2009, 13:27
I *think* if resolusion is decent, you wont see diff in quality either way, so speculating which one looks better is moo point
akupenguin
7th April 2009, 15:15
I *think* if resolusion is decent, you wont see diff in quality either way, so speculating which one looks better is moo point
That's true of every marginal 1% improvement in compression. Which means that you should consider how much effort and/or cpu-time you want to put into saving x% bitrate. It does not mean that you shouldn't bother with some decision just because the difference by itself is imperceptible.
audyovydeo
7th April 2009, 15:37
@Mob,
as a beginner I struggled with this in the past. The eye-opening explanation for me was this :
The encoder optimizes between 3 parameters: quality, bitrate, and speed.
There are some complex interactions between options, but lets ignore them for now. To a first approximation, if you use CRF or CQP mode then the only option that affects quality is --crf or --qp, and all other options tradeoff speed vs bitrate (note: this does not mean that you can measure just the bitrate to determine the effectiveness of some option. I said approximation.). If you use ABR, CBR, or 2pass mode, then the only option that affects bitrate is --bitrate, and all other options tradeoff quality vs speed. I can merge those two statements to become: Ratecontrol options trade quality vs bitrate, and all other options trade speed vs bitrate.
So there's two independent decisions to make: What quality you want (determines the value of --crf), and how much cpu-time you're willing to spend (determines everything else).
There's more complex interactions here, but I'll ignore them too. To a first approximation, each speed-vs-bitrate option costs a certain amount of time and reduces bitrate by a certain %. You pick some ratio of how much time you're willing to spend to save any given amount of bitrate, and enable all the options whose ROI is better than that.
from here : http://forum.doom9.org/showthread.php?p=1020500
In other words, YOU have to make an intelligent choice between the quality you want to preserve, how much storage you want to use and how much time you want to waste (and, ultimately, how much electrical power you want to use, which, in fine could probably be more useful for other purposes, in the grander scheme of things).
hope this helps.
cheers
audyovydeo
LoRd_MuldeR
7th April 2009, 16:36
But in reality it's not that easy. Changing other options at a constant CRF value will effect both, bitrate/size and quality.
For example using "slower" settings at the same CRF value may result in a bigger file and a better quality. All you can say is that "slower" settings improve the quality/bitrate ratio...
audyovydeo
7th April 2009, 16:59
But in reality it's not that easy. Changing other options at a constant CRF value will effect both, bitrate/size and quality.
For example using "slower" settings at the same CRF value may result in a bigger file and a better quality. All you can say is that "slower" settings improve the quality/bitrate ratio...
Bingo !!!
which is why I stubbornly hang on to metrics (ssim). It's the only way I have to measure quality, until another one comes along. I then make a choice of my minimum ssim, maximum bitrate, and maximum encoding time.
(notice my recurrent use of first person singular form, so as not to start another debate on "psy", subjective eye perception, alternate realities, etc). I'm a metrics fan because I need metrics. Quite beside the fact that "anything that cannot be measured ..." et caetera ...
cheers
audyovydeo
Well I must say, I started this thread with what I thought was a simple question that has a simple answer. Turns out that wasn't the case. I ended up learning something, but now I have about 10 other questions I want to ask :D
But before I attempt to find answers to those questions (which I'm sure would lead me to even more questions), I need to get a better understanding of the basics. I don't feel like I understand everything that has been said in this thread the way I should. So before I move on to even more complex things I need to make sure I have this basic stuff down first. Right now I'm going to spend a lot of time reading and learning about all of this and hopefully get an overall better understanding in the end.
For the encode that I'm working on right now, I have chosen to go with the mod4 resolution since it will only have 4px of padding to the next mod16 and I wont have to overcrop any visible pixels which is what I like. Also, since my encode will be CRF and I don't care too much about filesize then for me there is not much benefit in overcropping by 4px to get to mod8. My whole reason for starting this thread was to figure out if going the mod8 route would benefit me in any way. And from what I've learned in this thread, in my particular case, it would give me more padded pixels and a lower filesize. So since I don't care about filesize I may as well go with mod4 this time around.
I just want to say thanks to all you guys who replied and took the time to help me out. I appreciate it. There is a lot of great information in this thread and I will use it to get myself to the next level.
akupenguin
8th April 2009, 09:18
And from what I've learned in this thread, in my particular case, it would give me more padded pixels and a lower filesize. So since I don't care about filesize I may as well go with mod4 this time around.
Those are individually true, but the fact that you chose those points as a summary shows what you didn't understand. Even if you did care about filesize and didn't care much about overcropping, mod4 would still be the right answer.
Those are individually true, but the fact that you chose those points as a summary shows what you didn't understand. Even if you did care about filesize and didn't care much about overcropping, mod4 would still be the right answer.
I'm happy that I got to the right answer. But you are basically saying that I got to the right answer for the wrong reasons. So I'm not happy about that part at least. Because that means that the next time I have to encode something, I may end up with the wrong answer. :(
I'm trying to get better at this and I just want to be sure I'm getting the point you made in that last reply. Here is what I've gotten out of it:
The right answer is to crop to the nearest mod4 resolution without overcropping any visible pixels just for the sake of getting a mod16 resolution. Is this more along the lines of how I should be approaching the situation?
If I still have it wrong, then what do I need to consider when making a decision on how to crop a video? Obviously as you have pointed out, mod4 is the right answer in my particular case. But why is that the right answer? This is what I need to know in order to be able to deal with the next video correctly.
The two factors I am basing my decision on now are the fact that I don't mind large files and the fact that I would rather not overcrop if I don't have to. But according to what you said, this is the wrong way to go about it. So what should I be thinking about instead? How should I approach the situation?
In the first post you made in this thread, you said in order for me to maximize compression I should "minimize the amount of padding needed to fill mod16". This is one of the reasons why I decided to go with mod4 since overcropping to the mod8 resolution would have given me more padding. I hope at least I am thinking about that part correctly.
What I am trying to understand right now is how do I get to the right answer? I'm not supposed to be thinking about filesize and I'm not supposed to be overcropping visible pixels. This leads me to believe that the right answer is cropping to the nearest mod4 value (getting rid of all back bars and keeping as much visible pixels as possible). Is that the way I should be thinking?
akupenguin
9th April 2009, 13:11
Don't think about any modulus other than 16.
Crop off all the black border. If the edge is soft, then make sure to remove any partially-darkened rows too. For 4:2:0 you can only crop to even offsets, so this may involve up to 1 pixel of overcrop. (If and when x264 supports 4:4:4, if you use that, don't overcrop or undercrop at all.) Now you have the resolution that provides optimal compression if you want to keep all the source pixels.
The only choice to make from there is: do you care about maximizing compression enough that you're willing to overcrop all the way to mod16? (in your case, no).
And then you're done.
Cropping off any valid pixels will never improve compression unless it removes a whole macroblock, so there's no reason to overcrop even to mod4. Any undercropping (even by 1 row), has the full penalty of coding the edges, so that's bad. IOW, for h264 (unlike previous standards), if your filter chain doesn't contain any scaling, you should ignore modulus just as if you'd never heard of it. If your filter chain does include scaling, then that's an easy way to get mod16 and still keep the whole picture. But don't add a scaler just for this, because scaling introduces some distortion of its own.
mob
10th April 2009, 11:27
Thanks for the great info akupenguin.
Now I understand that the answer to the question of "how do I crop this video?" is as simple as "get rid of all the black borders". No need to think so much.
The only choice to make from there is: do you care about maximizing compression enough that you're willing to overcrop all the way to mod16? (in your case, no).
And then you're done.
This is great and makes it much easier to deal with. No need to worry about mod4's or mod8's. If I want to get better compression I should overcrop to mod16 otherwise don't overcrop at all as it would only cause me to lose visible pixels.
Cropping off any valid pixels will never improve compression unless it removes a whole macroblock, so there's no reason to overcrop even to mod4.
Yep I understand exactly what you're saying now. The only reason to overcrop is if I want to get to mod16, anything else would be pointless. Perfect, and easy to remember :)
I have one question about the last part where you said "so there's no reason to overcrop even to mod4". Do you mean that I am safe even with a mod2 resolution? I'm only asking because I just want to be 100% sure before I screw something up.
But don't add a scaler just for this, because scaling introduces some distortion of its own.
Thanks for the warning. Believe it or not those are words I live by :). I almost never use a scaler for that very same reason. If I ever do need to downscale, I'm always careful to choose a resolution that gives me the least AR error as that's another thing that is important to me.
akupenguin
10th April 2009, 12:02
Do you mean that I am safe even with a mod2 resolution?
yes .
mob
11th April 2009, 01:56
Perfect. Thank you so much for helping with all of this. This turned out to be a great thread.
Chengbin
11th April 2009, 02:44
I'm curious, how much more efficiency you get if you use a mod16 resolution than a mod8?
Brother John
11th April 2009, 16:31
Do you mean that I am safe even with a mod2 resolution?
AviSynth forces at least mod4Śmod2 for YV12 though, so most likely that will be your practical limitation.
I'm curious, how much more efficiency you get if you use a mod16 resolution than a mod8?
The problem here is: how do you define and measure efficiency? A while back I did some tests on that with efficiency meaning deviation from expected file size; and the expectation based on the difference in pixel count between the resolutions.
http://forum.gleitz.info/showthread.php?t=36603 (thread in German, though you should be able to understand the tables)
Short summary: Mod16 was the best regarding compression efficiency with roughly a 1–2% overall advantage. Mod2 (in its mod16-2 incarnation) came in second place. Ranking all other mods was impossible. However I have my doubts if anything in that test was statistically significant.
Since then I’ve settled on pretty much what akupenguin said: Mod doesn’t matter for x264.
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.