PDA

View Full Version : CQM to AVC conversion


redfordxx
12th December 2005, 16:05
IIRC, I read somewhere, that when encoding once decoded MPEG again, it is best to use the same QM to get best result.

If that is true: when I know the QM of my MPEG2 source (logged by DGIndex), can I convert it somehow to AVC format to use it in x264 and to attempt to have optimal quantization matrix for given video?

bond
12th December 2005, 16:37
no, avc and mpeg-2/4 asp cqm are different

Sharktooth
12th December 2005, 16:38
That statement is not true for the following reasons:
a) Let's assume who encoded the material chosen the wrong matrix. It dropped important frequencies reducing the quality. If you re-apply the same matrix it will drop again important frequencies reducing the quality again.

b) If the matrix was dropping low frequencies it could produce ringing, and if you reapply it it will produce even more ringing.

c) Using the same matrix for re-encoding will drop the same frequencies ranges (as in "a)") as for the first encode leading to a more visible threshold between dropped frequencies and less dropped frequencies.

d) etc... :)

AVC has a new format for custom matrices though... so you can't do it anyway...

redfordxx
12th December 2005, 16:51
AVC has a new format for custom matrices though... so you can't do it anyway...
no, avc and mpeg-2/4 asp cqm are differentThat's why I wrote CONVERT --- not COPY.
Other usage could be,if there is some favorite XviD matrix,to prepare fast similar AVC CQM.

redfordxx
12th December 2005, 17:35
Let's assume who encoded the material chosen the wrong matrix. It dropped important frequencies reducing the quality. If you re-apply the same matrix it will drop again important frequencies reducing the quality again.I guess the idea is, when the frequencies are dropped, you can't drop it again...
Choosing different matrix, will drop more frequencies...

As little (or maybe wrong) as I understand of DCT says to me:

let's name variables:
Bx_orig=8x8 block in original movie
QMx=quant matrix
Cx_orig=DCT coeficients w/o quantization
Cx_quant=quantized DCT coeficients
Cx_new=new, dequantized DCT coeficients
Bx_new=8x8 block in decoded movie
Qpx=quantizer
x=1 or 2 for first and secodn encode

Functions:
DCT(B)=DC transformation on block B of a movie
Quant(C,Q,Qp)=Quantization of coefficients C, with Qmatrix Q and quantizer Qp
DeQuant(C,Q,Qp)=reconstruction of the quant coefficients based on compressed coef's C, Qmatrix Q and quantizer Qp
IDCT(C)=reconstruction of a block in spatial domain

I think encoding is:
C1_orig=DCT(B1_orig)
C1_quant=Quant(C1_orig,QM1,Qp1)
And decoding is:
C1_new=DeQuant(C1_quant,QM1,Qp1)
B1_new=IDCT(C1_new)

For second encode:
C2_orig=DCT(B2_orig)
C2_quant=Quant(C2_orig,QM2,Qp2)
C2_new=DeQuant(C2_quant,QM2,Qp2)
B2_new=IDCT(C2_new)

I was refering to reencoding the decoded movie i.e.:
B2_orig=B1_new
then
C2_orig=DCT(B1_new)=DCT(IDCT(C1_new))=C1_new
so
If QM1=QM2 and Qp1>=Qp2 then C2_quant=C1_quant

In theory when codec1=codec2, this could work. In real world there would be some inaccuracy but still might help.

If I am completely wrong, let's just end the discussion. If I am little wrong pls correct me.

foxyshadis
12th December 2005, 22:06
Even if you were to turn off many options and replicate the matrices exactly, you would still have to contend with different motion vectors, so it would only work on I frames (or no-motion parts of P/B frames).

It works in JPEG because there's no mtion vectors, but unless you forced the ASP/AVC encoder to use the same motion vectors, quantizers, and matrices in the same way, it wouldn't work. And if you did, you'd have just replicated the original with no bitrate savings!