Beruflich Dokumente
Kultur Dokumente
HEVC/H.265
Prepared by Shevach Riabtsev
+ Residual Bit-Stream
Ref
Ref
Ref T&Q CABAC
Motion -
Est. MVs
Input Video
Inter
Motion
Comp.
Reference samples Intra/Inter MVs/Intra modes
Mode Intra Decision
Pred.
Intra
Quantized
Intra
Est. residuals
+
Ref.
Ref
Ref SAO Deblk.
Reconstructed
Q-1& T-1
Ref +
DPB SAO Params
Filter Control Est. SAO params
Notes:
In addition to AVC/H.264, SAO and SAO Params Estimation added.
The block SAO Params Est. can be executed right after deblocking or
right after the reconstruction (with negligible penalty) as shown in the figure.
HEVC similarity with AVC/H.264 allows quick upgrading of existing AVC/H.264 solutions
to HEVC ones.
Bitstream Structure
Slice
VPS SPS PPS Slice Data * * * *
Header
Picture #1
Slice Slice
Slice Data Slice Data * * * *
Header Header
Picture #k
As in H.264/AVC the byte stream format is also specified in HEVC, where each
NAL unit is delimited by start-code (0x000001).
Notice that each stream must commences with the 4-bytes start code (0x00000001) at least.
The 4-bytes start code at the very beginning of a stream enables a decoder to achieve
byte boundary and not skip over the first NAL (provided that the decoder enter to the stream
in bit-aligned position and not byte-aligned one).
High-Level Syntax ( VPS/SPS)
VPS dedicated to convey information that is common for multiple layers, i.e.
each layer refers same VPS
Notes:
There is a duplication of some information between SPS and VPS (e.g. profile_idc).
Potential Usage of Some SPS Parameters
Slice Header - conveys information that can change from slice to slice
POC, Slice type
Prediction weights
Deblocking parameters
Tiles Entry points
Reference picture lists: the list of reference pictures in DPB is explicitly signaled in
the slice header (unlike to AVC/H.264 where MMCO or sliding window mode is used).
Not mentioned pictures in the list are marked as unused for reference and should be
removed from DPB respectively. Its worth mentioning that the explicit signaling of the
reference pictures enhances error resilience. Indeed, if a decoder detects that one of
the mentioned pictures is not exist in DPB then the decoder derives that this picture got
lost. Maximal number of reference indexes is 15 (unlike 16 in AVC/H.264).
Selected Picture Types (IDR, CRA)
Leading pictures
CRA
0 1 2 3 4
CRA
0 2 3 1 4
Selected Picture Types (RADL, RASL)
64x64 CTU
CTU Syntax (2)
All CUs in a CTU are encoded (traversed) in ZScan (depth-first) order, this order
makes top and left samples to be available (casual) in most cases :
64x64 CTU
The figure taken:
Benjamin Bross: Relax it's only HEVC, WBU-ISOG Forum, European Broadcast Union, Geneva,
Switzerland, November 28, 2012,
CTU Syntax (3)
Formally CTU specifies quad-tree traversed in depth-first order
CTU
CU Syntax (1)
Prediction Block (PB):
Each CB is partitioned in 1, 2 or 4 prediction blocks (PBs).
Intra:
Inter:
Notice that if CU size is 8x8 assymetric partitions are disabled (in order to reduce
complexity). I think that assymetric partitions could be disabled for 16x16 sizes too.
CU Syntax (3)
Notes:
The smallest luma PB size is 4 8 or 8 4 samples (where 4x8 and 8x4 are
permitted only for uni-directional predictions, no bi-prediction < 8x8 allowed).
Chroma PBs mimic corresponding luma partition with the scaling factor 1/2 for 4:2:0.
Each luma CB can be quadtree partitioned into one, four or larger number of TBs.
The number of transform levels is controlled by max_transform_hierarchy_depth_inter
and max_transform_hierarchy_depth_intra.
Example.
CB divided into two TB levels (the block #1 is split into four blocks):
1,0 1,1
0
1,2 1,3
0 2 3
2 3
For the range transform block sizes from 8x8 to 32x32 we evaluate RD cost 21
times:
1 {32x32} + 4 {16x16} + 16 {8x8} = 21
For the range transform block sizes from 4x4 to 32x32 (intra CU) we evaluate RD
cost 53 times:
1 {32x32} + 4 {16x16} + 16 {8x8} + 32 {4x4} = 53
CU Syntax (6)
Notes
2x2 TBs are disabled (minimal TB size is 4x4). How handle chroma blocks in
4:2:0 format if luma TB is 4x4?
0 1 Cb
4x4 4x4 4x4
2 3 Cr
4x4 4x4 4x4
Restrictions/Constraints
a) HEVC disallows 16x16 CTBs for level 5 and above (4K TV).
Motivation:
16x16 CTBs add overheads for decoders to target 4K TV:
Numeric Example:
Lets take CtbSizeY=16 (as in AVC/H.264). Then RawCtuBits = 16*16*8+2*8*8*8 = 3072,
the maximal CTB bit-size is 5*3072/3 = 5120 bits ( much more than the corresponding
3200 bits threshold in AVC/H.264).
Note on maximal CTU bit-size and worst-case CABAC performance
CABAC decoding (as well as encoding) contains the renormalization stage (due to finite
arithmetic). The renormalization procedure is time consuming since it contains a while-loop
and several if-else statements inside the loop.
The number of calls the renormalization routine for a CTU is less or equal than the CTU bit-
size (because during the renormalization at least one bit is read from bit-stream).
Therefore if the worst case CTU bit-size is 5120 bits then the decoder has to invoke the
renormalization at most 5120 times, i.e. 5120 times in the worst case.
From point of CABAC HW design the execution of renormalization the 5120 times is a
serious performance bottleneck.
Note on Interlace Coding
No correction MVX[1] (or y-component of MV) if current and reference pictures are in
different polarity (top-bottom or bottom-top).
Field pictures are signaled by an SEI message (pic_timing) for every picture in the sequence.
If progressive and interlace streams are spliced together then its required to insert a new
sequence start to switch from progressive coding to interlaced one (or vice versa).
In H.264/AVC PAFF mode can be used to diminish I-frame bitrate peaks: I-frame is divided
into two field pictures where the top field picture is coded as I-picture while the bottom picture
is coded as P-picture. Consequently total bits produced by two I-P field pictures is expected
to be smaller than the bits generated by single I-frame.
Because H.265/HEVC does not support PAFF the above trick cant be applied to cope with I-
frame bitrate peaks.
Note on Picture Boundaries
As per the standard the picture boundaries are defined in units of the minimum luma CB size
(MinCbSizeY):
As a result, at the right and bottom edges of the picture CTBs may exceed the picture
boundaries. Data outside of the picture is not coded, therefore quadtree on the right and
bottom edges are pruned respectively.
Pls. see the following slide (granted by John Funnel from Parabola) for illustration:
Note on Reference Picture Signaling
Reference picture set (RPS) is signaled within the slice header of non-IDR pictures. Each
reference picture in RPS is identified by its POC.
Unlike to AVC/H.264, no information from previous pictures is needed to parse RPS and to
populate the reference list.
If a picture is declared in RPS and not present in DPB (Decoded Picture Buffer) then a
decoder should derive that the picture is lost.
To minimize the slice header overhead, up to 64 different RPS can be signaled in SPS and
the slice header can contain a reference to one of these RPS.
Inter Prediction/ Motion
Compensation
Overview
Motion Compensation consists of three steps:
Fetch - reference data, padding is applied if reference block outside picture boundaries.
Weighted Prediction
Weighted
Fetch Interpolation Prediction
(optional)
padding
Luma Interpolation Details (1)
Fractional interpolation for luma samples uses 8-tap filter for both half-pels and quarter-pels
(although some positions actually reduced to 7-tap filter).
Notice that in AVC/H.264 the motion compensation is executed in two serial stages for each
direction (horizontal and vertical):
6-tap filter for half-pels
bilinear filter for quarter-pels
So, AVC/H.264 gives the same complexity as HEVC 8-tap filter but two-stage latency (HEVC
motion compensation filter can be executed in one stage).
In HEVC luma interpolation consists of two stages: horizontal and vertical filtering.
Intermediate results after the horizontal stage are within16-bits accuracy (even if bitDepth>8
then corresponding right shift is applied to keep 16-bits dynamic range).
After the second stage, the results are right-shifted by 6 for bitDepth=8 (unlike to AVC/H.264
no rounding is applied) to reduce the dynamic range to 16 bits.
If bitDepth is 8 (i.e. 8-bits samples) then the order of interpolation is irrelevant. One can
execute firstly the vertical filtering and then horizontal one and vice versa.
Interpolation Flow Chart (w/o weighted prediction)
>>2
10 bits per pix
Merge
>>2
10 bits per pix
Luma Interpolation Details (2)
In the following slides we illustrate as positions a0,0 through r0,0 are specified.
A -1, -1 A 0, -1 a 0, -1 b 0, -1 c 0, -1 A 1, -1 A 2, -1
Quarter-pels a0,0, c0,0, d0,0, n0,0 and half-pels b0,0, h0,0 are derived from nearest integer
positions.
The quarter-pels a0,0, c0,0, d0,0, n0,0 are derived by the 7-tap filter and the half-pels b0,0, h0,0
by 8-tap filter.
a0,0 , b0,0 and c0,0 are computed by horizontal filtering, while d0,0 , h0,0 and n0,0 by vertical
filtering.
A -1, -1 A 0, -1 a 0, -1 b 0, -1 c 0, -1 A 1, -1 A 2, -1
Half-pel j0,0 is derived by applying the 8-tap filter vertically to nearest half-pels: b0,3 , b0,2 ,
b0,1 , b0,0 , b0,1 , b0,2 , b0,3 , b0,4 . Notice that j0,0 can be determined only after b0,0 has been
computed (see the previous slide).
Quarter-pels e0,0 and p0,0 are derived by applying the 7-tap filter vertically to nearest quarter-
pels. Notice that e0,0 and p0,0 can be determined only after a0,0 has been computed (see the
previous slide).
A - 1, -1 A 0, -1 a 0, - 1 b 0, - 1 c 0, - 1 A 1, -1 A 2, - 1
Quarter-pel i0,0 is derived by applying the 8-tap filter vertically to nearest quarter-pels: a 0,3,
a0,2, a0,1, a0,0, a0,1, a0,2, a0,3, a0,4
Quarter-pel k0,0 is derived by applying the 8-tap filter vertically to nearest quarter-pels: c 0,3,
c0,2, c0,1, c0,0, c0,1, c0,2, c0,3, c0,4
A -1, - 1 A 0, - 1 a 0, - 1 b 0, - 1 c 0, - 1 A 1, - 1 A 2, -1
Quarter-pels f0,0 , g0,0 , q0,0 , r0,0 are derived by applying the 7-tap filter vertically to the
nearest quarter-pels.
A -1, - 1 A 0, - 1 a 0, - 1 b 0, - 1 c 0, - 1 A 1, - 1 A 2, -1
The fractional interpolation for the chroma is similar to the luma with pel and 4-tap filters.
The filter coefficients depends on position, e.g. for ab00 the coefficients are [ -2,58,10,-2].
Notes/Conclusions
1. Luma interpolation can be performed in two serial stages: half-pel and quarter-
pel.
Maximal value of b0,0 is 88*255 = 22440, the minimal value is -24*255 = -6120. The same
limits are also correct for h0,0 .
Maximal value of a0,0 is 80*255 = 20400, the minimal value is -16*255 = -4080. The same
limits are also correct for c0,0, d0,0, n0,0 .
So, the values of a0,0, c0,0, d0,0, n0,0 , b0,0, h0,0 are within 16 bits.
Dynamic Range Estimation (2)
Second step of interpolation (when neighboring half-pel and quarter-pel samples are uses):
Taking into account that a0,k is in the range [-4080 .. 20400] the expression in the parenthesis
gives the following limits:
-80*4080= - 326400 a0,3 + 4*a0,2 10*a0,1 + 58*a0,0 + 17*a0,1 5*a0,2 + a0,3 80*20400=1632000
After shifting by 6 the dynamic range reduced to 16 bits: -5100 e0,0 25500
j0,0 = ( b0,3 + 4*b0,2 11*b0,1 + 40*b0,0 + 40*b0,1 11*b0,2 + 4*b0,3 b0,4 ) >> 6
Taking into account that b0,k is in the range [-6120 .. 22440] the expression in the parenthesis
gives the following limits:
-88*6120 = - 538560
b0,3 + 4*b0,2 11*b0,1 + 40*b0,0 + 40*b0,1 11*b0,2 + 4*b0,3 b0,4
88*22440=1974720
As in the case with e0,0 the dynamic range in calculation of j0,0 is increased to 22 bits. After
the shift by 6, the dynamic range is reduced to 16 bits.
Intra Prediction
Overview
33 angular predictions for both luma and chroma and two non-directional
predictions (DC, Planar).
Unlike to AVC/H.264 three most probable modes: MPM0, MPM1 and MPM2
are considered. The following figure reveals the logic for derivation of MPMs:
Note on Most Probable Mode (MPM)
Encoder side:
Otherwise, the index of the current luma intra prediction mode excluding
the three MPMs is transmitted to the decoder by using a 5-bit fixed length
code (rem_intra_luma_pred_mode).
Note:
If region is smooth (flat) then each of 35 intra modes provides similar result and can be
selected as best.
Coding & Derivation Luma Intra Prediction Mode (3)
Decoder side:
Luma IntraPredMode
intra_chroma_pred
0 26 10 1 X ( 0 <= X <= 34 )
_mode
0 34 0 0 0 0
1 26 34 26 26 26
2 10 10 34 10 10
3 1 1 1 34 1
4 0 26 10 1 X
Because allowable chroma modes are constrained by the corresponding luma mode, its
challenging to execute in parallel searching for best luma and chroma modes (like in
AVC/H.264). In other words one firstly should look for the best luma mode and then the
best chroma mode.
Note:
If intra_chroma_pred_mode=0 then chroma prediction mode is equal to
luma intra prediction mode of the top-left luma PB within a luma CB
Implementation Angular Intra Prediction (1)
At most 4N+1 neighbor pixels are required. In contrast to H.264/AVC, below-left
samples are exploited in HEVC. Wide range of prediction block sizes (from 4x4 to
64x64) makes availability of bottom-left samples to be more frequent event than in
H.264/AVC. Missing reference samples are generated by repetition of the closest
available sample in the reference line.
Top CTU
Top-left CTU
16x16
8x8 8x8
Top-left predictor Top predict. Top-right predictors
Example Case TB < PB : let 8x8 prediction block (PB) comprised from four 4x4
transform blocks (TB):
TB0 TB1
4x4 4x4
TB2 TB3
4x4 4x4
Step 1: Predict samples for TB0 (the predictors are outside the current PB), inverse
transform, reconstruct.
Step 2: Predict samples for TB1 where the left predictors are reconstructed samples of
TB0, inverse transform, reconstruct.
Step 3: Predict samples for TB2 where the top and top-right predictors are
reconstructed samples of TB0 and TB1, inverse transform, reconstruct.
Step 4: Predict samples for TB3 where all predictors are reconstructed samples of
TB0-TB2, inverse transform, reconstruct.
Implementation Angular Intra Prediction (3)
The parameter iIdx and iFact denote the index and the multiplication factor
determined by the intra prediction mode (can be extracted via LUTs).
The weighting factor iFact remains constant across predicted row or column
that facilitates SIMD implementations of angular intra predictions.
Planar Mode
In AVC/H.264, the plane intra mode requires two multiplications per sample
predSamples[ x ][ y ] = ( ( nT 1 x ) * p[ 1 ][ y ] + ( x + 1 ) * p[ nT ][ 1 ] +
( nT 1 y ) * p[ x ][ 1 ] + ( y + 1 ) * p[ 1 ][ nT ] + nT ) >> ( Log2( nT ) + 1 )
So, HEVC planar mode is more complex than in AVC/H.264. Actually, the
planar mode is an average of two linear predictions:
( nT 1 x ) * p[ 1 ][ y ] + ( x + 1 ) * p[ nT ][ 1 ]
( nT 1 y ) * p[ x ][ 1 ] + ( y + 1 ) * p[ 1 ][ nT ]
Effective and complex motion data prediction techniques have been adopted in HEVC in
order to reduce motion data portion in the stream. HEVC supports two modes:
2) AMVP (Advanced Motion Prediction) inferred only motion vector (MV) predictors and
MV difference is signaled.
Unlike other standards (e.g. AVC/H.264), the HEVC adopted the competitive motion vector
prediction for both AMVP and merge modes, i.e. several candidates are competing for the
prediction and the best candidate is signaled in the stream.
In both prediction modes, the set of candidates can include a temporal candidate (or co-
located candidate) from a pre-defined reference picture. Unlike to H.264/AVC, in HEVC
enables more flexibility in selection of the co-located reference, it is not necessarily the first
reference picture in L0 or L1. The co-located reference is signaled in slice header by
collocated_ref_idx.
Temporal MV prediction in both prediction modes improves error resilience. On the other hand
an additional storage of co-located MVs of reference frames is required.
In earlier versions of HEVC, a candidate removed if any of previous candidate has the same
motion. When NumMergeCands=5 the detection of all redundant candidates requires 10
comparisons per PU.
In the final HEVC version in order to reduce complexity of the merge list generation, only 5
comparisons (arcs in the figure below) are executed (instead of 10) for removing duplications.
B2 B1 B0
comparison
A1
A0
Note:
Due to limiting of comparisons and exempting the temporal candidate from prunning process,
redundant candidates (i.e. B0=B2) can appear in the merge list.
Merge Mode: Additional Candidates
If merge list is not full (i.e. #candidates < NumMergeCands) then additional virtual
candidates appended. So, the merge list is never empty.
Merge Mode: List Construction in Encoding
Prunning Process
remove duplicates (restricted)
If merge
list full?
No
Select candidate
for encoding
Merge Mode: List Construction in Decoding
CABAC
index
If merge_idx<
current list size?
No
Motion vector is predicted from five spatial neighbors: B0, B1, B2, A0, A1 (see the figure
below) and one co-located temporal MV. Only two motion candidates are chosen among six
neighbors and the selected predictor is explicitly signaled (mvp_lx_flag).
TBR
If both candidates are available and have the same motion data, one is
excluded
If one of the above candidates is not available or excluded then the temporal
MV (colocated) is used unless the temporal prediction mode disabled: the first
available from TBR and TCT . Notice that if TBR is out of CTU boundary its
considered as unavailable.
The standard supports 32x32, 16x16, 8x8 and 4x4 DCT-like transforms and 4x4 DST-like
transform. Notice that DST-like 4x4 transform is allowed only for intra mode.
Each transform is specified by 8-bits signed digital transform matrix T. To perform all
transform operations its required 32-bits precision.
b) Scaling and clipping of Z to guarantee that the output values are within 16-bits.
c) Y = Z T
Notice that in encoder architecture the step (c) can be coupled with quantization: once first
row of Y completed the quantization of the first row is started.
Transform Implementation
Notice AVC/H.264 where transform coefficients are dyadic in 4x4 case and near dyadic (i.e.
from the form 2^n, 2^n-1, 2^n+1) in 8x8 case and hence AVC/H.264 transform can be
multiplication-free.
In HEVC transform operations are not multiplication-free. Indeed, let the multiplication takes
3 cycles, shift or addition 1 cycle . Therefore if all coeffs are near dyadic we can use only
shifts and additions, otherwise we need a multiplier (because the alternative of shifts and
adds hurts performance).
As well as in AVC/H.264 the transforms in HEVC are separable and can be performed as
sequence of two 1D transforms (vertical and horizontal):
As well as in previous standards HEVC DCT works well on flat areas, but fails on areas with
noise, contours and other peculiarities of the signal.
HEVC DCT is efficient for big size of blocks but it looses efficiency on smaller blocks.
Beginning from 16x16 transforms visual artifacts are noticeable. The more the transform size
the more artifacts are observable. Deblocking can reduce artifacts on TB boundaries, while
artifacts inside a TB can be reduced only by SAO. Therefore its recommended to apply SAO
when large transform sizes (32x32) are used.
HW Aspects of Transform Implementation 1D 8x8 case
Pc permutation matrix
HW Aspects of Transform 1D 8x8 case (2)
29 55 74 84
74 74 0 74
84 29 74 55
55 84 74 29
Motivation:
Intra prediction is based on the top and left neighbors. Prediction accuracy is more
for the pixels located near to top/left neighbors than those away from it. In other
words, residual of pixels which are away from the top/left neighbor usually be larger
then pixels near to neighbors. Therefore DST transform is more suitable to code
such kind of residuals, since DST basis function start with low and increase further
which is different from conventional DCT basis function.
Reported 4x4 DST provides some performance gain, about 1%, against DCT. For
bigger sizes the gain is negligible.
According to JCTVC-G757:
The above results are obtained on x86 and ARM with SIMD operations (MMX/SSE on
x86, and NEON on ARM).
4.59 cycles per sample for 32x32 can be a bottleneck on some platforms.
If you wish to avoid performance issues on decoder's side it's would be better not use 32x32
transform and always split 32x32 CU into four 16x16 TBs or even into eight 8x8 TBs.
Notice that if 32x32 TBs is not used, its recommended to consider to disable SAO since
ringing artifacts and mosquito noise are mainly present in large TB sizes.
Entropy Coding
Overview
HEVC specifies only one entropy coding method CABAC, comparing to two
CABAC and CAVLC as in H.264/AVC.
Each Transform Block (TB) is divided into 4x4 sub-blocks (coefficient groups).
Processing starts with the last significant coefficient and proceeds to the DC coefficient in the
reverse scanning order.
Coefficient groups are processed sequentially in the reverse order (from bottom-right to top-
left) as illustrated in the following figure:
HEVC H.264/AVC
split_transform_flag
transform_size_8x8_flag
cbf_luma coded_block_pattern
cbf_cb
cbf_cr
transform_skip_flag
last_significant_coeff_x_prefix last_significant_coeff_flag
last_significant_coeff_y_prefix
last_significant_coeff_x_suffix
last_significant_coeff_y_suffix
coded_sub_block_flag coded_block_flag
significant_coeff_flag significant_coeff_flag
coeff_abs_level_greater1_flag
coeff_abs_level_greater2_flag
coeff_abs_level_remaining coeff_abs_level_minus1
coeff_sign_flag coeff_sign_flag
Residual Coding: Scanning Order
Notes:
Experiments show that including horizontal and vertical scans for large TBs offers
little compression efficiency, so vertical and horizontal scans are limited to 4x4 and
8x8 sizes.
Adaptive scanning for Intra blocks is not a new idea (e.g. see the paper Adaptive
Scanning for H.264/AVC Intra Coding, ETRI Journal, 2006).
Residual Coding: Multi-Level Significance
b) The coded_sub_block_flag is not signaled for the last CG (i.e. the CG which
contains the last level). Motivation: a decoder can infer significance since the last
level is present.
c) The coded_sub_block_flag is not signaled for the group including the DC position
Residual Coding: Multi-Level Significance (cont.)
Notes:
1. significant_coeff_flag loop
2. coeff_abs_level_greater1_flag loop
3. coeff_abs_level_greater2_flag (at most one flag is coded)
4. coeff_sign_flag loop
5. coeff_abs_level_remaining loop
Context model derivation for 8x8 and higher TBs - context depends on the
significant_coeff_group_flag of the neighboring right CG and lower (sl) CGs and on
the coefficient position in the current CG. Motivation: to avoid data dependencies
within a CG and to benefit parallezation with negligible coding loss if contexts
depend on significance of immediately preceeding coefficints (around 0.1% as
reported in JCTVC-I0296).
Coding direction
Current Right
CG CG
Bottom
CG
Notes:
There are 4 context model sets for luma ( denoted as 0, 1, 2 and 3) and 2 for chroma
(denoted as 4 and 5), the number of context models in each set is 4.
The derivation of context mode consists of two steps: the inference of context set and the
derivation of the model inside the selected set, the following table reveals the context set
derivation:
Luma Chroma
# coeff_abs_level_greater1_flags 0 >0 0 >0
in previous CG
CG with DC 0 1 4 5
CG without DC 2 3 4 5
Residual Coding: coeff_abs_level_greater1_flag (cont.)
Context model derivation within the selected context set depending on the
number of trailing ones and the number of coefficient levels larger than 1 in the
current CG:
Else If the revious coefficient in current CG is more than 1 (i.e. the previous
coeff_abs_level_greater1_flag=1) then the context model equal to 0.
Luma Chroma
# coeff_abs_level_greater1_flags 0 >0 0 >0
in previous CG
CG with DC 0 1 4 5
CG without DC 2 3 4 5
Sign Data Hiding (SDH): optional mode, for each CG the sign of the last nonzero coefficient
(in the reverse scan) is omitted. Instead, the sign is embedded in the parity of the sum of the
levels, if the sum is even then the hidden sign is +, otherwise .
If the distance in scan order between the first and the last nonzero coefficient is less
than 4 then SDH is not used. Notice that the fixed value 4 was experimentally chosen
(see JCTVC-I0156). Probably that value can be a bad choice on some streams.
If only one nonzero coefficient is present in CG, then SDH is not activated.
Disadvantages of SDH:
More complexity and Increase of quantization noise (potentially)
Residual Coding: example implementation of SDH in encoder
If the parity does not match the omitted sign, the encoder has to change the value of one of
the nonzero coefficients in the current CG.
If there is nonzero delta values, find the minima minNzDelta among abs( delta )
{
If minNzDelta >0
adjust qCoef = qCoef +1
Else [minNzDelta <0]
adjust qCoef = qCoef -1
}
Else [ all delta values are zero ]
Take most high frequence coeff and adjust it.
}
Residual Coding: coeff_abs_level_remaining
Binarization - HEVC employs adaptive GolombRice coding for small values and switches to
Exp-Golomb code for larger values.
The transition point to Exp-Golomb is when the unary code length equals 4.
Scan_pos 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Coefficients 0 1 -1 0 2 4 -1 -4 4 2 -6 4 7 6 -12 18
significantFlag 0 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1
signFlag 0 1 0 0 1 1 0 0 1 0 0 0 1 0
levelRem 2 2 2 0 5 3 6 5 11 17
Residual Coding - Notes
The loop counts in the four loops can be different (challenge for loop
unrolling)
picture boundaries
Granularity is 8x8 grid or higher (unlike AVC/H.264 where the granularity is 4x4)
32
Deblocked
8X8 8X8
Non-deblocked
16x16
4x4 4x4
8X8
4x4 4x4
32
16X16 16X16
Overview (cont.)
Notes:
2.Chroma is deblocked only if one of the adjacent blocks is intra (since at intra-block
boundaries blocking artefacts are strongest). By the way if one knows ahead that in a
picture no intra CU is present then one can turn off chroma deblocking at all.
1. Vertical edges are filtered first, then horizontal edges are filtered.
2. For each edge of 8x8 grid determine the filter strength (Bs)
3. According to the filter strength and the average quantization parameter (QP) determine
two thresholds: tC and
4. According to the values of edge pixels and tC , modify (if needed) the pixels
Note: in HEVC deblocking the decision process requires much more logic than the filtering
itself.
"For each macroblock and each component, vertical edges are filtered first, starting with
the edge on the left-hand side of the MACROBLOCK proceeding through the edges
towards the right-hand side of the MACROBLOCK in their geometrical order, and then
horizontal edges are filtered, starting with the edge on the top of the MACROBLOCK
proceeding through the edges towards the bottom of the MACROBLOCK in their
geometrical order."
In HEVC spec., the word MACROBLOCK is replaced with the word PICTURE. This subtle
difference complicates pipelining of Deblock. Indeed, the horizontal filtering of (N-1) th CTB
has to be delayed until the vertical filtering of Nth CTB (i.e. the next CTB) completed (at
least the leftmost vertical edge of the N-th CTB).
Top Line Buffer
Notice that in AVC/H.264 there are five strengths and more complicated derivation of
boundary strengths.
P and Q are two adjacent TB or PB blocks then the filter strength Bs is specified as:
Thresholds tC and are used in deblocking process and are derived by the following table:
Notice that if QP in a picture is constant then tC and can be specified once at the start of
the picture. E.g. x265 has adaptive quantization mode and if this mode is switched off then
QP is constant within a picture, although QP can vary between pictures.
Blockiness ad Discrepancy from Ramp
q2
q1 ramp
p0 q3
p2
q0
p1
p3 TB/PB boundary
Vertical Edge Filtering (Luma) derivation d [Decision Process]
Necessary condition for luma filtering is d<, because small discrepancies from the
ramp apparently are result of blockiness, while strong discrepancies means presence of a
natural edge.
dSam0 = 0
dSam3 = 0
If d< Then
If d < Then
if dEp = 1 // modify p1
{
p = Clip3( (tC >> 1), tC >> 1, ( ( ( p2,k + p0,k + 1 ) >> 1 ) p1,k + ) >>1 )
p1,k = Clip1Y( p1,k + p )
}
if dEq = 1 // modify q1
{
q = Clip3( (tC >> 1), tC >> 1, ( ( ( q2,k + q0,k + 1 ) >> 1 ) q1,k - ) >>1 )
q1,k = Clip1Y( q1,k + q )
}
}
}
Sample Adaptive Offset (SAO)
Page 100
Background
Quantization makes reconstructed and original blocks differ. The quantization error is not
uniformly distributed among pixels. There is a bias in distortion around edges (due to Gibbs
effect).
Reported (e.g. in JCTVC-G680) that in local minima reconstructed pixel tend to be lower than
the neighboring pixels. Therefore, the offset in local minima tend to have positive sign.
Background (cont.)
Reported that SAO reduces ringing and mosquitos artifacts (which in turn expected to
become more annoying with large transforms). Consequently SAO improves subjective
quality for low compression ratio video.
Heuristics:
If a CTB contains a strong edge then its recommended to apply Edge Type SAO for this CTB,
where the direction pattern (sao_eo_class) is determined from the edges direction, e.g. if the
edge is vertical then the direction pattern is horizontal respectively.
Overview
SAO is applied after deblocking. For efficient HW implementation SAO can be coupled with
deblocking in MB-loop. From point of HW design execution of SAO prior to deblocking
facilitates coupling.
SAO can be optionally turned off or applied only on luma samples or only on chroma samples
(regulated by slice_sao_luma_flag and slice_sao_chroma_flag ).
SAO parameters can be either explicitly signalled in CTU header or inherited from left or
above CTUs.
Note:
chroma CTBs share the same SaoTypeIdx.
Edge Type SAO
In case of Edge type, the edge is searched across one of following directions ( the
direction is signaled by sao_eo_class parameter, once per CTU):
The edge detection is applied to each sample. According to the results the
sample is classified into five categories (EdgeIdx) :
Edge Type SAO (cont.)
According to EdgeIdx the corresponding sample offset (signaled by sao_offset_abs and
sao_offset_sign) is added to the current sample.
Up to 12 edge offsets (4 luma, 4 Cb chroma and 4 Cr chroma) are signaled per CTU. To
reduce the bit overhead there is a particular merge mode (signaled by sao_merge_up_flag
and sao_merge_left_flag flag) which enables a direct inheritance of SAO parameters from top
or left CTU.
Band Type SAO
The pixel range from 0..255 (8-bits per pixel) is uniformly split into 32 bands.
A fixed offset added to all samples of the same band. Only 4 consecutive bands are selected
by an encoder (trade-off between CTU header overhead and coding efficiency), a separate
offset is signaled for each band. In other words only 4 successive bands are affected in Band
Type SAO.
Notes:
An offset can be computed on encoders side as the average difference between the
original samples and reconstructed samples in a certain band. Then encoder selects 4
successive bands with the maximal difference in averages.
Experiments reveal that Band Type SAO is beneficial in noisy sequences or in sequences
with large gradients (e.g. PeopleOnStreet which is abundant in black-white switches).
SAO Design Points
For SAO left and top lines of pixels need to keep in a memory.
Pipeline chain:
According to the schema (a), during the deblocking process, statistical information is
processed and the decision on SAO parameters is made. Due to the fact that SAO
parameters are determined in Deblock stage we cant apply CABAC in parallel to Deblocking.
The schema (b) enables to parallel Deblock and CABAC with negligible coding efficiency
loss.
The method (b) enable coupling SAO and DeblockFilter in CTU-loop. Indeed, after the top-
left 2x2 block in a CB has been completely deblocked, SAO can start with the pixel (0,0).
SAO Impact on Quality
Slices
Tiles
Wavefronts (WPP)
Slices
The first slice segment of each slice must be regular, i.e. regular segment is
a leading segment of each the slice. Slice #0
(contains 4 segments)
regular segment #0
dependent segment #1 Slice #1
(contains one segment)
dependent segment #2 #3
#3 Regular segment #0
Slices - Slice Segments
Dependencies among slice segments in a slice are not broken, although CABAC
engine must be flushed and reset at the end of each segment but states are not
reset.
Slice Header Dependency: Short slice header is used where the
missing parameters are taken from the regular segment.
Restriction:
Each slice always starts with a regular segment (carrying the slice header),
followed by zero or more dependent segments.
MTU-matching
Slices: Pros and Cons
Cons:
The entropy coding engine is reset at the start of each tile and flushed at the end
of the tile.
Only the deblocking filter can be optionally applied across tiles, in order to reduce
visual artifacts.
Tiles (cont.)
At the end of each tile CABAC is flushed and consequently the tile ends at byte
boundary.
The tile entry points (actually offsets) are signaled at the start of picture in order
to enable to a decoder to process tiles in parallel. Signaling tile offsets in the
start of picture increases encoding latency (it might be issue for ultra-low latency
applications). Indeed, encoder should wait until all tiles completed and then
update the picture header (actually the slice header) and then transmit data. We
can avoid this delay if compose tiles in the mode single slice single tile. In
such case only slice overhead is added.
Due to high area/perimeter ratio square tiles are more beneficial than
rectangular ones (since the perimeter represents the boundaries where the
dependencies are broken).
Tiles: Pros & Cons
Pros:
Composition of a picture (4K TV) from multiple rectangular sources which are
encoded independently. With slices we can compose only horizontal stripes.
Cons:
Breaking intra and motion vector prediction across tile boundaries deteriorates
coding efficiency.
Tiles vs. Slices
Tale: If we divide a WxH frame into 4 uniform slices then the total length of internal
boundaries is 3xW. On the other hand, if we divide this frame into 4 uniform tiles
then the total length of internal boundaries is (W+H).
In most cases W+H < 3xW therefore division into tiles looks more beneficial than
splitting into slices (since total length of boundaries where predictions broken is
minimized for tiles). Moreover slice headers adds additional overhead.
However
According my experiments on selected 4K streams the gain in bit-size of tiles
versus slices does not exceed 0.5% . The gain up to 0.5% in coding efficiency is
commonly considered as negligible (within a noise level).
So, tiles and slices can be considered as comparable tools for paralleling
processing.
The second row is delayed until two first CTUs of the first row completed.
The third row is processed after two first CTUs of the second row have been
made, etc.
Wavefronts (cont.)
The context models of the entropy coder in each row are inferred from those in the
preceding row with a small fixed processing lag. Actually the context models are
inherited from the second CTU of the previous row.
CABAC is flushed after the last CTU of each row, making each row to end at byte
boundary.
CABAC is flushed at the end of each CTU row in order to make each row to end at
byte boundary and to facilitate parallel processing.
CABAC is reset at the end of each CTU row in order to enable parallel processing.
Entry points of each CTU row are explicitly signaled in picture/slice header.
Let T is an average coding time of single CTU then the first CTU of the second row starts at
2T, the first CTU of the third CTU row starts at 4T, the first CTU of the last row starts at
2(H-1)T , where H is picture height in CTUs and W is width in CTUs.
Consequently in WPP mode the last CTU in the picture is coded at 2(H-1)T+WT, without WPP
mode the last CTU is coded at H*W*T
For 3840x1728 resolution CTU size = 64x64 the speed-up ratio is 14. For CTU size 32x32
the speed-up ratio is 28. Probably it might be efficient to use CTU size 32x32 to exploit better
parallelism?
Wavefronts (WPP) Pros & Cons
Pros:
Good for architectures with shared cache, e.g. overlapping of search areas:
Unlike tiles intra and motion
vector prediction across
CTU rows enabled.
Cons:
Cons
MTU size matching challenging with wavefronts.
Frequent cross-core data communication, inter-processor synchronization for
WPP is complex.
Wavefronts (WPP) Pros & Cons
Pros:
Good for architectures with shared cache due to overlapping of search areas
Core #n
Wavefront parallel encoding is reported to give BD-rate degradation around 1.0% compared
to a non-parallel mode.
Bitrate savings from 1% to 2.5% are observed at same QP for Wavefront against Tiles (each
row is encompassed by single tile).
1. All Intra
Main configuration - encoder_intra_main.cfg
High efficiency (10 bits per pixel) - encoder_intra_he10.cfg
2. Random Access
Main configuration - encoder_randomaccess_main.cfg
High efficiency (10 bits per pixel) - encoder_randomaccess_he10.cfg
HM Test Configuration (cont.)
3. Low Delay (DPB buffer contains two or more reference frames, each inter frame can
utilize bi-prediction from previous references):
Main configuration - encoder_lowdelay_main.cfg
High efficiency (10 bits per pixel) - encoder_lowdelay_he10.cfg
Tiles are targeted for multi-core platforms therefore the tiles are desired to have equal areas
and minimal joint boundaries (since dependencies are broken across tile boundaries and to
minimize penalty in coding efficiency it's desirable the total length of tile boundaries is
minimal).
Example, let's consider a four-cores platform. How to divide a picture into tiles
by keeping both equal areas and minimal borders?
Solution #1: Partitioning of WxH picture into four vertical (or horizontal) stripes meets the
first condition but the total tile boundary length is 3xH (or 3xW).
T0
T1
T0 T1 T2 T3
T2
T3
Solution #2: Partitioning of the WxH picture into four equivalent quadrants makes the total
tile boundary equal to (W+H) and this value is less than 3xH or 3xW.
T0 T1
T2 T3
So, Solution #2 is the best division (equal areas and minimal tile boundaries).
However, the solution #2 is not suited for triple-cores case (since HEVC enables only grid-
tiling).
In general tiling the best solution (minimal boundaries and equal areas) for triple-cores is:
1/3H T0
Area of T0 = 1/3H x W
1/2W 1/2W
4. Sample Adaptive Offset in the HEVC Standard, 2012 December, IEEE Transactions
on Circuits and Systems for Video Coding.
7. Intra Prediction Header Bits Estimation Algorithm for RDO in H.265/HEVC, Maxim
P. Sharabayko, Oleg G. Ponomarev