PDA

View Full Version : Matrix or Matrices for encoding Mpeg-2 - Please explain, help or link


video_magic
12th February 2005, 19:04
I have noticed Matrices, which are a lot of numbers that I understand help improve the encoding quality in some way

I would like to know the basic information about them (preferably explained simply :D ) - i.e. what do the numbers mean and what do Matrices do - what's the basic idea of how they work?

if anyone knows a good link and could give a little tutorial if it's worth me making my own if that's an option, even better.

I am interested in Matrices for Mpeg-2 and Mpeg-1.

If it's complicated please explain simply if possible, thanks. Here are a couple of questions too:

Do Matrices alter the picture for percieved qulity or enhancements - I mean like you could have a 'sharpen' effect which might fool the viewer into thinking it's a better quality encoding but it has actually altered the picture further from the original. Or do Matrices really improve the quality by keeping the picture closer to the original than if it was not used.

Is the use of a Matrix permissible if I wanted to encode 'Spec-compliant' Mpeg? I mean, does the decoder have to know about Matrices that were used to encode, or is this not an issue.

Amnon82
13th February 2005, 15:47
What is a Quantization Matrix?

To quote the explanation here: (http://www.ece.purdue.edu/%7Eace/jpeg-tut/jpgquan1.html)

The quantization matrix is the 8 by 8 matrix of step sizes (sometimes called quantums)
- one element for each DCT coefficient. It is usually symmetric. Step sizes will be small
in the upper left (low frequencies), and large in the upper right (high frequencies);
a step size of 1 is the most precise. The quantizer divides the DCT coefficient by its
corresponding quantum, then rounds to the nearest integer. Large quantums drive small
coefficients down to zero. The result:
many high frequency coefficients become zero, and therefore easier to code."

To put it short: It's the lossy filter by which you achieve higher compressibility by losing detail. The amount of detail lost is determined by the values of each individual quantum.

More theory about the technical process behind it:
http://www.ece.purdue.edu/~ace/jpeg-tut/jpegtut1.html
http://www.mpeg.org/MPEG/MSSG/tm5/Ch7/Ch7.html
http://www.cmlab.csie.ntu.edu.tw/cml/dsp/training/coding/jpeg/jpeg/encoder.htm
http://www.acm.org/crossroads/xrds6-3/sahaimgcoding.html
Note: Most of these links are about Jpeg but the process is nearly the same for MPEG-2

Some matrices of mine:

AutoQ#1 Matrix:

8,16,19,22,26,27,29,34
16,16,22,24,27,29,34,35
19,22,26,27,29,34,35,38
22,22,26,27,29,34,35,40
22,26,27,29,32,35,40,48
26,27,29,32,35,40,48,50
26,27,29,35,40,48,50,60
27,29,35,40,48,50,60,62

16,20,24,28,32,36,40,44
20,24,28,32,36,40,44,48
24,28,32,36,40,44,48,52
28,32,36,40,44,48,52,56
32,36,40,44,48,52,56,58
36,40,44,48,52,56,58,60
40,44,48,52,56,58,60,62
44,48,52,56,58,60,62,62

(C) 2005 by Amnon82 - You will find it in Auto(C)Q, DRPEncEasy, DRPEncME, DRPEncXP, EasySVCD/DVD.

AutoQ#2 Matrix:

8,16,19,22,26,28,32,38
16,16,22,24,28,32,38,44
19,22,26,28,32,38,44,48
22,22,26,32,38,44,48,54
22,26,32,38,44,48,54,64
26,32,38,44,48,54,64,74
32,38,44,48,54,64,74,84
38,44,48,54,64,74,84,94

16,20,24,28,36,42,46,52
20,24,28,36,42,46,52,58
24,28,36,42,46,52,58,62
28,36,42,46,52,58,62,68
36,42,46,52,58,62,68,78
42,46,52,58,62,68,78,88
46,52,58,62,68,78,88,99
52,58,62,68,78,88,99,99

(C) 2005 by Amnon82 - You will find it in Auto(C)Q and HCEncoder

neuron2
13th February 2005, 17:02
Suppose you have a number in 8 bits. It has 256 levels. You want to save some bits when sending the value. So you divide it by 2 and send that. It is only 7 bits now. Then when you receive that you multiply it back by 2. You've saved bits but you now only get the even values of the number.

That's just to give you an intuitive idea of what quantizing is for and the effect it has.

video_magic
13th February 2005, 19:19
Thanks guys! I get how they work now :cool:

To try and confirm my understanding: This kind of lossy compression (mpeg & jpeg) deals with the picture in blocks, and these matrices can affect the lossy compression of the blocks - using how the eye percieves details.
I guess the options in Mencoder 'lumi_mask', 'dark_mask', 'tcplx_mask', 'scplx_mask' & 'p_mask' work in the this way, in which case I suppose it would be inadvisable to enable them and also use a Matrice?

But wavelet encoding which is becoming popular would not use these matrices because it doesn't use blocks but deals with whole frames at once.

From what I just read lower numbers give the most precision of detail, what's the range of numbers that can be used?
Is it pointless to put them all to '1' to try and get the best quality encode :sly: , I suppose that would be too easy! and it doesn't work in that way.

Here's a quick question which might help me solve my main issue with Mpeg - what would be a good matrice to help maintain subtle shades in very dark areas? At the moment I believe it always just makes it all the same black - so people in black suits look like black blobs and not very life-like. It's difficult to tell on the screen, but even so I don't think the details of shade are being retained. I don't suffer from getting blocks in very dark areas though, like some other people complain of as I've read, just it all looks the same black.

hank315
14th February 2005, 01:26
Is it pointless to put them all to '1' to try and get the best quality encode , I suppose that would be too easy! and it doesn't work in that way.Too easy indeed :)
Don't use values < 8 for intra and < 16 for non-intra and also don't use values > 255 (better not use values > 127, some encoders/decoders can't handle it)
There's no perfect matrix, every matrix used is a compromise.
The upper left part (lower frequencies) take care off the general picture, the lower right (high frequencies) take care of the detail.
So if you want to preserve all detail just use all 8 (intra) and 16 (non-intra) but the result will be bad, the lower frequencies will not have enough bits.
The used quantiser (Q-value) can be seen as a factor applied to the matrices.

Hope this helps, but if you really want to know more about it, just Google on DCT or FFT, you will get *alot* more information ;)