hbVPVideoEncode

typedef void *hbVPVideoContext;

hbVPVideoEncode operator and hbVPVideoDecode operator's context description handle, which contains the description information necessary to run on the Video Process Unit and can be reused.

typedef enum { 
  HB_VP_VIDEO_TYPE_H264, 
  HB_VP_VIDEO_TYPE_H265 
} hbVPVideoType;

The video encoding type enumeration.

  • Member

    Member NameDescription
    HB_VP_VIDEO_TYPE_H264The H.264 video coding protocol.
    HB_VP_VIDEO_TYPE_H265The H.265 video coding protocol.
typedef enum {
  HB_VP_VIDEO_RC_MODE_H264_CBR,
  HB_VP_VIDEO_RC_MODE_H264_VBR,
  HB_VP_VIDEO_RC_MODE_H264_AVBR,
  HB_VP_VIDEO_RC_MODE_H264_FIXQP,
  HB_VP_VIDEO_RC_MODE_H264_QPMAP,
  HB_VP_VIDEO_RC_MODE_H265_CBR,
  HB_VP_VIDEO_RC_MODE_H265_VBR,
  HB_VP_VIDEO_RC_MODE_H265_AVBR,
  HB_VP_VIDEO_RC_MODE_H265_FIXQP,
  HB_VP_VIDEO_RC_MODE_H265_QPMAP
} hbVPVideoRcMode;

Code rate control mode enumeration.

  • Member

    Member NameDescription
    HB_VP_VIDEO_RC_MODE_H264_CBRH.264 coding protocol CBR bit rate control mode.
    HB_VP_VIDEO_RC_MODE_H264_VBRH.264 coding protocol VBR bit rate control mode.
    HB_VP_VIDEO_RC_MODE_H264_AVBRH.264 coding protocol AVBR bit rate control mode.
    HB_VP_VIDEO_RC_MODE_H264_FIXQPH.264 coding protocol FixQp bit rate control mode.
    HB_VP_VIDEO_RC_MODE_H264_QPMAPH.264 coding protocol QPMap bit rate control mode.
    HB_VP_VIDEO_RC_MODE_H265_CBRH.265 coding protocol CBR bit rate control mode.
    HB_VP_VIDEO_RC_MODE_H265_VBRH.265 coding protocol VBR bit rate control mode.
    HB_VP_VIDEO_RC_MODE_H265_AVBRH.265 coding protocol AVBR bit rate control mode.
    HB_VP_VIDEO_RC_MODE_H265_FIXQPH.265 coding protocol FIXQP bit rate control mode.
    HB_VP_VIDEO_RC_MODE_H265_QPMAPH.265 coding protocol QPMAP bit rate control mode.
typedef struct {
  uint32_t intraPeriod;
  uint32_t bitRate;
  uint32_t frameRate;
  uint32_t initialRcQp;
} hbVPVideoH264Cbr;

H.264 coding protocol constant bit rate parameters.

  • Member

    Member NameDescription
    intraPeriodI Frame Interval. Value range [0, 2047], recommended value 28.
    bitRateTarget average bit rate in kbps. Value range [1, 700000], recommended value 1000kbps.
    frameRateTarget frame rate in fps. Value range [1, 240], recommended value 30.
    initialRcQpInitial QP value, when the value is not in the range of [0, 51], the larger the parameter value, the worse the encoding quality becomes. If the parameter value exceeds 51, the specific value will be determined by the Video Processing Unit hardware.
typedef struct {
  uint32_t intraPeriod;
  uint32_t intraQp;
  uint32_t frameRate;
} hbVPVideoH264Vbr;

H.264 coding protocol variable bit rate parameter.

  • Member

    Member NameDescription
    intraPeriodI Frame Interval. Value range [0, 2047], recommended value 28.
    intraQpFrame QP value. Value range [0, 51], recommended value 30.
    frameRateTarget frame rate in fps. Value range [1, 240], recommended value 30.
typedef struct {
  uint32_t intraPeriod;
  uint32_t frameRate;
  uint32_t qpI;
  uint32_t qpP;
  uint32_t qpB;
} hbVPVideoH264FixQp;

The H.264 coding protocol fixes the quantization parameters.

  • Member

    Member NameDescription
    intraPeriodI Frame Interval. Value range [0, 2047], recommended value 28.
    frameRateTarget frame rate in fps. Value range [1, 240], recommended value 30.
    qpIForces the QP value of the I-frame. Value range [0, 51], recommended value 0.
    qpPForces the QP value of the P-frame. Value range [0, 51], recommended value 0.
    qpBForces the QP value of the B-frame. Value range [0, 51], recommended value 0.
