Please note as of Wednesday, August 15th, 2018 this wiki has been set to read only. If you are a TI Employee and require Edit ability please contact x0211426 from the company directory.
DM36x Rate Control Modes
DM36x H.264 Encoder Rate Control Modes
- 1 DM36x Rate Control Modes
- 1.1 CBR (rcAlgo = 0): Constant Bitrate Rate Control
- 1.2 VBR (rcAlgo = 1): Variable Bitrate Control
- 1.3 Constant quality (rcAlgo = 2): (Fixed QP)
- 1.4 CVBR (rcAlgo = 3): Constrained Variable Bitrate
- 1.5 Custom RC1 (rcAlgo = 4): Fixed frame size Rate Control
- 1.6 Custom CBR1 (rcAlgo = 5)
- 1.7 Custom VBR1 (rcAlgo = 6)
- 2 DM36x Rate Control Parameters
- 3 Example Usage: How to specify RC mode
DM36x Rate Control Modes
The Rate Control (RC) in an encoder maximizes video quality while ensuring target bit control is within specified limit during encoding. DM36x encoder specifies various rate control modes using rcAlgo dynamic API parameter. DM36x encoder uses this parameter along with other RC parameters such as targetBitRate, frameRate etc. to meet required behavior. A brief description of various supported RC modes of DM36x H.264 encoder is described below. rcAlgo > 2 are only present in ver 2.1 of encoder software.
CBR (rcAlgo = 0): Constant Bitrate Rate Control
This is a strict rate control which allows one to maintain end-to-end delay within the specified limit. This rate control method can also skip frames to maintain the desired VBV buffer level. In this rate control mode, instantaneous bitrate is given more importance. CBR is suitable for the video conferencing and streaming applications because it allows the application to maintain a constant flow of bit-rate and ensure the end-to-end delay stays within the specified limit required by an interactive application.
VBR (rcAlgo = 1): Variable Bitrate Control
VBR has flexibility to average the bit-rate over a larger time interval when compared to CBR. Focus of the rate control is picture quality rather than instantaneous bitrate control. Larger bit-rate deviations from target bit-rate are allowed more often on the VBR. The VBV buffer size is larger than that of the CBR because higher end-to-end delay can be tolerated, which enables the encoder to use larger instantaneous bit-rates if required, i.e., larger maximum to average picture size is allowed than compared to CBR. Picture skips are not allowed for VBR rate control. This implies all pictures will be encoded. VBR is appropriate for storage, broadcast, streaming and surveillance applications as the video sequences in these applications consist of non-homogenous video content.
Constant quality (rcAlgo = 2): (Fixed QP)
This method does not employ any rate control method, rather uses fixed QP provided by user (intraFrameQP and interFrameQP) while encoding. Since the quantization parameter is fixed during the course of encoding, this RC method can also be considered as constant quality rate control.
CVBR (rcAlgo = 3): Constrained Variable Bitrate
This rate control allows the bitrate to change based on the complexity of the scene. The rate control takes two inputs viz. 1. targetBitrate and 2. maxBitrateCVBR. For scene with normal complexity, the RC operates at targetBitrate. When the scene complexity increases, the RC increases the operating bitrate to higher value maxed to maxBitrateCVBR. The operating bit rate is encoder's internal term - from end user point of view, one should not expect that it is always adhered. Encoder might consume higher bits than to its operating bit rate momentarily. In a longer duration, the overall bitrate achieved will be targetBitrate. This rate control is especially suited for video surveillance where one would intend to encode with better quality when there is an increase in scene complexity
For details, please refer to : CVBR Rate control
Note: CVBR is designed to achieve targetBitrate in longer duration of time. Hence if one observes the overall bitrate(for long duration), it will always be same as targetBitrate. It will go nearer to maxBitrate for short duration in case the complexity increases. To observe this, one has to use elecard(or some other tool) and see the running bitrate with time/complexity. Also, the complexity estimate done by CVBR is based on previous history. If you start and stop the video recording with complexity factor always remaining at high, CVBR will not treat it differently. It will be considered as VBR and you will see the the running bitrate does not go above the targetBitrate for the whole duration. Hence in lab test, one has to be careful when inferring at results. They should let video get recorded with static sequence for few seconds before changing to complex video(like hand movement before camera etc).
Custom RC1 (rcAlgo = 4): Fixed frame size Rate Control
This is a custom RC algorithm where each encoded frame produces the same number of bits. The size of the frame is determined by "targetBitrate/targetFrameRate". In case of interlaced encoding, the size of the frame is sum of top and bottom fields. In this mode, the encoder operates in multipass mode(internally) to achive the best quality for the given frame size. In case the frame size is still not achived, the remaining bits are filled with filler data. This rate control mode has impact on video performance and is only suitable for smaller resolutions below VGA.
Custom CBR1 (rcAlgo = 5)
This is the customized version of CBR (rcAlgo = 0) algorithm. The main purpose of Custom CBR1 algorithm is to reduce the breathing artifacts in encoded videos. Breathing artifacts are observed when periodic intra frames are used at low bitrates. Another distinguishable feature of this algorithm is that, the skip frames are distributed over a group of encoded frames instead of the skips occurring in bursts. This encoding mode is meant to be used in video surveillance at lower bitrates as is gives optimal balance between constant bitrate and video quality.
Custom VBR1 (rcAlgo = 6)
This is the customized version of VBR (rcAlgo = 1) algorithm. This version of VBR algorithm is targeted for sequences with varying complexity distribution. The important feature of this rcAlgo is that it ensures target bitrate is achieved over shorter durations (compared to VBR). In a situation where higher complexity frames are preceded by relatively lower complexity frames, VBR(rcAlgo = 1) will reuse the bits saved during encoding of lower complexity frames and hence the average bitrate at the time of encoding higher complexity frame may be slightly higher than the target bitrate. On the other hand, Custom VBR1 will not reuse the bits saved during coding of lower complexity frames, hence ensuring that the average bitrate at the time of higher complexity remains same as target bitrate. This RC mode is suitable for application which wants to use VBR but still wants to ensure that the average bitrate should not exceed target bitrate under any circumstance.
DM36x Rate Control Parameters
Below mentioned parameters along withrcAlgo determine the behaviour of rate control.
This parameter selects the QP to be used for the very first frame of the video sequence. It is important to select an appropriate value for this parameter which is inline with both the video resolution and the target bitrate. Both the video resolution and the target bitrate dependencies are taken care of internally by the H.264 video encoder. To make use of this, it is recommended that auto setting of the init QP is used by application by setting this value to -1. The higher the bitrate the lower the value of the initial QP should be and vice-versa. The choice of initial QP is also dependent on the texture complexity of the video sequence. If the application has specific knowledge about the texture complexity of the video sequence to be encoded then the initial QP should be set by the application. For high texture complexity video sequences the initial QP should be set to a high value and for low texture complexity video sequences the initial QP should be set to a low value. The exact values to be set are outside the scope of this wiki topic.
rcQMax/ rcQMaxI and rcQMin/ rcQMinI
To achieve the target bitrate the encoder uses rate control to decide the QP for every picture in the sequence. Explanation for rcQMax and rcQMaxI remains same except that rcQMax is used for P-frames and rcQMaxI is used for I-frames. Same logic applies to rcQMin and rcQMinI. The minimum and maximum value of QP is operating zone for the rate control algorithm. For every picture it selects a QP value in-between (and inclusive) of the minimum and maximum QP. By setting the minimum QP, user controls the minimum compression and maximum bit consumption by a picture. Setting lower value for minimum QP implies higher fidelity, however if the lowest value of QP ( equal to 0) as allowed by the standard is chosen, then this can in some cases lead to some frames consuming too many bits. This indirectly reduces the bit available for subsequent pictures and can lead to overall quality degradation. By setting the maximum QP value user controls the minimum quality for every picture. Setting it to the maximum allowed by the standard (equal to 51) can lead to some pictures having very poor quality. However, it should not be set to too small a value as this would constrain the rate control algorithm and the target bitrate might not be achieved.
rcQMin = 8 rcQMinI = 8 rcQMax = 44 rcQMaxI = 40
The value of Max Delay controls the size of the VBV buffer size. The VBV buffer size is set to the product of the target bitrate and the Max Delay. This ensures that the video encoder performs compression in order to achieve the target bitrate over every Max Delay time duration. The selection of the Max Delay value directly impacts the video quality. For e.g., if the Max Delay is set to 300ms, the VBV buffer size will set be to 33% of the target bitrate. Hence, the rate control needs to achieve the target bitrate over a 9 frame period (assuming the input video is 30fps). Smaller Max Delay value implies that the video encoder has to achieve the target period over a small Max Delay interval. This can result in more skipped frames and/or more aggressive frame level rate control. Both of which can lead to quality degradations. Hence, larger Max Delay is preferable since this implies more flexibility in bit allocation by the rate control algorithm.
Recommended Value for codec running at 30fps
maxDelay = 2000 /* For typical VBR usage */ maxDelay = 300 /* For CBR usage */
The texture masking property of the Human Visual System (HVS) states that more quantization distortion should be introduced in areas of high texture and less quantization distortion should be introduced in smoother areas. This will result in overall better subjective quality of the video frame. Such a quantization noise shaping is performed by using a fine quantization (less quantization noise) in smooth areas and coarse quantization (more quantization noise) in high texture areas. Humans will perceive such a “noise-shaped” video frame as having better subjective quality than a video frame which has the same amount of noise evenly distributed throughout the video frame. This is achieved by using perceptualRC(PRC). PRC calculates the texture measure of every macroblock and assigns a suitable QP which takes into account the texture masking property of the HVS. This ensures that the bits allocated in every frame maximize the perceptual quality perceived by the user.
NOTE: This feature is supported only in version 1.1 backward compatible mode (encQuality = 0)
LBRmaxpicsize/LBRminpicsize controls the maximum/minimum number of bits consumed per frame. For example, if 'B' is the targetBitRate and 'F' is the targetFrameRate, then average bits per frame T is given by the relation,
T = B / F
LBRmaxpicsize and LBRminpicsize are specified in terms of T. If LBRmaxpicsize is set to 45, then the maximum number of bits consumed per frame will be 4.5T. If LBRminpicsize is set to 5, then the minimum number of bits consumed per frame will be 0.5T.When LBRmaxpicsize or LBRminpicsize is set to 0, encoder internally sets their values.
Recommended Value for codec running at 30fps
LBRmaxpicsize = 18 /* For typical LBR usage */ LBRminpicsize = 4 /* For LBR usage */
This feature is applicable only to Custom CBR1 (rcAlgo = 5). This parameter configures the minimum number of frames to be encoded in a set of N frames. Upper 16 bits of this is parameter represents the set of N frames and lower 16 bits represent the minimum number of frames to be encoded in the set. Maximum value of N is 10. For example, if LBRskipcontrol is assigned a value 0x00060005, then atleast 5 frames will be encoded in a every set of 6 frames.
Recommended Value for codec running at 30fps
LBRskipcontrol = 0x00060005 /* For typical LBR usage */
This parameter defines maximum bit-rate to be supported in bits per second. Maximum value supported in this version of H.264 Encoder on DM36x is 50000000. Default value = 10000000. This Value does not have any impact on quality, its limit condition to check bitrate values
This parameter is applicable to CVBR (rcAlgo = 3): Constrained Variable Bitrate. It limits the maximum bitrate which the rate control can achieve during increased complexity duration. The value of maxBitrateCVBR must be atleast 1.5 times targetBitRate.
Typical Value for for the parameter
maxBitrateCVBR = 1.5 * targetBitrate
This parameter is applicable to CVBR (rcAlgo = 3): Constrained Variable Bitrate. It limits the maximum duration of increased complexity. maxHighCmpxIntCVBR is specified in minutes and can take any value from 0 to 60. For instance, if maxHighCmpxIntCVBR is set to 5, then the maximum duration at high complexity state will be 5 minutes. If it set to 0, high complexity duration is internally set to 1.5 seconds.
Typical Value for the parameter
maxHighCmpxIntCVBR = 5 /* It will be mostly application dependent, choose the value based on how long you want to be on the higher bitrate when the complexity increases */
This parameter is applicable to CVBR (rcAlgo = 3): Constrained Variable Bitrate. It controls the sensitivity of the CVBR algorithm towards complexity of video. It can take any value from 0 to 8. A lower value signifies that maxBitrareCVBR will be used for very complex scene, in case complexity increase is not high, CVBR will choose a bitrate between target bitrate and maxBitrateCVBR. If set to higher value say 8, rate control tries to achieve maxBitrateCVBR even for small complexity increase. Since complexity is a subjective measure, it is reccomended to tune this parameter based on user expectation.
CVBRsensitivity = 5
Example Usage: How to specify RC mode
rcAlgo values are used only when IVIDENC1_Params ->RateControlPreset = IVIDEO_USER_DEFINED. CBR and Custom CBR1 Rate Control algorithms are not supported for interlaced encoding and will be automatically disabled by encoder. Custom RC1 - Fixed size frame is not supported for encQuality = 0. Default value of rcAlgo is 1.
Below are the few examples of how to set different RC modes.
rateControlPreset = IVIDEO_LOW_DELAY
rateControlPreset = IVIDEO_USER_DEFINED rcAlgo = 0
rateControlPreset = IVIDEO_LOW_STORAGE
rateControlPreset = IVIDEO_USER_DEFINED rcAlgo = 1
Constant quality (Fixed QP)
rateControlPreset = IVIDEO_IVIDEO_NONE
rateControlPreset = IVIDEO_USER_DEFINED rcAlgo = 2
Please see this application note for more details: Application Parameter Settings for TMS320DM365 H.264 Encoder