Common Bitrate Control Methods (BRC) in Intel® Media SDK

Legal Disclaimer

In this article we will be discussing some of the Bit Rate Control (BRC) methods present in Intel® Media SDK, part of Intel® Media Server Studio. There are quite a few number of bitrate control algorithm which are supported in the Intel Media SDK, but this article will focus on the commonly used algorithms which are Constant Bit Rate, Variable Bit Rate and Look Ahead Algorithm.

Constant Bitrate (CBR)-
In this method, number of bytes consumed per unit time is constant. The encoder performs padding (a process that appends zero's to the end of encoded frames) when the size of the least-compressed frame is smaller than what is required to meet the HRD requirements. The goal of the CBR is to provide constant flow of data, which mostly result into unused capacity. This method is available for historical/legacy reasons. This is a default method used in Media SDK samples.

Variable Bitrate (VBR)-
In this method, number of bytes consumed per unit of time is variable. This method provides bitrate depending upon the complexity of the data i.e. assign higher bit rate to complex scenarios like scene change and low bitrate to less complex scenarios. This overall bitrate is usually comparable with the equivalent CBR mode bitrate . It tries to achieve a smaller overall file size, but also gives unpredictable spikes. This method provides an overall better bitrate quality by allowing bitrate to fluctuate more and also by disable padding. This is a default method used in Media SDK tutorials. For general purposes we recommend using VBR.


I have used simple_encode tutorial(taken from the tutorials on Media Solution Portal) to encode a 720p - Park Joy uncompressed video at 2Mbps, 30fps to do a comparison between CBR and VBR method. 
One of the way you can modify  the encoding code to get the DataLength of the frames

      if (MFX_ERR_NONE == sts) {
            sts = session.SyncOperation(syncp, 60000);      // Synchronize. Wait until encoded frame is ready
            MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, sts);

            sts = WriteBitStreamFrame(&mfxBS, fSink);
			numBytes += mfxBS.DataLength;                      //adding DataLength to find bitrate of 30 frames
			mfxBS.DataLength = 0;
			if (nFrame % 30 == 0)                             
				printf("nFrame:%d\t%lu\n", nFrame, numBytes);  //printing data length(in bytes) after every 30 frames
				numBytes = 0;

            if (bEnableOutput) {
                //printf("Frame number: %d\n", nFrame);

Since the output is in bytes, so convert into bits to get bitrate. In the beginning both methods show higher bitrate, later CBR tries to align to the expected bitrate during encoding where as we can see a spike in the VBR mode.

Look Ahead (LA)-
This is a special bitrate control method used in Media SDK AVC encoder that has been designed to improve encoding quality.  It works by performing extensive analysis of several dozen frames like complexity of the frames, relative motion, frame dependency before the actual encoding. It distributes available bit budget between frames to produce the best possible encoding quality. This method is not a HRD compliant.

It generates good results on the complex data such as fast motion video, computer generated sequences. It improves both objective metrics like SSIM, PSNR and subjective video quality. It works with any GOP pattern but presence of B frames provides the best quality gain. One side effect is that it significantly increases encoding delay and memory consumption.

LookAheadDepth, a parameter which specifies the depth of look ahead rate control algorithm. It is the number of frames that SDK encoder analyzes before encoding. Valid value range is from 10 to 100 inclusive. To instruct the SDK encoder to use the default value the application should zero this field. The only available rate control parameter in this mode is mfxInfoMFX::TargetKbps. Two other parameters, MaxKbps and InitialDelayInKB, are ignored. Media SDK must be initialized to use API version 1.7 or newer to use Media SDK Method.
There are some limitations to LA like it is only available on Intel® Iris™ Pro Graphics, Intel® Iris™ Graphics and Intel® HD Graphics (4200+ Series). Only  Progressive content is supported right now. For more details please check Developers guide available in the document section of Media Solution Portal. There are other Look Ahead bit rate control methods like LA Extended and LA ICQ(Intelligent Constant Quality) but they are experimental methods in development. 

Parameters which can be helpful to achieve different results-

BufferSizeInKB, a parameter which specifies the maximum possible size for any compressed frames. If BufferSizeInKB is less then we will see instantaneous bit rate to be less, this might can affect quality. Keeping BufferSizeInKB is relevant for the developers who want lesser variation over the instantaneous bit rate specially streaming uses cases. If there is a tolerance to more variations or bigger buffer, it can give better quality.
I have done an experiment by encoding foreman.yuv at 4Mbps different BufferSizeInKB using simple_encode tutorial(taken from the tutorials on Media Solution Portal). 
Here is the graph showing variation over the instantaneous bitrate for different BufferSizeinKB.

Here bitrate in used in Kbps to show the variation over the period of frames being encoded. The least buffer size which can encode at 4000kbps(target bitrate) is 34KB, below this encoder throws an error. The variation over the instantaneous bit rate is seen from 34KB to 1000KB, after that variation starts getting saturated. The least variation is seen with buffer size is equal to 200KB. This value will be different for different inputs and also would be different for encoding at different bitrates. The below graph shows the variation of the bitrate over the buffer size.

BRCParamMultiplier, a parameter which specifies a multiplier for bitrate control parameters. It is useful to achieve higher bit rate. This multiplier multiplies with the TargetKbps(which is mfxU16) to achieve quite high bitrate(validated upto 200mbps). Please keep in mind this multiplier will also affect BufferSizeInKB, IntialDelayInKB and MaxKbps. The table below shows the scenario when this parameter is used.

I have used simple_encode tutorial(taken from the tutorials on Media Solution Portal) to encode a 720p - Park Joy uncompressed video to achieve higher bitrate with BRCParamMultiplier and without the BRCParamMultiplier and here are the results -

This table shows that after 60Mbps, the conventional method does not achieve the higher bitrates. In these scenarios, you are advised to use the BRCParamMultipler to go beyond 60Mbps, and also make sure to modify the the Maxlength and BufferSizeInKB accordingly. The BRCParamMultiplier was introduced in Media SDK API 1.3 version.

For more information about the Bitrate Control methods, you can read the Media SDK Manual which comes with Installation and developers guide from the documents in Media Solution Portal Page.

For more complete information about compiler optimizations, see our Optimization Notice.