typedef struct {
  uint32_t intraPeriod;
  uint32_t frameRate;
  uint32_t qpMapArrayCount;
  uint8_t *qpMapArray;
} hbVPVideoH264QpMap;

H.264 coding protocol QP mapping parameter.

  • Member

    Member NameDescription
    intraPeriodI Frame Interval. Value range [0, 2047], recommended value 28.
    frameRateTarget frame rate in fps. Value range [1, 240], recommended value 30.
    qpMapArrayCountSpecifies the count of the QP Map. The calculation formula is (ALIGN16(width)>>4) * (ALIGN16(height)>>4), with a value range of [128, 8192x4096/(16x16)].
    qpMapArraySpecify the QP Map, the subCTU size of H.264 coding protocol is 16x16, you need to specify a QP value for each subCTU. Each QP value occupies one byte and is ordered by raster scan direction.
typedef hbVPVideoH264Cbr hbVPVideoH264Avbr;

H.264 coding protocol constant average target bit rate parameter.

  • Member

    Member NameDescription
    intraPeriodI Frame Interval. Value range [0, 2047], recommended value 28.
    bitRateTarget average bit rate in kbps. Value range [1, 700000], recommended value 1000kbps.
    frameRateTarget frame rate in fps. Value range [1, 240], recommended value 30.
    initialRcQpInitial QP value, when the value is not in the range of [0, 51], The larger the parameter value, the worse the encoding quality becomes. If the parameter value exceeds 51, the specific value will be determined by the Video Processing Unit hardware.
typedef hbVPVideoH264Cbr hbVPVideoH265Cbr;

H.265 coding protocol variable bit rate parameter, the parameter range is restricted in the same way as hbVPVideoH264Cbr.

typedef hbVPVideoH264Vbr hbVPVideoH265Vbr;

H.265 coding protocol variable bit rate parameter, the parameter range is restricted in the same way as hbVPVideoH264Vbr.

typedef hbVPVideoH264AVbr hbVPVideoH265AVbr;

H.265 coding protocol constant average target bit rate parameter, the parameter range is restricted in the same way as hbVPVideoH264AVbr.

typedef hbVPVideoH264FixQp hbVPVideoH265FixQp;

H.265 coding protocol fixed quantization parameter, the parameter range is restricted in the same way as hbVPVideoH264FixQp.

typedef hbVPVideoH264QpMap hbVPVideoH265QpMap;

H.265 coding protocol QP mapping parameter. The calculation formula for qpMapArrayCount is
(ALIGN64(width)>>5) * (ALIGN64(height)>>5) , with a value range of [32, 8192x4096/(32x32)] and a recommended value of 0. The macroblock size is 32x32 , and each macroblock requires a specified QP value. The parameter range is restricted in the same way as hbVPVideoH264QpMap.

typedef struct {
  hbVPVideoRcMode mode;
  union {
    hbVPVideoH264Cbr h264Cbr;
    hbVPVideoH264Vbr h264Vbr;
    hbVPVideoH264Avbr h264Avbr;
    hbVPVideoH264QpMap h264QpMap;
    hbVPVideoH264FixQp h264FixQp;

    hbVPVideoH265Cbr h265Cbr;
    hbVPVideoH265Vbr h265Vbr;
    hbVPVideoH265Avbr h265Avbr;
    hbVPVideoH265QpMap h265QpMap;
    hbVPVideoH265FixQp h265FixQp;
  };
} hbVPVideoRcParam;

Video Process Unit coding protocol code rate control parameter.

  • Member

    Member NameDescription
    modeBit rate control mode.
    h264CbrThe parameter of the H.264 coding protocol CBR bit rate control mode.
    h264VbrThe parameter of the H.264 coding protocol VBR bit rate control mode.
    h264AvbrThe parameter of the H.264 coding protocol AVBR bit rate control mode.
    h264QpMapThe parameter of the H.264 coding protocol QpMap bit rate control mode.
    h264FixQpThe parameter of the H.264 coding protocol FixQp bit rate control mode.
    h265CbrThe parameter of the H.265 coding protocol CBR bit rate control mode.
    h265VbrThe parameter of the H.265 coding protocol VBR bit rate control mode.
    h265AvbrThe parameter of the H.265 coding protocol AVBR bit rate control mode.
    h265QpMapThe parameter of the H.265 coding protocol QpMap bit rate control mode.
    h265FixQpThe parameter of the H.265 coding protocol FixQp bit rate control mode.
typedef struct {
  int32_t decodingRefreshType;
  uint32_t gopPresetIdx;
} hbVPVideoGopParam;

