Log in

View Full Version : GOP + matrix


86peaches
26th November 2002, 14:53
what are the GOP structure and Quantize Matrix tabs for?

i have been using TMPG for a while but it just occured to me i have absoultely no idea what they are for.

so am i missing out on anything? what are they actually for?

SansGrip
26th November 2002, 23:30
what are the GOP structure and Quantize Matrix tabs for?

Short question, long answer:

GOP structure

An MPEG stream is subdivided into groups of pictures (GOPs), comprised of various types of frames. An I-frame is more or less a JPEG-compressed frame, containing all the information from the source frame albeit highly compressed. P-frames and B-frames contain only part of the information from the corresponding source frame, encoded as the difference between nearby frames.

When you play back the MPEG file, the decoder reads the I-frame and displays it verbatim, then it reads the next frame (which is most likely a B- or P-frame) and combines that "difference information" with the I-frame to reconstruct the picture, which it then displays. And so on.

A GOP is a collection of frames which always starts with an I-frame. For NTSC video there's usually (always?) 18 frames in the GOP, comprised of some I-frames and a lot of P- and B- frames.

Theoretically, the more I-frames you have in the GOP the more accurate the encoding will be, but it will also be a lot bigger, because it takes far more space to describe an entire frame than it does to describe the difference between one frame and another.

TMPGEnc's GOP tab allows one to specify how many I-frames, P-frames and B-frames will go into one GOP, as well as some other related settings.

It's best not to mess with it unless you know what you're doing. If you want to experiment you could take a look at, say, the KVCD templates and copy the settings from those. The GOP structure used in the KVCD templates provides better compression than the TMPGEnc defaults.

Quantize matrix

In order to understand the quantize matrix, you need to know a little bit about how MPEG is compressed. The first thing it does is split the frame up into 8x8 blocks. Instead of trying to compress the 64 pixel values in this block directly, what it does is it converts this information into 64 numbers representing the frequency range of the pixels in the block (this process is known as Discrete Cosine Transform, or DCT).

If you imagine these 64 numbers in a 8x8 square, the numbers in the top-left corner will represent low frequencies (that is, areas with little detail, flat surfaces etc.), and the number in the bottom-right corner will represent high frequencies (detailed areas with lots of edges).

It so happens that because of how human vision works, we can remove a lot more information from high frequency areas of the picture than from the low frequency areas before we start to notice anything's amiss. MPEG takes advantage of this by quantizing (basically, dividing) each of the 64 numbers by another number, thereby making it smaller.

How big a number these values are divided by is determined by the quantize matrix. If you look at the TMPGEnc settings you can see that the numbers get progressively bigger towards the bottom-right of the square (you'll also notice there are 64 of them). This means that numbers towards the bottom right, i.e. in the high frequency area, get divided by a larger amount than those in the top left.

Often the values in the very bottom-right end up as zeroes, which is perfect for compression purposes because we can run those consecutive zeroes together to take up less space.

By changing the numbers in the quantize matrix you change how much the various frequencies are quantized, or compressed. The TMPGEnc default values are pretty good, but IMO can be improved. There are many templates available with custom quantize matrices that you can check out.

By the way, there are two matrices in TMPGEnc because one is for I-frames and one is for P- and B-frames.

i have been using TMPG for a while but it just occured to me i have absoultely no idea what they are for.

I hope you have a vague idea now. With more time on my hands I could probably be more lucid, but I have to go cook supper ;).

(Note that the above is a very simplified explanation of how MPEG works, and isn't entirely accurate but should be good enough to give you an idea of what's going on. You can find plenty of in-depth information on MPEG through Dr Google if you're curious.)

86peaches
27th November 2002, 11:28
that's plenty of info for me :) , thanks SansGrip.