Video Compression

VideoNerd

The sacred purpose of HRD does not overwhelm Decoder by strong fluctuations in instant bitrates

General Flowchart

Details

  • Frames  are removed from CPB instantaneously and  decoded instantaneously and put onto DPB instantaneously. In other words a frame moves from CPB to DPB via Decoder in 0 seconds.  Therefore HRD model is called Hypothetical. 

 

  • CBP Size (in bits) is specified in VUI  (sub-section of SPS) via cpb_size_value_minus1 and cpb_size_scale as

        CpbSize = ( cpb_size_value_minus1+ 1 ) <<(4+ cpb_size_scale) 

 

  • The bitrate (bits per second) is specified in VUI via bit_rate_value_minus1 and bit_rate_scale as

       BitRate =  (bit_rate_value_minus1+1)<<(bit_rate_scale+6)

 

  • DPB Size granularity is in units of frames and specified in VUI by max_dec_frame_buffering, if this parameter not present derived from Table A-1 of the spec. according to level.

 

  • Removal Time from DPB is specified in picture timing SEI by  dpb_output_delay, this parameter is signaled for each picture. Frame is removed from DPB instantaneously.

 

  • Removal Time from CPB is specified in picture timing SEI by cpb_removal_delay. The cpb_removal_delay denotes the frame removal time (in units of clock ticks, details are present later) from the last buffering period SEI. This parameter is signaled for each picture and encoded frame is removed from CPB instantaneously. Thus, cpb_removal_delay is monotonically increasing along frames until next buffering_period SEI message encountered. The number of bits allocated for cpb_removal_delay is specified by the VUI parameter cpb_removal_delay_length.  You should choice the magnitude of  cpb_removal_delay_length  such that no wrap-around occur  within the maximal buffering-period interval. For example, if you specify cpb_removal_delay_length=8 bits and the frame duration is 2 clock ticks, then the number of frames between two buffering period SEIs must be smaller 512.

 

  • TS buffer is not specified in H.264/AVC.  However, it’s specified in Blu-Ray spec. (named as MB1 or Multiplexor buffer) and it has a constant size of 40000 bytes (Table 8-3 of Blu-Ray spec).

 

  • The input rate to TS buffer is leak rate (the rate is specified in Table 8-2 of Blu-Ray spec). For level 4.1 the input rate is 1.2*40*10^6 bits/sec.

Some definitions for following parts:

  • Ta(n) – the time when the first bit of the picture #n enters the CPB, called the arrival time of picture #n.

 

  • Tf(n) – the time when the last bit of the picture #n enters the CPB, called the final arrival time of the picture #n. Tf(n) is equal to Ta(n)+PictureSize/BitRate.

 

  • Tr(n) – the time when the picture #n is removed from the CPB, called the removal time.

 

   When Frames Removed from CPB?

  • Frame is removed from CPB according to cpb_removal_delay (signaled in the pic_timing SEI associated with the given frame).

 

  • cpb_removal_delay is specified in units of clock ticks from arrival of the last buffering_period SEI


  • Clock Tick (Tc) is derived from num_units_in_tick and time_scale (signaled in VUI) as

        Tc = num_units_in_tick /time_scale

     Tc also specifies the duration of field in seconds, hence the duration of frame is 2 x Tc seconds.

 

  • To convert cpb_removal_delay to seconds use the following:

cpb_removal_delay * Tc 

 

  • The removal time Tr( n ) of the frame #n from CPB is specified as follows:

                  Tr( n ) = Tr( last buffering period ) + tc * cpb_removal_delay( n )

 

  • Usually the buffering period SEI is signaled at the start of GOP (not necessarily each GOP).

 

When the Very First Frame Removed from CPB?

Initial removal time ( or removal time of the very first frame) in seconds is specified by initial_cpb_removal_delay/90000, where initial_cpb_removal_delay is present as a parameter in buffering_period SEI.

 

When Data starts to Flow to TS buffer and Restrictions?

  • The start time is specified by the first PCR, at this time data commence to flow to TS buffer and immediately “drain” to CPB with the predefined rate BitRate.

 

  • Only after initial_cpb_removal_delay/90000 seconds Decoder starts to remove data from CPB. Thus, decoding delay is equal to initial_cpb_removal_delay/90000 .

 

  • Blue-Ray limits maximal delay to 1 sec., i.e. initial_cpb_removal_delay < 90000. The maximal delay of 1 second puts restrictions on CPB size and BitRate, i.e. if we divide a declared CPB buffer size (CpbSize) with a declared bit-rate (BitRate) then the result must be less or equal to 1, if not, the buffer size is need to be reduced or BitRate is need to be increased.

 

VBR and CBR Modes

  • CBR – signaled by cbr_flag=1 in VUI.

In this mode data from TS buffer flows with a constant rate BitRate, i.e. the tap between TS and CPB is always open. Hence, Ta(n) = Tf(n-1).

 

  • VBR – signaled by cbr_flag=0 in VUI.

In this mode the tap between TS and CPB can be closed temporarily (to prevent CPB overflows), however when the tap is open data flows with constant rate BitRate. Hence, Ta(n) ≥ Tf(n-1).

 

Note: in both mode bit-rate is specified as

BitRate =  (bit_rate_value_minus1+1)<<(bit_rate_scale+6)

 

CBR Mode Example

 

VBR Mode Example

 

How Arrival Time Derived in VBR mode?

Unlike CBR mode, Ta(n) > Tf(n-1). In other words in the period of  [Ta(n) – Tf(n-1)] seconds the tap is closed.

Before let’s specify what is Te(n) – earliest time for the picture #n to enter:

a)  For non-IDR frame

Te(n) = Tc*cpb_removal_delay(n) + Tr(last idr) –(initial_cpb_removal_delay+initial_cpb_removal_delay_offset)/90000

where Tc = num_units_in_tick /time_scale

b) For IDR frame

     Te(n) = Tc*cpb_removal_delay(n) + Tr(last idr) – initial_cpb_removal_delay/90000

 The arrival time of frame #n is

Ta( n ) = Max( Tf( n − 1 ), Te( n ) )

 

How Prevent Violations

To prevent underflow of TS buffer in VBR it’s necessary to close the tap, in other words to increase Te(n).

We can decrease cpb_removal_delay, this action would cause the tap to be closed more frequently.

However, by closing the tap we increase a risk to underflow CPB.

19 Responses

  1. Hmm is anyone else encountering problems with the pictures on this blog loading? I’m trying to figure out if its a problem on my end or if it’s the blog. Any suggestions would be greatly appreciated.

  2. Simply want to say your article is as astonishing. The clarity in your post is just cool and i could assume you are an expert on this subject. Well with your permission allow me to grab your feed to keep up to date with forthcoming post. Thanks a million and please keep up the gratifying work.

  3. It’s really a cool and useful piece of information. I am happy that you simply shared this useful information with us. Please stay us informed like this. Thanks for sharing.

Leave a Reply

Your email address will not be published. Required fields are marked *