GOP structural parameter.

  • Member

    Member NameDescription
    decodingRefreshTypeSpecifies the type of decoding refresh to apply at the intra frame period. Range value [0, 2], recommended value 2.
    0: NON_IRAP, 1: CRA, 2: IDR.
    gopPresetIdxGOP structure, recommended value 2.
    gopPresetIdx supports 1, 2, 3, 6, 7 and 9.
typedef struct {
  uint8_t pixelFormat;
  int32_t width;
  int32_t height;
  uint32_t outBufCount;
  hbVPVideoType videoType;
  hbVPVideoRcParam rcParam;
  hbVPVideoGopParam gopParam;
} hbVPVideoEncParam;

Parameter for Video encoding.

  • Member

    Member NameDescription
    pixelFormatThe pixel format of the input picture. The currently supported formats include HB_VP_IMAGE_FORMAT_NV12 and HB_VP_IMAGE_FORMAT_YUV420.
    widthThe width of the input image should be aligned to 32. Range Values[256, 8192].
    heightThe height of the input image should be aligned to 8. Range Values[128, 4096].
    outBufCountSpecifies the number of output Buffers inside the Video Process Unit. Range Values[1, 1000], recommended value 5.
    videoTypeThe type of encoding protocol.
    rcParamBit rate control parameter.
    gopParamGOP parameter.
int32_t hbVPGetDefaultVideoEncParam(hbVPVideoEncParam *param);

Gets the default encoding parameters for the encoder, where pixelFormat is set to HB_VP_IMAGE_FORMAT_YUV420 by default, and width and height default to 0, requiring specification based on actual dimensions. The outBufCount defaults to 5, decodingRefreshType to 2, and gopPresetIdx to 2. The bitrate mode is determined by the videoType parameter: When videoType=HB_VP_VIDEO_TYPE_H264, the bitrate control mode is HB_VP_VIDEO_RC_MODE_H264_CBR. Specific parameters can be found in the recommended settings of the hbVPVideoH264Cbr structure. When videoType=HB_VP_VIDEO_TYPE_H265, the bitrate control mode is HB_VP_VIDEO_RC_MODE_H265_CBR. Specific parameters can be found in the recommended settings of the hbVPVideoH265Cbr structure.

  • Parameter
    • [in] param Pointer the encoding parameter.
  • Return Value
    • Return 0 means the API was successfully executed, otherwise the execution failed.
  • Description of interface limitations
    • Before calling the interface, you need to specify the videoType as HB_VP_VIDEO_TYPE_H264 or HB_VP_VIDEO_TYPE_H265 .
int32_t hbVPCreateVideoEncContext(hbVPVideoContext *context,
                                  hbVPVideoEncParam const *param);

Create the encoder context API and initialize context to nullptr in advance before creation.

  • Parameter
    • [out] context Encoder context.
    • [in] param Pointer the encoding parameter.
  • Return Value
    • Return 0 means the API was successfully executed, otherwise the execution failed.
  • Description of interface limitations
    • The Video Process Unit supports the creation of the highest 32 encoding or decoding contexts.
    • The encoder does not support codestream encoding of backward reference frames containing B frames.
int32_t hbVPReleaseVideoEncContext(hbVPVideoContext context);

Release the encoder context API.

  • Parameter
    • [in] context Encoder context.
  • Return Value
    • Return 0 means the API was successfully executed, otherwise the execution failed.
int32_t hbVPVideoEncode(hbUCPTaskHandle_t *taskHandle, 
                        hbVPImage const *srcImg,
                        hbVPVideoContext context);

The API for calling the Video Process Unit encoding.

  • Parameter
    • [out] taskHandle Task handles are responsible for the interaction of the operator with the UCP architecture.
    • [in] srcImg Input YUV Image.
    • [in] context Encoder context.
  • Return Value
    • Return 0 means the API was successfully executed, otherwise the execution failed.
  • Description of interface limitations
    • Creating tasks using asynchronous methods is only supported.
    • Due to hardware limitations of the Video Processing Unit (VPU), the VPU supports a maximum of 31 tasks being submitted simultaneously for encoding or decoding operations.
    • To avoid wasting system resources and improve Video Processing Unit encoding performance, it is recommended to reuse input addresses.
int32_t hbVPGetVideoEncOutputBuffer(hbVPArray *outBuf,
                                    hbUCPTaskHandle_t taskHandle);

The API for calling to get the encoded data buffer.

  • Parameter
    • [out] outBuf Output stream file.
    • [in] taskHandle Task handles are responsible for the interaction of the operator with the UCP architecture.
  • Return Value
    • Return 0 means the API was successfully executed, otherwise the execution failed.
  • Description of interface limitations
    • The output buffer outBuf is requested internally by the Video Process Unit.
    • The buffer contains valid data upon the task is successfully completed, and is released during the task release phase.