hbVPVideoEncode

typedef void *hbVPVideoContext;

hbVPVideoEncode operator and hbVPVideoDecode operator's context description handle, which contains the description information necessary to run on the VPU. necessary to run on the VPU, 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 intraQp; uint32_t bitRate; uint32_t frameRate; uint32_t initialRcQp; int32_t vbvBufferSize; uint32_t mbLevelRcEnable; uint32_t minQpI; uint32_t maxQpI; uint32_t minQpP; uint32_t maxQpP; uint32_t minQpB; uint32_t maxQpB; uint32_t hvsQpEnable; int32_t hvsQpScale; uint32_t hvsMaxDeltaQp; uint8_t qpMapEnable; } hbVPVideoH264Cbr;

H.264 coding protocol constant bit rate parameters.

  • Member

    Member NameDescription
    intraPeriodI Frame Interval. Value range [0, 2047], default value 28.
    intraQpI-frame QP value. Value range [0, 51], default value 30.
    bitRateTarget average bit rate in kbps. Value range [0, 700000], default value 1000.
    frameRateTarget frame rate in fps. Value range [0, 240], default value 30.
    initialRcQpInitial QP value, when the value is not in the range of [0, 51], the encoder will decide the initial value internally. Value range [0, 63], default value 63.
    vbvBufferSizeSpecifies the size of the video buffer in ms. Value range [10, 3000], default value 10. The size of the video buffer is bitRate*vbvBufferSize/1000(kb), and the size affects the encoding quality and bit rate control accuracy. When the video buffer is relatively small, the bit rate control is accurate, but the picture coding quality is poor; When this buffer is relatively large, the picture is encoded with high quality, but the code rate fluctuates a lot.
    mbLevelRcEnableEnable macroblock-based frame-level rate control to dynamically adjust the encoding parameters of each macroblock according to the characteristics and requirements of the video content. Value range [0, 1], default value 0.
    minQpIThe minimum QP value for the I-frame. Value range [0, 51], default value 8.
    maxQpIThe maximum QP value for the I-frame. Value range [0, 51], default value 51.
    minQpPThe minimum QP value for the P-frame. Value range [0, 51], default value 8.
    maxQpPThe maximum QP value for the P-frame. Value range [0, 51], default value 51.
    minQpBThe minimum QP value for the B-frame. Value range [0, 51], default value 8.
    maxQpBThe maximum QP value for the B-frame. Value range [0, 51], default value 51.
    hvsQpEnableThe bitrate control can work at the subCTU level of control, the mode that adjusts the QP value of the sub-macroblock, which in turn improves the subjective image quality. Value range [0, 1], default value 1.
    hvsQpScaleValid when hvsQpEnable is enabled, indicates the QP scaling factor. Value range [0, 4], default value 2.
    hvsMaxDeltaQpValid when hvsQpEnable is enabled, specifies the maximum deviation range of HVS QP values. Value range [0, 12], default value 10.
    qpMapEnableEnable QP Map for ROI encoding. value range [0, 1], default value 0.
typedef struct { uint32_t intraPeriod; uint32_t intraQp; uint32_t frameRate; uint8_t qpMapEnable; } hbVPVideoH264Vbr;

H.264 coding protocol variable bit rate parameter.

  • Member

    Member NameDescription
    intraPeriodI Frame Interval. Value range [0, 2047], default value 28.
    intraQpFrame QP value. Value range [0, 51], default value 0.
    frameRateTarget frame rate in fps. Value range [0, 240], default value 30.
    qpMapEnableEnable QP Map for ROI encoding. Value range [0, 1], default value 0.
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], default value 28.
    frameRateTarget frame rate in fps. Value range [0, 240], default value 30.
    qpIForces the QP value of the I-frame. Value range [0, 51], default value 8.
    qpPForces the QP value of the P-frame. Value range [0, 51], default value 8.
    qpBForces the QP value of the B-frame. Value range [0, 51], default value 8.
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], default value 28.
    frameRateTarget frame rate in fps. Value range [0, 240], default value 30.
    qpMapArrayCountSpecifies the size of the QP Map table. The value range [0, 240], default value is 0.
    qpMapArraySpecify the QP Map table, the subCTU size of H.264 coding protocol is 32x32, you need to specify a QP value for each subCTU. Each QP value occupies one byte and is ordered by raster scan direction. The default value nullptr.
typedef struct { uint32_t intraPeriod; uint32_t intraQp; uint32_t bitRate; uint32_t frameRate; uint32_t initialRcQp; int32_t vbvBufferSize; uint32_t ctuLevelRcEnable; uint32_t minQpI; uint32_t maxQpI; uint32_t minQpP; uint32_t maxQpP; uint32_t minQpB; uint32_t maxQpB; uint32_t hvsQpEnable; int32_t hvsQpScale; uint32_t hvsMaxDeltaQp; uint8_t qpMapEnable; } hbVPVideoH265Cbr;

