CQP HRD Mode Encoding#

The application can configure an AVC encoder to work in CQP rate control mode with HRD model parameters. oneVPL 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). oneVPL will choose CBR or VBR HRD mode based on the MaxKbps parameter. If MaxKbps is set to zero, oneVPL 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 does not support individual QPI, QPP and QPB parameters, then QPI parameter should be used as a QP parameter across all frames.

 1mfxExtCodingOption option, *option_array;
 2
 3/* configure mfxExtCodingOption */
 4memset(&option,0,sizeof(option));
 5option.Header.BufferId         = MFX_EXTBUFF_CODING_OPTION;
 6option.Header.BufferSz         = sizeof(option);
 7option.VuiNalHrdParameters     = MFX_CODINGOPTION_ON;
 8option.NalHrdConformance       = MFX_CODINGOPTION_OFF;
 9
10/* configure mfxVideoParam */
11mfxVideoParam param;
12
13// ...
14
15param.mfx.RateControlMethod         = MFX_RATECONTROL_CQP;
16param.mfx.FrameInfo.FrameRateExtN   = valid_non_zero_value;
17param.mfx.FrameInfo.FrameRateExtD   = valid_non_zero_value;
18param.mfx.BufferSizeInKB            = valid_non_zero_value;
19param.mfx.InitialDelayInKB          = valid_non_zero_value;
20param.mfx.TargetKbps                = valid_non_zero_value;
21
22if (write_cbr_flag == 1)
23   param.mfx.MaxKbps = 0;
24else /* write_cbr_flag = 0 */
25   param.mfx.MaxKbps = valid_non_zero_value;
26
27param.NumExtParam = 1;
28option_array     = &option;
29param.ExtParam     = (mfxExtBuffer **)&option_array;
30
31/* encoder initialization */
32mfxStatus sts;
33sts = MFXVideoENCODE_Init(session, &param);
34
35// ...
36
37/* encoding */
38mfxEncodeCtrl ctrl;
39memset(&ctrl,0,sizeof(ctrl));
40ctrl.QP = frame_qp;
41
42sts=MFXVideoENCODE_EncodeFrameAsync(session,&ctrl,surface2,bits,&syncp);