The quantification method of MPEG4

Source: Internet
Author: User

MPEG4 mainly supports two kinds of quantization methods, one is H.263, the other is MPEG4.

Because the quantization method of h.263 is simpler, the H.263 method is used when MPEG4 video coding on embedded.

The main differences between the two methods of quantification:

The quantization-weighted matrix is introduced in the MPEG4 quantization method, so the quantization is more fine.

QP: The quantization parameter, actually is the index value of quantization step q_step, they satisfy certain correspondence relation. As in the H.263 quantization method, the actual value is divided by 2*QP, so the quantization step here corresponds to QP with twice times the QP.

In the process of inverse quantization, the median value of two adjacent levels is generally taken as the decision level, so there is a coefficient of 1 in inverse quantization of h.263.

The following is the C code in XviD that is quantified in h.263 way:

1/*****************************************************************************
2 *
3 * XVID MPEG-4 VIDEO CODEC
4 *-MPEG4 quantization H263 implementation-
5 *
6 * Copyright (C) 2001-2003 Peter Ross <pross@xvid.org>
7 *
8 * This program was free software; You can redistribute it and/or modify
9 * It under the terms of the GNU general public License as published by
Ten * the free software Foundation; Either version 2 of the License, or
One * (at your option) any later version.
12 *
Distributed in the hope that it'll be useful,
* but without any WARRANTY; Without even the implied warranty of
merchantability or FITNESS for A particular PURPOSE. See the
* GNU general public License for more details.
17 *
* You should has received a copy of the GNU general public License
* Along with the program; If not, write to the free software
Foundation, Inc., Temple Place, Suite Boston, MA 02111-1307 USA
21 *
* $Id: quant_h263.c,v 1.8 2004/03/22 22:36:24 Edgomez EXP $
23 *
24 ****************************************************************************/
25
#include ". /global.h "
#include "Quant.h"
28
29/*****************************************************************************
* Global Function pointers
31 ****************************************************************************/
32
*/* Quant */
Quant_intrafuncptr Quant_h263_intra;
Quant_interfuncptr Quant_h263_inter;
36
Notoginseng */dequant */
Quant_intrafuncptr Dequant_h263_intra;
Quant_interfuncptr Dequant_h263_inter;
40
41/*****************************************************************************
* Local Data
43 ****************************************************************************/
44
*/* divide-by-multiply table
* A + bit shiting is enough in the case */
47
#define SCALEBITS 16
#define FIX (x) ((1L << scalebits)/(x) + 1)
50
51StaticConst uint32_tMULTIPLIERS[32] =
52 {
0, Fix (2), fix (4), fix (6),
Fix (8), fix (14), Fix (
Fix (22), fix (+), for Fix,
Fix (30), fix (for. fix),
Fix (38), fix (+), and fix (
Fix (46), fix (for.),.
Fix (54), fix (for. fix),
Fix (62), fix (+) (+)
61};
62
63/*****************************************************************************
* Function Definitions
65 ****************************************************************************/
66
*/* Quantize Intra-block
68 */
69
70uint32_t
Quant_h263_intra_c (int16_t* Coeff,
72Const int16_t* Data,
73Constuint32_tQuant
74Constuint32_tDcscalar,
75Constuint16_t* mpeg_quant_matrices)
76 {
77Constuint32_tmult = Multipliers[quant];
78Constuint16_tQuant_m_2 = quant << 1;
79intI
80
Bayi Coeff[0] = Div_div (Data[0], (int32_t) dcscalar);
82
83 for(i = 1; i <; i++) {
84int16_tAclevel = Data[i];
85
86if(Aclevel < 0) {
Aclevel =-aclevel;
88if(Aclevel < Quant_m_2) {
Coeff[i] = 0;
90Continue;
91}
Aclevel = (Aclevel * mult) >> scalebits;
Coeff[i] =-aclevel;
94}Else{
95if(Aclevel < Quant_m_2) {
Coeff[i] = 0;
97Continue;
98}
Aclevel = (Aclevel * mult) >> scalebits;
Coeff[i] = Aclevel;
101}
102}
103
104return(0);
105}
106
107
108/* Quantize Inter-block
109 */
110
111uint32_t
Quant_h263_inter_c (int16_t* Coeff,
113Constint16_t* Data,
114Constuint32_tQuant
115Constuint16_t* mpeg_quant_matrices)
116 {
117Constuint32_tmult = Multipliers[quant];
118Constuint16_tQuant_m_2 = quant << 1;
119Constuint16_tQuant_d_2 = quant >> 1;
120uint32_tsum = 0;
121uint32_tI
122
123 for(i = 0; i <; i++) {
124int16_tAclevel = Data[i];
125
126if(Aclevel < 0) {
127 Aclevel = (-aclevel)-quant_d_2;
128if(Aclevel < Quant_m_2) {
129 Coeff[i] = 0;
130Continue;
131}
132
133 Aclevel = (Aclevel * mult) >> scalebits;
134 Sum + = Aclevel; /* sum + = |aclevel| */
135 Coeff[i] =-aclevel;
136}Else{
137 Aclevel-= quant_d_2;
138if(Aclevel < Quant_m_2) {
139 Coeff[i] = 0;
140Continue;
141}
142 Aclevel = (Aclevel * mult) >> scalebits;
143 sum + = Aclevel;
144 Coeff[i] = Aclevel;
145}
146}
147
148return(sum);
149}
150
151
*/* dequantize Intra-block & clamp to [ -2048,2047]
153 */
154
155uint32_t
156 Dequant_h263_intra_c (int16_t* Data,
157Constint16_t* Coeff,
158Constuint32_tQuant
159Constuint32_tDcscalar,
160Constuint16_t* mpeg_quant_matrices)
161 {
162Constint32_tQuant_m_2 = quant << 1;
163Constint32_tQuant_add = (Quant & 1 quant:quant-1);
164intI
165
166 Data[0] = coeff[0] * dcscalar;
167if(Data[0] <-2048) {
168 Data[0] =-2048;
169}Elseif(Data[0] > 2047) {
Data[0] = 2047;
171}
172
173 for(i = 1; i <; i++) {
174int32_tAclevel = Coeff[i];
175
176if(Aclevel = = 0) {
177 Data[i] = 0;
178}Elseif(Aclevel < 0) {
179 Aclevel = quant_m_2 *-aclevel + quant_add;
Data[i] = (aclevel <= 2048?-aclevel:-2048);
181}Else{
182 Aclevel = quant_m_2 * aclevel + quant_add;
183 Data[i] = (aclevel <= 2047? aclevel:2047);
184}
185}
186
187return(0);
188}
189
190
191
192/* Dequantize Inter-block & clamp to [ -2048,2047]
193 */
194
195uint32_t
196 Dequant_h263_inter_c (int16_t* Data,
197Constint16_t* Coeff,
198Constuint32_tQuant
199Constuint16_t* mpeg_quant_matrices)
200 {
201Constuint16_tQuant_m_2 = quant << 1;
202Constuint16_tQuant_add = (Quant & 1 quant:quant-1);
203intI
204

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.