H.265 coding protocol constant bit rate parameter.

  • Member

    Member NameDescription
    intraPeriodI Frame Interval. Value range [0, 2047], default value 28.
    intraQpI-frame QP value. Value range [0, 51], default value 30.
    bitRateTarget average bit rate in kbps. Value range [0, 700000], default value 1000.
    frameRateTarget frame rate in fps. Value range [0, 240], default value 30.
    initialRcQpInitial QP value, when the value is not in the range of [0, 51], the encoder will decide the initial value internally. Value range [0, 63], default value 63.
    vbvBufferSizeSpecifies the size of the video buffer in ms. Value range [10, 3000], default value 10. The size of the video buffer is bitRate*vbvBufferSize/1000(kb), and the size affects the encoding quality and bit rate control accuracy. When the video buffer is relatively small, the bit rate control is accurate, but the picture coding quality is poor; When this buffer is relatively large, the picture is encoded with high quality, but the code rate fluctuates a lot.
    ctuLevelRcEnableEnable macroblock-based frame-level rate control to dynamically adjust the encoding parameters of each macroblock according to the characteristics and requirements of the video content. Value range [0, 1], default value 0.
    minQpIThe minimum QP value for the I-frame. Value range [0, 51], default value 8.
    maxQpIThe maximum QP value for the I-frame. Value range [0, 51], default value 51.
    minQpPThe minimum QP value for the P-frame. Value range [0, 51], default value 8.
    maxQpPThe maximum QP value for the P-frame. Value range [0, 51], default value 51.
    minQpBThe minimum QP value for the B-frame. Value range [0, 51], default value 8.
    maxQpBThe maximum QP value for the B-frame. Value range [0, 51], default value 51.
    hvsQpEnableEnable the frame rate control of the encoded number unit.
    hvsQpScaleValid when hvsQpEnable is enabled, indicates the QP scaling factor. Value range [0, 4], default value 2.
    hvsMaxDeltaQpValid when hvsQpEnable is enabled, specifies the maximum deviation range of HVS QP values. Value range [0, 12], default value 10.
    qpMapEnableEnable QPMap for ROI encoding. Value range [0, 1], default value 0.
typedef hbVPVideoH264Cbr hbVPVideoH264Avbr;

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

typedef hbVPVideoH264Vbr hbVPVideoH265Vbr;

H.265 coding protocol variable bit rate parameter.

typedef hbVPVideoH264QpMap hbVPVideoH265QpMap;

H.265 coding protocol QP mapping parameter.

typedef hbVPVideoH264FixQp hbVPVideoH265FixQp;

H.265 coding protocol fixed quantization parameter.

typedef hbVPVideoH265Cbr hbVPVideoH265Avbr;

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

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;

VPU 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 CBR 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], default value 2.
    gopPresetIdxGOP structure, default value 2.
    gopPresetIdx supports 0, 1, 2, 3, 6, 7 and 9.
typedef enum { HB_VP_H264_PROFILE_UNSPECIFIED, HB_VP_H264_PROFILE_BP, HB_VP_H264_PROFILE_MP, HB_VP_H264_PROFILE_EXTENDED, HB_VP_H264_PROFILE_HP, HB_VP_H264_PROFILE_HIGH10, HB_VP_H264_PROFILE_HIGH422, HB_VP_H264_PROFILE_HIGH444 } hbVPH264Profile;

Profile enumeration under the H.264 encoding protocol.

  • Member

    Member NameDescription
    HB_VP_H264_PROFILE_UNSPECIFIEDWithout specifying the encoding level, the VPU will automatically configure the encoding level according to the bit depth of the source picture.
    HB_VP_H264_PROFILE_BPBaseline Profile, the basic picture quality, supports video sequences in 8bit and 4:2:0 sampling formats.
    HB_VP_H264_PROFILE_MPMain Profile, mainstream picture quality, supports video sequences in 8bit and 4:2:0 sampling formats.
    HB_VP_H264_PROFILE_EXTENDEDExtended Profile, advanced picture quality, supports video sequences in 8bit and 4:2:0 sampling formats.
    HB_VP_H264_PROFILE_HPHigh Profile, senior picture quality, supports video sequences in 8bit and 4:2:0 sampling formats.
    HB_VP_H264_PROFILE_HIGH10High Profile, senior picture quality, supports video sequences in 10bit and 4:2:0 sampling formats.
    HB_VP_H264_PROFILE_HIGH422High Profile, senior picture quality, supports video sequences in 8bit and 4:2:2 sampling formats.
    HB_VP_H264_PROFILE_HIGH444High Profile, senior picture quality, supports video sequences in 8bit and 4:4:4 sampling formats.
