CQP HRD Mode Encoding

The application can configure AVC encoder to work in CQP rate control mode with HRD model parameters. SDK will place HRD information to SPS/VUI and choose the appropriate profile/level. It’s the responsibility of the application to provide per-frame QP, track HRD conformance, and insert required SEI messages to the bitstream.

The following example shows how to enable CQP HRD mode. The application should set RateControlMethod to CQP, mfxExtCodingOption::VuiNalHrdParameters to ON, mfxExtCodingOption::NalHrdConformance to OFF, and set rate control parameters similar to CBR or VBR modes (instead of QPI, QPP, and QPB). The SDK will choose CBR or VBR HRD mode based on the MaxKbps parameter. If MaxKbps is set to zero, the SDK will use CBR HRD model (write cbr_flag = 1 to VUI), otherwise the VBR model will be used (and cbr_flag = 0 is written to VUI).

Note

For CQP, if implementation doesn’t support individual QPI, QPP and QPB parameters, then QPI parameter should be used as a QP parameter across all frames.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
mfxExtCodingOption option, *option_array;

/* configure mfxExtCodingOption */
memset(&option,0,sizeof(option));
option.Header.BufferId         = MFX_EXTBUFF_CODING_OPTION;
option.Header.BufferSz         = sizeof(option);
option.VuiNalHrdParameters     = MFX_CODINGOPTION_ON;
option.NalHrdConformance       = MFX_CODINGOPTION_OFF;

/* configure mfxVideoParam */
mfxVideoParam param;

// ...

param.mfx.RateControlMethod         = MFX_RATECONTROL_CQP;
param.mfx.FrameInfo.FrameRateExtN   = valid_non_zero_value;
param.mfx.FrameInfo.FrameRateExtD   = valid_non_zero_value;
param.mfx.BufferSizeInKB            = valid_non_zero_value;
param.mfx.InitialDelayInKB          = valid_non_zero_value;
param.mfx.TargetKbps                = valid_non_zero_value;

if (write_cbr_flag == 1)
   param.mfx.MaxKbps = 0;
else /* write_cbr_flag = 0 */
   param.mfx.MaxKbps = valid_non_zero_value;

param.NumExtParam = 1;
option_array     = &option;
param.ExtParam     = (mfxExtBuffer **)&option_array;

/* encoder initialization */
mfxStatus sts;
sts = MFXVideoENCODE_Init(session, &param);

// ...

/* encoding */
mfxEncodeCtrl ctrl;
memset(&ctrl,0,sizeof(ctrl));
ctrl.QP = frame_qp;

sts=MFXVideoENCODE_EncodeFrameAsync(session,&ctrl,surface2,bits,&syncp);