Title: H.264 Rate-Distortion Optimization and Rate Control
1H.264 Rate-Distortion Optimization and Rate
Control
- MC Course, 2009
- Ref
- Siwei Ma, Wen Gao, and Yan Lu,
- Rate-Distortion Analysis for H.264/AVC Video
Coding and its Application to Rate Control, IEEE
TRANSACTIONS ON CIRCUITS AND SYSTEMS FOR VIDEO
TECHNOLOGY, VOL. 15, NO. 12, pp. 1533-1544,
DECEMBER 2005.
2Rate-distortion Optimization
- Minimize distortion D, subject to a constraint
Rd, on the number of bits used Rd. - min D, subject to R lt Rd.
- Rate-distortion optimized selection, given target
rate - Minimize the distortion, subject to the target
rate constraint - Dn(mn) distortion of the nth MB using mode mn
- The optimal mode is such that each MB working at
the same RD slope - The optimal mode in each MB is such that the
resulting RD slope is the same among
different MBs.
3H.264 Rate Control
- H.264/AVC test model Draft ISO/IEC 14
496-52002/PDAM6, ISO IEC TC JTC 1/SC29 N5821,
2003. - based on the R-D model in VM8
- Recommendation H.264 does not (at present)
specify a rate control algorithm - Ma, Gao, and Lu the quantization scheme in
H.264/AVC has been significantly changed, which
leads to the nonlinear relation between the
quantization parameter and the true quantization
stepsize. Therefore, it is highly desirable to
develop a more efficient R-D model for the rate
control in H.264/AVC encoder.
4Hypothetical Reference Decoder
- H.264 hypothetical reference decoder (HRD)
guarantee that the buffers never overflow or
underflow - rate allocation allocate proper bits to each
coding unit according to the buffer status - quantization parameter adjustment how to adjust
the encoder parameters to properly encode each
unit with the allocated bits - Find the relation between the rate and the
quantization parameter
5The Relation between QSTEP and QP
- In H.264/AVC, the relation between QSTEP and QP
is - QSTEP 2 (QP-4)/6.
6The Relation between PSNR and the quantization
parameter QP
- The Relation between PSNR and the quantization
parameter QP is - where l and b are the constants.
7The Relation between PSNR and the quantization
parameter QP, Ma, Gao, and Lu
- is the estimated number of coded bits of a
macroblock - SADi is the SAD of a motion-compensated
macroblock - t I, P, B
- The first item reflects the bits used to code the
transform coefficients. - The second item is the bits used to code the
header information of a macroblock.
8Some Rate Control Models
- TM5 R(QP) X/QP, X is a constant
- VM8
- TMN8
- MADi is the mean absolute difference of a
residual macroblock - Xi mode parameters
- A, K, and C constants
- ?i2 is the variance of residual coefficients in a
macroblock.
9MPEG-4 Scalable Rate Control
- MPEG-4 Annex
- based on VM8
- appropriate for a single video object (a
rectangle VO that covers the entire frame) and a
range of bit rates and spatial/temporal
resolutions - target bit rate for a certain number of frames,
(long delay of course) - Q quantizer step size
- S is the mean absolute difference of a residual
frame
10SRC Algorithm
- Rate control process
- Calculate the target bit rate Ri, based on the
number of frames, the number of available bits,
the maximum acceptable buffer contents and the
estimated complexity of frame i. - Compute the quantizer step size Q, (to be applied
to the whole frame). Calculate S for the complete
residual frame and solve () to find Q. - Encode the frame
- Update the model parameters X1 and X2 based on
the actual number of bits generated for frame i. - The MB level version of SRC (low delay)
11TMN8 Algorithm
- Rate control process
- Measure ?i, the variance of residual coefficients
in a macroblock. - Calculate QPi
- Encode MBi
- Update the model parameters K and C based on the
actual number of bits generated for MBi. - TMN8 is effective at maintaining good visual
quality with a small encoder output buffer,
keeping coding delay to a minimum.
12H.264 RDO and HRD
- H.264 RDO and HRD closely related to rate
control - RDO
- MB modes INTRA 4?4, INTRA 16?16, INTER 16?16,
INTER 16?8, INTER 8?16, INTER 8?8, INTER 8?4,
INTER 4?8, INTER 4?4, SKIP and DIRECT. - Lagrangian method
- Optimal mvs for inter (or intra) and optimal
coding modes for blocks - Optimal bit allocation for mvs and residuals
13H.264 R-D Optimization, Ma, Gao, and Lu
For a block in an inter frame, the
rate-constrained motion estimation is first done
to find the optimal motion vector by minimizing
s the original video signal, c the coded video
signal
Multiple-reference prediction
14H.264 R-D Optimization, Ma, Gao, and Lu
- Afterwards, the rate-constrained mode selection
is performed to choose the optimal coding mode by
minimizing - Langrage multipliers ?s have the following
relation with QP, m constant - With the different QP, the different motion
vectors and modes might be selected.
15H.264 Hypothetical Reference Decoder
- Terminology
- CPB Coded Picture Buffer
- b(n) the size in bits of picture n
- tai (n) the time when the first bit of picture n
enters the CPB, the initial arrival time of
picture n - taf (n) the time when the last bit of picture n
enters the CPB, the final arrival time of picture
n, and - tr(n) is the time when the picture n is removed
from the CPB
R the bit rate at which the CPB is filled.
16H.264 Hypothetical Reference Decoder
Packetization, and others One packet per frame
this case
tc time of a clock tick
the earliest time when picture n can reach the
buffer
initial_CPB_removal_delay represents the delay
between the time when the first bit of the coded
data arrives in the CPB and the time when the
first time removal of coded data from the CPB.
17H.264 Hypothetical Reference Decoder
- access unit one coded picture or slice data
partition
18H.264 Hypothetical Reference Decoder
To ensure that the CPB does not overflow or
underflow, Ln the lower bound of rate
This means that picture n must be in the buffer
when it is removed from the buffer.
19H.264 Hypothetical Reference Decoder
R the bit rate at which the CPB is filled.
CPB should neither overflow nor underflow if
Where bet and tet denote the bit equivalent
of a time t and the time equivalent of a number
of bits b, respectively, and
Usually the bits allocated to a picture are
clipped to ?Ln, ?Un, where ? ? 1.0 and ? ? 0.9.
20Rate-control Algorithm, Ma, Gao, and Lu
- Bit allocation In this step, a target bit is
allocated to each picture in a group of pictures
(GOP) - Initialization for the current macroblock
- where X0t is global complexity measure for a
picture as defined in TM5, R0t is the coded bits
of the picture, SAD0t is the average SAD of all
macroblocks in the picture, BHead is the average
header bits for a macroblock, including motion
and mode information, and BCoeff is the bits used
to code luminance and chrominance coefficients.
TM5 R(QP) X/QP
QSTEP 2 (QP-4)/6
21Rate-control Algorithm, Ma, Gao, and Lu (2)
- First RDO-based coding mode selection
- If the current macroblock is the first MB in the
frame, QP is set to be the average quantization
parameter of the previous frame QPprev
otherwise, we use - Second RDO-based coding mode selection
- Calculate SADi in terms of the selected coding
mode and then compute a new quantization
parameter QP using SADi in the same way as Step
3. - Counter updating
- R-D model parameter updating
Mi the number of remaining uncoded MBs Ti the
number of available bits for encoding the
remaining uncoded MBs
22Rate-control Algorithm, Ma, Gao, and Lu (3)
- new R-D model the relationship between the
quantization parameter and the true quantization
stepsize is no longer linear. - proposed a new rate-distortion (R-D) model by
utilizing the true quantization stepsize and then
develop an improved rate-control scheme for the
H.264/AVC encoder based on this new R-D model. - The algorithm performs one-pass operation at
frame level and a partial two-pass operation at
the macroblock level. Since the second RDO-based
coding model selection in Step 4 is a conditional
operation, the percentage of such macroblocks can
be controlled by parameter ? consequently, the
computing complexity is controllable as well.
23(No Transcript)