typedef enum { HB_VP_H264_LEVEL_UNSPECIFIED, HB_VP_H264_LEVEL1b = 9, HB_VP_H264_LEVEL1 = 10, HB_VP_H264_LEVEL1_1 = 11, HB_VP_H264_LEVEL1_2 = 12, HB_VP_H264_LEVEL1_3 = 13, HB_VP_H264_LEVEL2 = 20, HB_VP_H264_LEVEL2_1 = 21, HB_VP_H264_LEVEL2_2 = 22, HB_VP_H264_LEVEL3 = 30, HB_VP_H264_LEVEL3_1 = 31, HB_VP_H264_LEVEL3_2 = 32, HB_VP_H264_LEVEL4 = 40, HB_VP_H264_LEVEL4_1 = 41, HB_VP_H264_LEVEL4_2 = 42, HB_VP_H264_LEVEL5 = 50, HB_VP_H264_LEVEL5_1 = 51, HB_VP_H264_LEVEL5_2 = 52 } hbVPH264Level;

Level enumeration under the H.264 coding protocol.

typedef struct { hbVPH264Profile h264Profile; hbVPH264Level h264Level; } hbVPH264EncConfig;

H.264 encoding protocol configuration parameter.

  • Member

    Member NameDescription
    h264ProfileProfile for the H.264 coding protocol.
    Value range [0, 4], default value HB_VP_H264_PROFILE_UNSPECIFIED.
    h264LevelLevel of the H.264 coding protocol.
    default value HB_VP_H264_LEVEL_UNSPECIFIED
typedef enum { HB_VP_H265_LEVEL_UNSPECIFIED, HB_VP_H265_LEVEL1 = 30, HB_VP_H265_LEVEL2 = 60, HB_VP_H265_LEVEL2_1 = 63, HB_VP_H265_LEVEL3 = 90, HB_VP_H265_LEVEL3_1 = 93, HB_VP_H265_LEVEL4 = 120, HB_VP_H265_LEVEL4_1 = 123, HB_VP_H265_LEVEL5 = 150, HB_VP_H265_LEVEL5_1 = 153 } hbVPH265Level;

Level enumeration under H.265 coding protocol.

typedef struct { int32_t h265Tier; uint32_t transformSkipEnable; uint32_t losslessMode; uint32_t tmvpEnable; uint32_t wppEnable; uint8_t mainStillPictureProfileEnable; hbVPH265Level h265Level; } hbVPH265EncConfig;

H.265 encoding protocol configuration parameter.

  • Member

    Member NameDescription
    h265TierVPU supports main tier and high tier. Value range [0, 1], default value 0.
    transformSkipEnableEnable transform_skip mode, value range [0, 1], default value 1. When the picture content and background similarity are higher, some unnecessary computations and data transmission are skipped to reduce the encoding time and data traffic, while maintaining high video quality and smoothness.
    losslessModeEnable lossless encoding mode. Value range [0, 1], default value 0.
    tmvpEnableEnable time motion vector prediction. Takes values in the range [0, 1], default value 1.
    wppEnableEnable wavefront parallel processing. Value range [0, 1], default value 0.
    mainStillPictureProfileEnableEnabling Profile for the main still frame provides better video quality and lower compression ratio. Value range [0, 1], default value 0.
    h265LevelLevel of the H.265 coding protocol. default value HB_VP_H265_LEVEL_UNSPECIFIED.
typedef struct { uint8_t pixelFormat; int32_t width; int32_t height; uint32_t outBufCount; hbVPVideoType videoType; hbVPVideoRcParam rcParam; hbVPVideoGopParam gopParam; union { hbVPH264EncConfig h264EncConfig; hbVPH265EncConfig h265EncConfig; }; } 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 8. Range Values[256, 8192].
    heightThe height of the input image should be aligned to 8. Range Values[128, 8192].
    outBufCountSpecifies the number of output Buffers inside the VPU. Range Values[1, 65536], default value 5.
    videoTypeThe type of encoding protocol.
    rcParamBit rate control parameter.
    gopParamGOP parameter.
    h264EncConfigH.264 encoding configuration parameter.
    h265EncConfigH.265 encoding configuration parameter.
int32_t hbVPGetDefaultVideoEncParam(hbVPVideoEncParam *param);

Gets the encoder default encoding parameter.

  • Parameter
    • [in] param Pointer the encoding parameter.
  • Return Value
    • Return 0 means the API was successfully executed, otherwise the execution failed.
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 pointer.
    • [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 VPU supports the creation of the highest 32 encoding or decoding contexts.
    • The VPU only supports H265 encoding.
int32_t hbVPReleaseVideoEncContext(hbVPVideoContext context);

Release the encoder context API.

  • Parameter
    • [in] context Encoder context pointer.
  • 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 VPU encoding

  • Parameter
    • [out] taskHandle Task handles are responsible for the interaction of the operator with the UCP architecture.
    • [in] srcImg Pointer the memory address where the encoded picture is stored.
    • [in] context Encoder context pointer.
  • 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.
int32_t hbVPGetVideoEncOutputBuffer(hbUCPTaskHandle_t taskHandle, hbVPArray *outBuf);

The API for calling to get the encoded data buffer.

  • Parameter
    • [in] taskHandle Task handles are responsible for the interaction of the operator with the UCP architecture.
    • [out] outBuf Pointer the memory address that holds the encoded data.
  • 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 VPU.
    • The buffer contains valid data upon the task is successfully completed, and is released during the task release phase.