7.3.9 Video Encoding
Overview
The video encoding module implements hardware encoding protocols such as H.264/H.265/JPEG/MJPEG. This module supports real-time encoding of multiple channels, with each channel being independent. Common use cases include single-channel recording, multi-channel recording, single-channel VIO video streaming, multi-channel VIO video streaming, recording + VIO video streaming, etc.
Function Description
Basic Specifications
The encoding specifications supported by X3 are as follows:
H.264/H.265 protocol encoding performance is as follows:
- H.264 decoding supports a maximum resolution of 8192 x 8192, with a minimum resolution of 256 x 128, and a minimum decoding resolution of 32 x 32.
- H.265 decoding supports a maximum resolution of 8192 x 8192, with a minimum resolution of 256 x 128, and a minimum decoding resolution of 8 x 8.
- The stride of H.264/H.265 is aligned to 32 bytes, while the width and height are aligned to 8 bytes. If they are not aligned, it is recommended to use VIDEO_CROP_INFO_S to perform corresponding cropping.
- Both H.264/H.265 have real-time multi-stream encoding capabilities.
- The highest capability supports 4K@60fps.
- ROI encoding with QP map (allows users to select regions of interest in the picture, after enabling ROI function, important or moving regions will be encoded with high-quality lossless coding, while the bitrate and image quality of regions that do not move or are not selected will be reduced, achieving standard definition video compression, or even not transmitting this part of the video)
- Supports rotation and mirroring.
- Multi-instance processing, up to 32 instances.
JPEG protocol encoding capabilities are as follows:
- Encoding and decoding resolution range from 16 x 16 to 32768 x 32768.
- MJPEG and JPEG stride are aligned to 32 bytes, width is aligned to 16 bytes, and height is aligned to 8 bytes.
- For YUV 4:2:0 format (e.g. NV12), the highest capability is 4K@30fps.
- JPEG Baseline and Extended sequential ISO/IEC 10918-1.
- Supports one or three color components, each component can have 8-bit or 12-bit sampling.
- Supports YUV 4:0:0, 4:2:0, 4:2:2, 4:4:0, and 4:4:4 color formats.
- Supports encoding and decoding ROI.
- Supports slice encoding.
- Supports rotation and mirroring.
- Multi-instance, with a maximum support of 64 instances.
Encoding and Decoding Channels
An encoding and decoding channel refers to a specific type of encoding and decoding instance. The user parameters, configuration, and resources of different encoding and decoding channels can be independent of each other, allowing for multiple channels of video encoding and decoding with different specifications to cover various business scenarios.
Bitrate Control
Bitrate control mainly refers to the control of encoding bitrate. Bitrate control is for continuous video encoding streams, and for a changing scene, if you want to achieve stable image quality, the encoding bitrate will fluctuate. If you want to achieve stable encoding bitrate, the image quality will fluctuate. X3 supports the following bitrate control methods for H.264, H.265, and MJPEG protocols:
- H.264/H.265 supports CBR, VBR, AVBR, FixQp, and QpMap five types of bitrate control modes for encoding channels.
- MJPEG encoding channel supports FixQp bitrate control mode.
CBR can ensure a stable overall encoding bitrate.
VBR ensures a stable image quality during encoding.AVBR considers both bitrate and image quality, generating a bitrate and image quality relatively stable bitstream;
FixQp fixes the QP value for each I frame, P frame, and B frame;
QPMAP assigns a QP value for each block in a frame, where the block size is 16x16 for H264 and 32x32 for H265.
For CBR and AVBR, the encoder internally finds a suitable QP value for each frame image to ensure a constant bitrate.
The encoder supports three levels of rate control internally, which are frame level, CTU/MB level, and subCTU/subMB level. The frame level control mainly generates a QP value for each frame image based on the target bitrate to ensure a constant bitrate; the CTU/MB level control generates a QP value for each block based on the target bitrate of each 64x64 CTU or 16x16 MB, which can achieve better bitrate control, but frequent QP value adjustments may cause unstable image quality; the subCTU/subMB level control generates a QP value for each 32x32 subCTU or 8x8 subMB, with complex blocks receiving higher QP values and static blocks receiving lower QP values, because the human eye is more sensitive to static regions compared to complex areas. The detection of complex and static regions mainly relies on internal hardware modules. This level of control is mainly for improving subjective image quality while ensuring a constant bitrate, and it results in higher SSIM scores but lower PSNR scores.
CBR, VBR, and AVBR can enable QPMAP, and the actual value for each block region is obtained by the following formula:
MQP is the value in the ROI map, RQP is the value obtained by the internal bitrate control of the encoder, and ROIAvaQP is the average QP value in the ROI map.
GOP Structure
The GOP structure table can define a set of periodic GOP structures that will be used throughout the encoding process. The elements in a single structure table are shown in the following table. It is possible to specify the reference frames for this image. If the reference frames specified for the frames following the IDR frame are the data frames before the IDR frame, the encoder will automatically handle this situation so that they do not reference other frames. Users do not need to be concerned about this situation. When defining a custom GOP structure, users need to specify the number of structure tables. A maximum of 8 structure tables can be defined, and the order of the structure tables needs to be arranged in decoding order.
Element | Description |
---|---|
Type | Slice type (I, P or B) |
POC | Display order of the frame within a GOP, ranging from 1 to GOP size |
QPoffset | A quantization parameter of the picture in the custom GOP |
NUM_REF_PIC_L0 | Flag to use multi-reference picture for P picture. It is valid only if PIC_TYPE is P |
temporal_id | Temporal layer of the frame. A frame cannot predict from a frame with a higher temporal ID (0~6) |
1st_ref_POC | The POC of the 1st reference picture of L0 |
2nd_ref_POC | The POC of the 1st reference picture of L1 in case that Type is equal to B. The POC of the 2nd reference picture of L0 in case that Type is equal to P. Note that reference_L1 can have the same POC as reference in B slice. But for compression efficiency, it is recommended that reference_L1 have a different POC from reference_L0. |
GOP Predefined Structures
The following table provides 8 predefined GOP structures.
Index | GOP Structure | Low Delay (encoding order and display order are the same) | GOP Size | Encoding Order | Minimum Source Frame Buffer | Minimum Decoded Picture Buffer | Intra Period (I Frame Interval) Requirement |
---|---|---|---|---|---|---|---|
1 | I | Yes | 1 | I0-I1-I2… | 1 | 1 | |
2 | P | Yes | 1 | P0-P1-P2… | 1 | 2 | |
3 | B | Yes | 1 | B0-B1-B2… | 1 | 3 | |
4 | BP | No | 2 | B1-P0-B3-P2… | 4 | 3 | Multiple of 2 |
5 | BBBP | No | 4 | B2-B1-B3-P0… | 7 | 4 | Multiple of 4 |
6 | PPPP | Yes | 4 | P0-P1-P2-P3… | 1 | 2 | |
7 | BBBB | Yes | 4 | B0-B1-B2-B3… | 1 | 3 | |
8 | BBBBBBBB | No | 8 | B3-B2-B4-B1-B6-B5-B7-B0… | 12 | 5 | Multiple of 8 |
Where: [image available for reference, not shown here]- GOP Preset1
-
Only I frames, no inter-reference frames
-
Low latency
-
GOP Preset2
- Only I frames and P frames
- P frames reference two forward reference frames
- Low latency
-
GOP Preset3
- Only I frames and B frames
- B frames reference two forward reference frames
- Low latency
-
GOP Preset4
- I frames, P frames, and B frames
- P frames reference two forward reference frames
- B frames reference one forward reference frame and one backward reference frame
-
GOP Preset5
- I frames, P frames, and B frames
- P frames reference two forward reference frames
- B frames reference one forward reference frame and one backward reference frame, where the backward reference frame can be a P frame or a B frame
-
GOP Preset 6
- Only I frames and P frames
- P frames reference two forward reference frames
- Low latency
-
GOP Preset 7
- Only I frames and B frames
- B frames reference two forward reference frames
- Low latency
-
GOP Preset 8
- Only I frames and B frames
- B frames reference one forward reference frame and one backward reference frame
Relationship between GOP and I frame period
The following figure shows the relationship between GOP structure and I frame period.
ROI
The implementation of ROI encoding is similar to QPMAP, and users need to set the QP value for each block according to the raster scan direction. The following figure shows an example of ROI map for H265. For H264 encoding, the size of each block is 16x16, while in H265, it is 32x32. In the ROI map table, each QP value occupies one byte, ranging from 0 to 51.
ROI encoding can work together with CBR and AVBR. When CBR or AVBR is not enabled, the actual QP value for each block region is the value specified in the ROI map. When CBR or AVBR is enabled, the actual value for each block region is obtained by the following formula:
MQP is the value in the ROI map, RQP is the value obtained by the encoder's internal rate control, and ROIAvaQP is the average QP value in the ROI map.
Intra Refresh
Intra Refresh mode improves fault tolerance by periodically inserting intra-coded MB/CTUs into non-I frames. It provides more repair points for the decoder to avoid image corruption caused by temporal errors. Users can specify the number of continuous rows, columns, or step size of MB/CTUs to force the encoder to insert intra-coded units. Users can also specify the size of intra-coded units, which will be determined internally by the encoder.
Long-term reference frame
Users can specify the period of long-term reference frames and the cycle of referring long-term reference frames, as shown in the following figure.
Smart background encoding
In video surveillance scenarios, the background is often static. Therefore, it is desired that the encoder can either ignore the background region or use less bitrate to encode it when detecting a background region. In actual scenarios, due to the presence of noise in the camera image, it is not easy to detect the background region. In many cases, the ISP needs to notify the encoder when it detects a background region, which consumes additional bandwidth and system computing resources.
H264 and H265 encoding provide integrated smart background encoding modes inside the codec. This mode fully utilizes internal hardware modules and on-the-fly processing, without consuming additional bandwidth and system resources. The following figure shows the working mode of background detection. In the smart background encoding mode, the internal hardware module compares each block unit with the corresponding block unit of the reference frame to determine whether the block is part of the background.
For background region judgment, users can set the maximum pixel difference value (recommended value 8) and the average pixel difference value (recommended value 1). Users can also adjust the Lambda parameter to influence the mode selection in encoding. When a background region is detected, the encoder internally increases the corresponding Lambda value for each block unit, making the encoder more likely to use ignore mode to encode the block unit. For Lambda control, users can set lambdaQP (recommended value 32) and deltaQP (recommended value 3), and the final Lambda value is calculated according to the following formula:
QP_TO_LAMBDA_TABLE is the Lambda conversion table, which is also used for Lambda conversion in non-background regions.
It should be noted that Smart background encoding does not work when ROI encoding is enabled. The amount of bandwidth saved by this mode is closely related to the set bitrate and I-frame interval. The larger the bitrate and I-frame interval, the more bandwidth can be saved. In addition, in this mode, frames with better image quality can be set as long-term reference frames to improve the quality of the background image and save bitrate.
Frame skip setting
Users can use the interface to set the encoding mode of the next input image as the skip mode. This mode is only valid for non-I frames. In skip mode, the encoder internally ignores the input frame and uses the reconstructed frame of the previous frame to generate the reconstruction frame of the current input. The input frame is then encoded as a P frame.
API Reference
HB_VENC_CreateChn: Create an encoding channel.
HB_VENC_DestroyChn: Destroy an encoding channel.
HB_VENC_ResetChn: Reset an encoding channel.
HB_VENC_StartRecvFrame: Start the encoding channel to receive input images.
HB_VENC_StopRecvFrame: Stop the encoding channel from receiving input images.
HB_VENC_SetChnAttr: Set the encoding attributes of an encoding channel.
HB_VENC_GetChnAttr: Get the encoding attributes of an encoding channel.
HB_VENC_GetStream: Get the encoded stream.
HB_VENC_ReleaseStream: Release the stream buffer.
HB_VENC_SendFrame: Support the user to send raw images for encoding.
HB_VENC_RequestIDR: Request an IDR frame.
HB_VENC_SetRoiAttr: Set the ROI encoding configuration of an encoding channel.
HB_VENC_GetRoiAttr: Get the ROI encoding configuration of an encoding channel.HB_VENC_SetH264SliceSplit: Set slice splitting configuration for H.264 encoding.
HB_VENC_GetH264SliceSplit: Get slice splitting configuration for H.264 encoding.
HB_VENC_SetH264IntraPred: Set frame intra-prediction configuration for H.264 encoding.
HB_VENC_GetH264IntraPred: Get frame intra-prediction configuration for H.264 encoding.
HB_VENC_SetH264Trans: Set transform and quantization configuration for H.264 encoding.
HB_VENC_GetH264Trans: Get transform and quantization configuration for H.264 encoding.
HB_VENC_SetH264Entropy: Set entropy coding configuration for H.264 encoding.
HB_VENC_GetH264Entropy: Get entropy coding configuration for H.264 encoding.
HB_VENC_SetH264Dblk: Set deblocking configuration for H.264 encoding.
HB_VENC_GetH264Dblk: Get deblocking configuration for H.264 encoding.
HB_VENC_SetH264Vui: Set VUI configuration for H.264 encoding.
HB_VENC_GetH264Vui: Get VUI configuration for H.264 encoding.
HB_VENC_SetH265Vui: Set VUI parameters for H.265 encoding channel.
HB_VENC_GetH265Vui: Get VUI configuration for H.265 encoding channel.
HB_VENC_SetRcParam: Set advanced parameters for channel bitrate control.
HB_VENC_GetRcParam: Get advanced parameters for channel bitrate control.
HB_VENC_SetRefParam: Set advanced skip frame reference parameters for H.264/H.265 encoding channels.
HB_VENC_GetRefParam: Get advanced skip frame reference parameters for H.264/H.265 encoding channels.
HB_VENC_SetH265SliceSplit: Set slice splitting configuration for H.265 encoding.
HB_VENC_GetH265SliceSplit: Get slice splitting configuration for H.265 encoding.
HB_VENC_SetH265PredUnit: Set PU configuration for H.265 encoding.
HB_VENC_GetH265PredUnit: Get PU configuration for H.265 encoding.
HB_VENC_SetH265Trans: Set transform and quantization configuration for H.265 encoding.
HB_VENC_GetH265Trans: Get transform and quantization configuration for H.265 encoding.
HB_VENC_SetH265Dblk: Set deblocking configuration for H.265 encoding.
HB_VENC_GetH265Dblk: Get deblocking configuration for H.265 encoding.
HB_VENC_SetH265Sao: Set SAO configuration for H.265 encoding.
HB_VENC_GetH265Sao: Get SAO configuration for H.265 encoding.
HB_VENC_GetIntraRefresh: Get parameters for P frame refreshing Islice.
HB_VENC_SetIntraRefresh: Set parameters for P frame refreshing Islice.
HB_VENC_SetCuPrediction: Set tendency for CU mode prediction.
HB_VENC_GetCuPrediction: Get configuration for CU mode prediction.
HB_VENC_GetFd: Get device file handle for encoding channel.
HB_VENC_CloseFd: Close device file handle for encoding channel.
HB_VENC_QueryStatus: Query status of encoding channel.
HB_VENC_InserUserData: Insert user data.
HB_VENC_SendFrameEx: Send raw image and QpMap table for encoding.
HB_VENC_CreateChn
Function Declaration
int32_t HB_VENC_CreateChn(VENC_CHN VeChn, const VENC_CHN_ATTR_S *pstAttr);
Function Description
Creates an encoding channel.
Parameter Descriptions
Parameter Name | Description | Input/Output |
---|---|---|
VeChn | Channel number for encoding. Range: [0, VENC_MAX_CHN_NUM). H264/H265 supports up to 32 channels, JPEG/MJPEG up to 64 channels. | Input |
pstAttr | Pointer to the encoding channel attributes | Input |
Return Values
Return Value | Description |
---|---|
0 | Success |
Non-zero | Failure, refer to error codes. |
Note
None
Reference Code
See HB_VENC_GetStream for reference code.
HB_VENC_DestroyChn
Function Declaration
int32_t HB_VENC_DestroyChn(VENC_CHN VeChn);
Function Description
Destroys an encoding channel.
Parameter Descriptions
Parameter Name | Description | Input/Output |
---|---|---|
VeChn | Encoding channel number. Range: [0, VENC_MAX_CHN_NUM) | Input |
Return Values
Return Value | Description |
---|---|
0 | Success |
Non-zero | Failure, refer to the error code. |
Note
None
Reference Code
HB_VENC_GetStream reference code
HB_VENC_ResetChn
Function Declaration
int32_t HB_VENC_ResetChn(VENC_CHN VeChn);
Function Description
Resets an encoding channel.
Parameter Descriptions
Parameter Name | Description | Input/Output |
---|---|---|
VeChn | Encoding channel number. Range: [0, VENC_MAX_CHN_NUM) | Input |
Return Values
Return Value | Description |
---|---|
0 | Success |
Non-zero | Failure, refer to the error code. |
Note
None
Reference Code
HB_VENC_GetStream reference code
HB_VENC_StartRecvFrame
Function Declaration
int32_t HB_VENC_StartRecvFrame(VENC_CHN VeChn, const VENC_RECV_PIC_PARAM_S *pstRecvParam);
Function Description
Enables receiving input images for the encoding channel.
Parameter Descriptions
Parameter Name | Description | Input/Output |
---|---|---|
VeChn | Encoding channel number. Range: [0, VENC_MAX_CHN_NUM) | Input |
pstRecvParam | Pointer to the receive image parameter structure, used to specify the number of frames to be received. | Input |
Return Values
Return Value | Description |
---|---|
0 | Success |
Non-zero | Failure, refer to the error code. |
Note
This function must be called after setting channel attributes with HB_VENC_SetChnAttr.
Reference Code
HB_VENC_GetStream reference code
HB_VENC_StopRecvFrame
Function Declaration
int32_t HB_VENC_StopRecvFrame(VENC_CHN VeChn);
Function Description
Stops receiving input images for the encoding channel.
Parameter Descriptions
Parameter Name | Description | Input/Output |
---|---|---|
VeChn | Encoding channel number. Range: [0, VENC_MAX_CHN_NUM) | Input |
Return Values
Return Value | Description |
---|---|
0 | Success |
Non-zero | Failure, refer to the error code. |
Note
None
Reference Code
HB_VENC_GetStream reference code
HB_VENC_SetChnAttr
Function Declaration
int32_t HB_VENC_SetChnAttr(VENC_CHN VeChn, const VENC_CHN_ATTR_S *pstChnAttr);
Function Description
Sets the encoding attributes for an encoding channel.
Parameter Descriptions
Parameter Name | Description | Input/Output |
---|---|---|
VeChn | Encoding channel number. Range: [0, VENC_MAX_CHN_NUM) | Input |
pstChnAttr | Pointer to the encoding channel attribute structure. | Input |
Return Values
Return Value | Description |
---|---|
0 | Success |
Non-zero | Failure, refer to the error code. |
Note
A channel must be created using HB_VENC_CreateChn before calling this function.
Reference Code
HB_VENC_GetStream reference code
HB_VENC_GetChnAttr
【Function Declaration】
int32_t HB_VENC_GetChnAttr(VENC_CHN VeChn, VENC_CHN_ATTR_S *pstChnAttr);
【Function Description】
Get the encoding attributes of the encoding channel.
【Parameter Description】
Parameter Name | Description | Input/Output |
---|---|---|
VeChn | Encoding channel number. Value range: [0, VENC_MAX_CHN_NUM) | Input |
pstChnAttr | Pointer to encoding channel attributes | Input |
【Return Value】
Return Value | Description |
---|---|
0 | Success |
Non-zero | Failure. Refer to error code. |
【Notes】
None
【Reference code】
Reference code for HB_VENC_GetStream
HB_VENC_GetStream
【Function Declaration】
int32_t HB_VENC_GetStream(VENC_CHN VeChn, VIDEO_STREAM_S *pstStream, int32_t s32MilliSec);
【Function Description】
Get the encoding stream.
【Parameter Description】
Parameter Name | Description | Input/Output |
---|---|---|
VeChn | Encoding channel number. Value range: [0, VENC_MAX_CHN_NUM) | Input |
pstStream | Pointer to the stream structure | Input |
s32MilliSec | Timeout for getting the stream. Value range: [-1, + ∞ ) -1: Block. 0: Non-block. Greater than 0: Timeout duration. | Input |
【Return Value】| Return Value | Description | | :----------: | :---------------- | | 0 | Success | | Non-zero | Failure, see error code. |
【Notes】
None
【Reference Code】
VENC_CHN VeChn = 0;
int32_t s32Ret = 0;
int32_t Width = 640;
int32_t Height = 480;
FILE *inFile;
char *inputFileName = "./venc/yuv/input_640x480_yuv420p.yuv";
inFile = fopen(inputFileName, "rb");
ASSERT_NE(inFile, nullptr);
char* mmz_vaddr[10];
int32_t i = 0;
for (i=0;i<10;i++) {
mmz_vaddr[i] = NULL;
}
uint64_t mmz_paddr[10];
memset(mmz_paddr, 0, sizeof(mmz_paddr));
int32_t mmz_size = Width * Height * 3 / 2;
VP_CONFIG_S struVpConf;
memset(&struVpConf, 0x00, sizeof(VP_CONFIG_S));
struVpConf.u32MaxPoolCnt = 32;
HB_VP_SetConfig(&struVpConf);
s32Ret = HB_VP_Init();
if (s32Ret != 0) {
printf("vp_init fail s32Ret = %d !\n",s32Ret);
}
for (i = 0; i < 10; i++) {
s32Ret = HB_SYS_Alloc(&mmz_paddr[i], (void **)&mmz_vaddr[i], mmz_size);
if (s32Ret == 0) {
printf("mmzAlloc paddr = 0x%x, vaddr = 0x%x i = %d \n", mmz_paddr[i], mmz_vaddr[i],i);
}
}
int32_t s32ReadLen = 0;
for (i = 0; i < 10; i++) {
s32ReadLen = fread(mmz_vaddr[i], 1, mmz_size, inFile);printf("s32ReadLen = %d !!!!!\n", s32ReadLen);
if (s32ReadLen == 0) {
printf("read over !!!\n");
}
}
/* if (inFile) fclose(inFile); */
VENC_CHN_ATTR_S m_VencChnAttr;
memset(&m_VencChnAttr, 0, sizeof(VENC_CHN_ATTR_S));
m_VencChnAttr.stVencAttr.enType = PT_H264;
m_VencChnAttr.stVencAttr.u32PicWidth = Width;
m_VencChnAttr.stVencAttr.u32PicHeight = Height;
m_VencChnAttr.stVencAttr.enMirrorFlip = DIRECTION_NONE;
m_VencChnAttr.stVencAttr.enRotation = CODEC_ROTATION_0;
m_VencChnAttr.stVencAttr.stCropCfg.bEnable = HB_FALSE;
m_VencChnAttr.stVencAttr.stAttrH264.h264_profile = 0;
m_VencChnAttr.stVencAttr.stAttrH264.h264_level = 0;
m_VencChnAttr.stGopAttr.u32GopPresetIdx = 2;
m_VencChnAttr.stGopAttr.s32DecodingRefreshType = 2;
m_VencChnAttr.stRcAttr.enRcMode = VENC_RC_MODE_H264CBR;
VENC_RC_ATTR_S *pstRcParam = &(m_VencChnAttr.stRcAttr);
s32Ret = HB_VENC_GetRcParam(VeChn, pstRcParam);
pstRcParam->stH264Cbr.u32BitRate = 3000;
pstRcParam->stH264Cbr.u32FrameRate = 30;
pstRcParam->stH264Cbr.u32IntraPeriod = 30;
pstRcParam->stH264Cbr.u32VbvBufferSize = 3000;
s32Ret = HB_VENC_CreateChn(VeChn, &m_VencChnAttr);
HB_VENC_SetChnAttr(VeChn, &m_VencChnAttr); // config
VENC_RECV_PIC_PARAM_S pstRecvParam;
pstRecvParam.s32RecvPicNum = 0; // unchangable
s32Ret = HB_VENC_StartRecvFrame(VeChn, &pstRecvParam);
VIDEO_FRAME_S pstFrame;
VIDEO_STREAM_S pstStream;
memset(&pstFrame, 0, sizeof(VIDEO_FRAME_S));
memset(&pstStream, 0, sizeof(VIDEO_STREAM_S));
pstFrame.stVFrame.width = Width;
pstFrame.stVFrame.height = Height;
pstFrame.stVFrame.size = mmz_size;
int32_t offset = Width * Height;
for (i=0;i<10;i++) {
pstFrame.stVFrame.phy_ptr[0] = mmz_paddr[i];
pstFrame.stVFrame.phy_ptr[1] = mmz_paddr[i] + offset;
pstFrame.stVFrame.phy_ptr[2] = mmz_paddr[i] + offset * 5 / 4;
pstFrame.stVFrame.vir_ptr[0] = mmz_vaddr[i];
pstFrame.stVFrame.vir_ptr[1] = mmz_vaddr[i] + offset;
pstFrame.stVFrame.vir_ptr[2] = mmz_vaddr[i] + offset * 5 / 4;\# If i is equal to 9
if (i == 9) {
pstFrame.stVFrame.frame_end = HB_TRUE;
}
s32Ret = HB_VENC_SendFrame(VeChn, &pstFrame, 3000);
usleep(300000);
s32Ret = HB_VENC_GetStream(VeChn, &pstStream, 3000);
EXPECT_EQ(s32Ret, (int32_t)0);
printf("i = %d pstStream.pstPack.size = %d !!!!!\n", i, pstStream.pstPack.size);
s32Ret = HB_VENC_ReleaseStream(VeChn, &pstStream);
}
s32Ret = HB_VENC_StopRecvFrame(VeChn);
s32Ret = HB_VENC_DestroyChn(VeChn);
for (i = 0; i < 10; i++) {
s32Ret = HB_SYS_Free(mmz_paddr[i], mmz_vaddr[i]);
if (s32Ret == 0) {
printf("mmzFree paddr = 0x%x, vaddr = 0x%x i = %d \n", mmz_paddr[i],
mmz_vaddr[i], i);
}
}
s32Ret = HB_VP_Exit();
if (s32Ret == 0) printf("vp exit ok!\n");
printf("GetStream_Test\n");
if (inFile) fclose(inFile);
HB_VENC_ReleaseStream
【Function Declaration】
int32_t HB_VENC_ReleaseStream(VENC_CHN VeChn, VIDEO_STREAM_S *pstStream);
【Function Description】
Release stream buffer.
【Parameter Description】
Parameter | Description | Input/Output |
---|---|---|
VeChn | Encoding channel number. Range: [0, VENC_MAX_CHN_NUM) | Input |
pstStream | Pointer of stream structure | Input |
【Return Value】
Return Value | Description |
---|---|
0 | Success |
Non-zero | Fail, see error code |
【Notes】Please translate the following Chinese parts into English, while keeping the original format and content:
None
【Reference Code】
HB_VENC_GetStream reference code
HB_VENC_SendFrame
【Function Declaration】
int32_t HB_VENC_SendFrame(VENC_CHN VeChn, VIDEO_FRAME_S *pstFrame ,int32_t s32MilliSec);
【Function Description】
Supports sending original images for encoding.
【Parameter Description 】
Parameter | Description | Input/Output |
---|---|---|
VeChn | Encoding channel number. Range: [0, VENC_MAX_CHN_NUM) | Input |
pstFrame | Pointer to the structure of the original image information. | Input |
s32MilliSec | Timeout for obtaining the bitstream. Range: [-1, +∞) -1: Block. 0: Non-block. >0: Timeout. | Input |
【Return Value】
Return Value | Description |
---|---|
0 | Success |
Non-zero | Failure, see error code. |
【Notes】
None
【Reference Code】
HB_VENC_GetStream reference code
HB_VENC_RequestIDR
Function Declaration
int32_t HB_VENC_RequestIDR(VENC_CHN VeChn);
Function Description
Requests an IDR frame.
Parameter Descriptions
Parameter Name | Description | Input/Output |
---|---|---|
VeChn | Encoding channel number. Range: [0, VENC_MAX_CHN_NUM) | Input |
Return Values
Return Value | Description |
---|---|
0 | Success |
Non-zero | Failure, refer to error codes. |
Note
None
Reference Code
VENC_CHN VeChn = 0;
int32_t s32Ret = 0;
int32_t Width = 1920;
int32_t Height = 1080;
VENC_CHN_ATTR_S m_VencChnAttr;
memset(&m_VencChnAttr, 0, sizeof(VENC_CHN_ATTR_S));
m_VencChnAttr.stVencAttr.enType = PT_H264;
m_VencChnAttr.stVencAttr.u32PicWidth = Width;
m_VencChnAttr.stVencAttr.u32PicHeight = Height;
m_VencChnAttr.stVencAttr.enMirrorFlip = DIRECTION_NONE;
m_VencChnAttr.stVencAttr.enRotation = CODEC_ROTATION_0;
m_VencChnAttr.stVencAttr.stCropCfg.bEnable = HB_FALSE;
m_VencChnAttr.stVencAttr.stAttrH264.h264_profile = 0;
m_VencChnAttr.stVencAttr.stAttrH264.h264_level = 0;
m_VencChnAttr.stGopAttr.u32GopPresetIdx = 2;
m_VencChnAttr.stGopAttr.s32DecodingRefreshType = 2;
m_VencChnAttr.stRcAttr.enRcMode = VENC_RC_MODE_H264CBR;
VENC_RC_ATTR_S *pstRcParam = &(m_VencChnAttr.stRcAttr);
s32Ret = HB_VENC_GetRcParam(VeChn, pstRcParam);
pstRcParam->stH264Cbr.u32BitRate = 3000;
pstRcParam->stH264Cbr.u32FrameRate = 30;
pstRcParam->stH264Cbr.u32IntraPeriod = 30;
pstRcParam->stH264Cbr.u32VbvBufferSize = 3000;
s32Ret = HB_VENC_CreateChn(VeChn, &m_VencChnAttr);
HB_VENC_SetChnAttr(VeChn, &m_VencChnAttr);
s32Ret = HB_VENC_RequestIDR(VeChn);
s32Ret = HB_VENC_DestroyChn(VeChn);
HB_VENC_SetRoiAttr
Function Declaration
int32_t HB_VENC_SetRoiAttr(VENC_CHN VeChn, const VENC_ROI_ATTR_S *pstRoiAttr);
Function Description
Sets the ROI (Region of Interest) encoding configuration for a video coding channel.
Parameter Descriptions
Parameter Name | Description | Input/Output |
---|---|---|
VeChn | Encoding channel number. Range: [0, VENC_MAX_CHN_NUM) | Input |
pstRoiAttr | Pointer to ROI area parameters | Input |
Return Values
Return Value | Description |
---|---|
0 | Successful |
Non-zero | Failure; see error codes for details |
Caution
None
Reference Code
HB_VENC_GetRoiAttr reference code
HB_VENC_GetRoiAttr
Function Declaration
int32_t HB_VENC_GetRoiAttr(VENC_CHN VeChn, VENC_ROI_ATTR_S *pstRoiAttr);
Function Description
Retrieves the ROI (Region of Interest) encoding configuration for a video coding channel.
Parameter Descriptions
Parameter Name | Description | Input/Output |
---|---|---|
VeChn | Encoding channel number. Range: [0, VENC_MAX_CHN_NUM) | Input |
pstRoiAttr | Pointer to the ROI configuration that will receive the retrieved data | Output |
Return Values
Return Value | Description |
---|---|
0 | Successful |
Non-zero | Failure; see error codes for details |
Caution
None
Example Code
VENC_CHN VeChn = 0;
int32_t s32Ret = 0;
int32_t Width = 1920;
int32_t Height = 1080;
VENC_ROI_ATTR_S pstRoiAttrTest1;
memset(&pstRoiAttrTest1, 0, sizeof(VENC_ROI_ATTR_S));
uint8_t stroi_map_array1[100] = {0};
pstRoiAttrTest1.roi_map_array = stroi_map_array1;
VENC_CHN_ATTR_S m_VencChnAttr;
memset(&m_VencChnAttr, 0, sizeof(VENC_CHN_ATTR_S));
m_VencChnAttr.stVencAttr.enType = PT_H264;
m_VencChnAttr.stVencAttr.u32PicWidth = Width;
m_VencChnAttr.stVencAttr.u32PicHeight = Height;
m_VencChnAttr.stVencAttr.enMirrorFlip = DIRECTION_NONE;
m_VencChnAttr.stVencAttr.enRotation = CODEC_ROTATION_0;
m_VencChnAttr.stVencAttr.stCropCfg.bEnable = HB_FALSE;
m_VencChnAttr.stVencAttr.stAttrH264.h264_profile = 0;
m_VencChnAttr.stVencAttr.stAttrH264.h264_level = 0;
m_VencChnAttr.stGopAttr.u32GopPresetIdx = 2;
m_VencChnAttr.stGopAttr.s32DecodingRefreshType = 2;
m_VencChnAttr.stRcAttr.enRcMode = VENC_RC_MODE_H264CBR;
VENC_RC_ATTR_S *pstRcParam = &(m_VencChnAttr.stRcAttr);
s32Ret = HB_VENC_GetRcParam(VeChn, pstRcParam);
pstRcParam->stH264Cbr.u32BitRate = 3000;
pstRcParam->stH264Cbr.u32FrameRate = 30;
pstRcParam->stH264Cbr.u32IntraPeriod = 30;
pstRcParam->stH264Cbr.u32VbvBufferSize = 3000;
s32Ret = HB_VENC_CreateChn(VeChn, &m_VencChnAttr);
VENC_ROI_ATTR_S pstRoiAttrTest2;
memset(&pstRoiAttrTest1, 0, sizeof(VENC_ROI_ATTR_S));
uint8_t stroi_map_array[100] = {0};
pstRoiAttrTest2.roi_enable = HB_TRUE;
pstRoiAttrTest2.roi_map_array = stroi_map_array;
pstRoiAttrTest2.roi_map_array_count = 100;
s32Ret = HB_VENC_SetRoiAttr(VeChn, &pstRoiAttrTest2);
s32Ret = HB_VENC_GetRoiAttr(VeChn, &pstRoiAttrTest1);
s32Ret = HB_VENC_DestroyChn(VeChn);
HB_VENC_SetH264SliceSplit
Function Declaration
int32_t HB_VENC_SetH264SliceSplit(VENC_CHN VeChn, const VENC_H264_SLICE_SPLIT_S *pstSliceSplit);
Function Description
Configures the H.264 encoding slice splitting parameters.
Parameter Descriptions
Parameter Name | Description | Input/Output |
---|---|---|
VeChn | Encoding channel number. Range: [0, VENC_MAX_CHN_NUM) | Input |
pstSliceSplit | H.264 stream slice splitting parameters | Input |
Return Values
Return Value | Description |
---|---|
0 | Success |
Non-zero | Failure, refer to error code. |
Caution
None
Reference Code HB_VENC_GetH264SliceSplit Reference Code
HB_VENC_GetH264SliceSplit
Function Declaration
int32_t HB_VENC_GetH264SliceSplit(VENC_CHN VeChn, VENC_H264_SLICE_SPLIT_S *pstSliceSplit);
Function Description
Retrieves the H.264 encoding slice splitting configuration.
Parameter Descriptions
Parameter Name | Description | Input/Output |
---|---|---|
VeChn | Encoding channel number. Range: [0, VENC_MAX_CHN_NUM) | Input |
pstSliceSplit | H.264 stream slice splitting parameters | Output |
Return Values
Return Value | Description |
---|---|
0 | Success |
Non-zero | Failure, refer to error code. |
Caution
None
Reference Code
VENC_CHN VeChn = 0;
int32_t Width = 1920;
int32_t Height = 1080;
int32_t s32Ret = 0;
VENC_H264_SLICE_SPLIT_S pstSliceSplit1;
memset(&pstSliceSplit1, 0, sizeof(VENC_H264_SLICE_SPLIT_S));
VENC_CHN_ATTR_S m_VencChnAttr;
memset(&m_VencChnAttr, 0, sizeof(VENC_CHN_ATTR_S));
m_VencChnAttr.stVencAttr.enType = PT_H264;
m_VencChnAttr.stVencAttr.u32PicWidth = Width;
m_VencChnAttr.stVencAttr.u32PicHeight = Height;
m_VencChnAttr.stVencAttr.enMirrorFlip = DIRECTION_NONE;
m_VencChnAttr.stVencAttr.enRotation = CODEC_ROTATION_0;
m_VencChnAttr.stVencAttr.stCropCfg.bEnable = HB_FALSE;
m_VencChnAttr.stVencAttr.stAttrH264.h264_profile = 0;
m_VencChnAttr.stVencAttr.stAttrH264.h264_level = 0;
m_VencChnAttr.stGopAttr.u32GopPresetIdx = 2;
m_VencChnAttr.stGopAttr.s32DecodingRefreshType = 2;
m_VencChnAttr.stRcAttr.enRcMode = VENC_RC_MODE_H264CBR;
VENC_RC_ATTR_S *pstRcParam = &(m_VencChnAttr.stRcAttr);
s32Ret = HB_VENC_GetRcParam(VeChn, pstRcParam);
pstRcParam->stH264Cbr.u32BitRate = 3000;
pstRcParam->stH264Cbr.u32FrameRate = 30;
pstRcParam->stH264Cbr.u32IntraPeriod = 30;
pstRcParam->stH264Cbr.u32VbvBufferSize = 3000;
s32Ret = HB_VENC_CreateChn(VeChn, &m_VencChnAttr);
HB_VENC_SetChnAttr(VeChn, &m_VencChnAttr); // config
pstSliceSplit1.h264_slice_mode = HB_TRUE;
pstSliceSplit1.h264_slice_arg = 10;
pstSliceSplit1.slice_loop_filter_across_slices_enabled_flag = HB_TRUE;
s32Ret = HB_VENC_SetH264SliceSplit(VeChn, &pstSliceSplit1);
VENC_H264_SLICE_SPLIT_S pstSliceSplit2;
memset(&pstSliceSplit2, 0, sizeof(VENC_H264_SLICE_SPLIT_S));
s32Ret = HB_VENC_GetH264SliceSplit(VeChn, &pstSliceSplit2);
s32Ret = HB_VENC_DestroyChn(VeChn);
HB_VENC_SetH264IntraPred
Function Declaration
int32_t HB_VENC_SetH264IntraPred(VENC_CHN VeChn, const VENC_H264_INTRA_PRED_S *pstH264IntraPred);
Function Description
Configures the intra prediction settings for H.264 encoding.
Parameter Descriptions
Parameter Name | Description | Input/Output |
---|---|---|
VeChn | Encoding channel number. Range: [0, VENC_MAX_CHN_NUM) | Input |
pstH264IntraPred | H.264 protocol's intra prediction configuration | Input |
Return Values
Return Value | Description |
---|---|
0 | Success |
Non-zero | Failure, refer to error codes. |
Note
None
Reference Code HB_VENC_GetH264IntraPred reference code
HB_VENC_GetH264IntraPred
Function Declaration
int32_t HB_VENC_GetH264IntraPred(VENC_CHN VeChn, VENC_H264_INTRA_PRED_S *pstH264IntraPred);
Function Description
Retrieves the intra prediction configuration for H.264 encoding.
Parameter Descriptions
Parameter Name | Description | Input/Output |
---|---|---|
VeChn | Encoding channel number. Range: [0, VENC_MAX_CHN_NUM) | Input |
pstH264IntraPred | H.264 protocol's intra prediction configuration | Output |
Return Values
Return Value | Description |
---|---|
0 | Success |
Non-zero | Failure, refer to error codes. |
Note
None
Reference Code
int32_t s32Ret = 0;
VENC_CHN VeChn = 0;
int32_t Width = 1920;
int32_t Height = 1080;
VENC_H264_INTRA_PRED_S pstH264IntraPred1;
memset(&pstH264IntraPred1, 0, sizeof(VENC_H264_INTRA_PRED_S));
VENC_CHN_ATTR_S m_VencChnAttr;
memset(&m_VencChnAttr, 0, sizeof(VENC_CHN_ATTR_S));
m_VencChnAttr.stVencAttr.enType = PT_H264;
m_VencChnAttr.stVencAttr.u32PicWidth = Width;
m_VencChnAttr.stVencAttr.u32PicHeight = Height;
m_VencChnAttr.stVencAttr.enMirrorFlip = DIRECTION_NONE;
m_VencChnAttr.stVencAttr.enRotation = CODEC_ROTATION_0;
m_VencChnAttr.stVencAttr.stCropCfg.bEnable = HB_FALSE;
m_VencChnAttr.stVencAttr.stAttrH264.h264_profile = 0;
m_VencChnAttr.stVencAttr.stAttrH264.h264_level = 0;
m_VencChnAttr.stGopAttr.u32GopPresetIdx = 2;
m_VencChnAttr.stGopAttr.s32DecodingRefreshType = 2;
m_VencChnAttr.stRcAttr.enRcMode = VENC_RC_MODE_H264CBR;
VENC_RC_ATTR_S *pstRcParam = &(m_VencChnAttr.stRcAttr);
s32Ret = HB_VENC_GetRcParam(VeChn, pstRcParam);
pstRcParam->stH264Cbr.u32BitRate = 3000;
pstRcParam->stH264Cbr.u32FrameRate = 30;
pstRcParam->stH264Cbr.u32IntraPeriod = 30;
pstRcParam->stH264Cbr.u32VbvBufferSize = 3000;
s32Ret = HB_VENC_CreateChn(VeChn, &m_VencChnAttr);
pstH264IntraPred1.constrained_intra_pred_flag = HB_TRUE;
s32Ret = HB_VENC_SetH264IntraPred(VeChn, &pstH264IntraPred1);
VENC_H264_INTRA_PRED_S pstH264IntraPred2;
memset(&pstH264IntraPred2, 0, sizeof(VENC_H264_INTRA_PRED_S));
s32Ret = HB_VENC_GetH264IntraPred(VeChn, &pstH264IntraPred2);
s32Ret = HB_VENC_DestroyChn(VeChn);
HB_VENC_SetH264Trans
Function Declaration
int32_t HB_VENC_SetH264Trans(VENC_CHN VeChn, const VENC_H264_TRANS_S *pstH264Trans);
Function Description
Configures the H.264 encoding transformation and quantization settings.
Parameter Descriptions
Parameter Name | Description | Input/Output |
---|---|---|
VeChn | Encoding channel number. Range: [0, VENC_MAX_CHN_NUM) | Input |
pstH264Trans | H.264 protocol-specific channel transformation and quantization attributes | Input |
Return Values
Return Value | Description |
---|---|
0 | Success |
Non-zero | Failure; refer to error codes |
Note
None
Reference Code
int32_t s32Ret = 0;
VENC_CHN VeChn = 0;
int32_t Width = 1920;
int32_t Height = 1080;
VENC_H264_TRANS_S pstH264Trans1;
memset(&pstH264Trans1, 0, sizeof(VENC_H264_TRANS_S));
VENC_CHN_ATTR_S m_VencChnAttr;
memset(&m_VencChnAttr, 0, sizeof(VENC_CHN_ATTR_S));
m_VencChnAttr.stVencAttr.enType = PT_H264;
m_VencChnAttr.stVencAttr.u32PicWidth = Width;
m_VencChnAttr.stVencAttr.u32PicHeight = Height;
m_VencChnAttr.stVencAttr.enMirrorFlip = DIRECTION_NONE;
m_VencChnAttr.stVencAttr.enRotation = CODEC_ROTATION_0;
m_VencChnAttr.stVencAttr.stCropCfg.bEnable = HB_FALSE;
m_VencChnAttr.stVencAttr.stAttrH264.h264_profile = 0;
m_VencChnAttr.stVencAttr.stAttrH264.h264_level = 0;
m_VencChnAttr.stGopAttr.u32GopPresetIdx = 2;
m_VencChnAttr.stGopAttr.s32DecodingRefreshType = 2;
m_VencChnAttr.stRcAttr.enRcMode = VENC_RC_MODE_H264CBR;
s32Ret = HB_VENC_GetRcParam(VeChn, &m_VencChnAttr.stRcAttr);
m_VencChnAttr.stRcAttr.stH264Cbr.u32BitRate = 3000;
m_VencChnAttr.stRcAttr.stH264Cbr.u32FrameRate = 30;
m_VencChnAttr.stRcAttr.stH264Cbr.u32IntraPeriod = 30;
m_VencChnAttr.stRcAttr.stH264Cbr.u32VbvBufferSize = 3000;
s32Ret = HB_VENC_CreateChn(VeChn, &m_VencChnAttr);
HB_VENC_SetChnAttr(VeChn, &m_VencChnAttr);
pstH264Trans1.chroma_cb_qp_offset = 5;
pstH264Trans1.chroma_cr_qp_offset = 5;
pstH264Trans1.transform_8x8_enable = HB_TRUE;
pstH264Trans1.user_scaling_list_enable = 1;
s32Ret = HB_VENC_SetH264Trans(VeChn, &pstH264Trans1);
VENC_H264_TRANS_S pstH264Trans2;
memset(&pstH264Trans2, 0, sizeof(VENC_H264_TRANS_S));
s32Ret = HB_VENC_GetH264Trans(VeChn, &pstH264Trans2);
s32Ret = HB_VENC_DestroyChn(VeChn);
HB_VENC_GetH264Vui
Function Declaration
int32_t HB_VENC_GetH264Vui(VENC_CHN VeChn, VENC_H264_VUI_S *pstH264Vui);
Function Description
Retrieves the VUI configuration for H.264 encoding.
Parameter Descriptions
Parameter Name | Description | Input/Output |
---|---|---|
VeChn | Encoding channel number. Range: [0, VENC_MAX_CHN_NUM) | Input |
pstH264Vui | Pointer to the H.264 protocol's Vui parameters for the encoding channel | Output |
Return Values
Return Value | Description |
---|---|
0 | Success |
Non-zero | Failure, refer to the error code. |
Note
None
Reference Code HB_VENC_SetH264Vui reference code
HB_VENC_SetH265Vui
Function Declaration
int32_t HB_VENC_SetH265Vui(VENC_CHN VeChn, const VENC_H265_VUI_S *pstH265Vui);
Function Description
Sets the VUI configuration for H.265 encoding channels.
Parameter Descriptions
Parameter Name | Description | Input/Output |
---|---|---|
VeChn | Encoding channel number. Range: [0, VENC_MAX_CHN_NUM) | Input |
pstH265Vui | Pointer to the H.265 protocol's Vui parameters for the encoding channel | Input |
Return Values
Return Value | Description |
---|---|
0 | Success |
Non-zero | Failure, refer to the error code. |
Note
None
Reference Code
int32_t s32Ret = 0;
VENC_CHN VeChn = 0;
int32_t Width = 1920;
int32_t Height = 1080;
VENC_H265_VUI_S pstH265Vui1;
memset(&pstH265Vui1, 0, sizeof(VENC_H265_VUI_S));
VENC_CHN_ATTR_S m_VencChnAttr;
memset(&m_VencChnAttr, 0, sizeof(VENC_CHN_ATTR_S));
m_VencChnAttr.stVencAttr.enType = PT_H265;
m_VencChnAttr.stVencAttr.u32PicWidth = Width;
m_VencChnAttr.stVencAttr.u32PicHeight = Height;
m_VencChnAttr.stVencAttr.enMirrorFlip = DIRECTION_NONE;
m_VencChnAttr.stVencAttr.enRotation = CODEC_ROTATION_0;
m_VencChnAttr.stVencAttr.stCropCfg.bEnable = HB_FALSE;
m_VencChnAttr.stGopAttr.u32GopPresetIdx = 2;
m_VencChnAttr.stGopAttr.s32DecodingRefreshType = 2;
m_VencChnAttr.stRcAttr.enRcMode = VENC_RC_MODE_H265CBR;
VENC_RC_ATTR_S *pstRcParam = &(m_VencChnAttr.stRcAttr);
s32Ret = HB_VENC_GetRcParam(VeChn, pstRcParam);
pstRcParam->stH265Cbr.u32BitRate = 3000;
pstRcParam->stH265Cbr.u32FrameRate = 30;
pstRcParam->stH265Cbr.u32IntraPeriod = 30;
pstRcParam->stH265Cbr.u32VbvBufferSize = 3000;
s32Ret = HB_VENC_CreateChn(VeChn, &m_VencChnAttr);
pstH265Vui1.stVuiTimeInfo.num_ticks_poc_diff_one_minus1 = 1;
pstH265Vui1.stVuiTimeInfo.num_units_in_tick = 2000;
pstH265Vui1.stVuiTimeInfo.time_scale = 50000;
s32Ret = HB_VENC_SetH265Vui(VeChn, &pstH265Vui1);
VENC_H265_VUI_S pstH265Vui2;
memset(&pstH265Vui2, 0, sizeof(VENC_H265_VUI_S));
s32Ret = HB_VENC_GetH265Vui(VeChn, &pstH265Vui2);
HB_VENC_SetChnAttr(VeChn, &m_VencChnAttr);
s32Ret = HB_VENC_DestroyChn(VeChn);
HB_VENC_GetH265Vui
Function Declaration
int32_t HB_VENC_GetH265Vui(VENC_CHN VeChn, VENC_H265_VUI_S *pstH265Vui);
Function Description
Retrieves the VUI configuration for an H.265 encoding channel.
Parameter Descriptions
Parameter Name | Description | Input/Output |
---|---|---|
VeChn | Encoding channel number. Range: [0, VENC_MAX_CHN_NUM) | Input |
pstH265Vui | Pointer to the H.265 VUI parameters | Output |
Return Values
Return Value | Description |
---|---|
0 | Success |
Non-zero | Failure, refer to error codes |
Note
None
Reference Code
Refer to the HB_VENC_SetH265Vui reference code for more details.
HB_VENC_SetRcParam
Function Declaration
int32_t HB_VENC_SetRcParam(VENC_CHN VeChn, const VENC_RC_ATTR_S *pstRcParam);
Function Description
Sets advanced rate control parameters for the encoding channel.
Parameter Descriptions
Parameter Name | Description | Input/Output |
---|---|---|
VeChn | Encoding channel number. Range: [0, VENC_MAX_CHN_NUM) | Input |
pstRcParam | Pointer to the advanced rate controller parameters | Input |
Return Values
Return Value | Description |
---|---|
0 | Success |
Non-zero | Failure, refer to error codes |
Note
None
Reference Code
For more information, consult the HB_VENC_SetRcParam reference code.
HB_VENC_GetRcParam
Function Declaration
int32_t HB_VENC_GetRcParam(VENC_CHN VeChn, VENC_RC_ATTR_S *pstRcParam);
Function Description
Retrieves the advanced parameters for the channel's rate control.
Parameter Descriptions
Parameter Name | Description | Input/Output |
---|---|---|
VeChn | Encoding channel number. Range: [0, VENC_MAX_CHN_NUM) | Input |
pstRcParam | Pointer to the advanced rate control parameters for the encoder channel | Input |
Return Values
Return Value | Description |
---|---|
0 | Success |
Non-zero | Failure; refer to error codes. |
Note
None
Reference Code
HB_VENC_SetRefParam
Function Declaration
int32_t HB_VENC_SetRefParam(VENC_CHN VeChn, const VENC_REF_PARAM_S *pstRefParam);
Function Description
Sets the advanced frame skipping reference parameters for H.264/H.265 encoding channels.
Parameter Descriptions
Parameter Name | Description | Input/Output |
---|---|---|
VeChn | Encoding channel number. Range: [0, VENC_MAX_CHN_NUM) | Input |
pstRefParam | Pointer to the H.264/H.265 advanced frame skipping reference parameters | Input |
Return Values
Return Value | Description |
---|---|
0 | Success |
Non-zero | Failure; refer to error codes. |
Note
None
Example Code
int32_t s32Ret = 0;
VENC_CHN VeChn = 0;
int32_t Width = 1920;
int32_t Height = 1080;
VENC_REF_PARAM_S pstRefParam_test1;
memset(&pstRefParam_test1, 0x00, sizeof(VENC_REF_PARAM_S));
VENC_CHN_ATTR_S m_VencChnAttr;
memset(&m_VencChnAttr, 0, sizeof(VENC_CHN_ATTR_S));
m_VencChnAttr.stVencAttr.enType = PT_H264;
m_VencChnAttr.stVencAttr.u32PicWidth = Width;
m_VencChnAttr.stVencAttr.u32PicHeight = Height;
m_VencChnAttr.stVencAttr.enMirrorFlip = DIRECTION_NONE;
m_VencChnAttr.stVencAttr.enRotation = CODEC_ROTATION_0;
m_VencChnAttr.stVencAttr.stCropCfg.bEnable = HB_FALSE;
m_VencChnAttr.stVencAttr.stAttrH264.h264_profile = 0;
m_VencChnAttr.stVencAttr.stAttrH264.h264_level = 0;
m_VencChnAttr.stGopAttr.u32GopPresetIdx = 2;
m_VencChnAttr.stGopAttr.s32DecodingRefreshType = 2;
m_VencChnAttr.stRcAttr.enRcMode = VENC_RC_MODE_H264CBR;
VENC_RC_ATTR_S *pstRcParam = &(m_VencChnAttr.stRcAttr);
s32Ret = HB_VENC_GetRcParam(VeChn, pstRcParam);
pstRcParam->stH264Cbr.u32BitRate = 3000;
pstRcParam->stH264Cbr.u32FrameRate = 30;
pstRcParam->stH264Cbr.u32IntraPeriod = 30;
pstRcParam->stH264Cbr.u32VbvBufferSize = 3000;
s32Ret = HB_VENC_CreateChn(VeChn, &m_VencChnAttr);
pstRefParam_test1.use_longterm = HB_TRUE;
pstRefParam_test1.longterm_pic_period = 30;
pstRefParam_test1.longterm_pic_using_period = 20;
s32Ret = HB_VENC_SetRefParam(VeChn, &pstRefParam_test1);
VENC_REF_PARAM_S pstRefParam_test2;
memset(&pstRefParam_test2, 0x00, sizeof(VENC_REF_PARAM_S));
s32Ret = HB_VENC_GetRefParam(VeChn, &pstRefParam_test2);
HB_VENC_SetChnAttr(VeChn, &m_VencChnAttr);
s32Ret = HB_VENC_DestroyChn(VeChn);
HB_VENC_GetRefParam
Function Declaration
int32_t HB_VENC_GetRefParam(VENC_CHN VeChn, VENC_REF_PARAM_S *pstRefParam);
Function Description
Retrieves the advanced frame skipping reference parameters for H.264/H.265 encoding channels.
Parameter Descriptions
Parameter Name | Description | Input/Output |
---|---|---|
VeChn | Encoding channel number. Range: [0, VENC_MAX_CHN_NUM) | Input |
pstRefParam | Advanced H.264/H.265 frame skipping reference parameters | Output |
Return Values
Return Value | Description |
---|---|
0 | Success |
Non-zero | Failure; refer to error codes. |
Note
None
Reference Code
Reference code for HB_VENC_SetRefParam
HB_VENC_EnableIDR
Function Declaration
int32_t HB_VENC_EnableIDR(VENC_CHN VeChn, HB_BOOL bEnableIDR);
Function Description
Enables IDR frames.
Parameter Descriptions
Return Values
Return Value | Description |
---|---|
0 | Success |
Non-zero | Failure; refer to error codes. |
Note
None
Reference Code
None (No available example)
HB_VENC_SetH265SliceSplit
Function Declaration
int32_t HB_VENC_SetH265SliceSplit(VENC_CHN VeChn, const VENC_H265_SLICE_SPLIT_S *pstSliceSplit);
Function Description
Sets H.265 slice splitting configurations.
Parameter Descriptions
Parameter Name | Description | Input/Output |
---|---|---|
VeChn | Encoding channel number. Range: [0, VENC_MAX_CHN_NUM) | Input |
pstSliceSplit | H.265 stream slice splitting parameters | Input |
Return Values
Return Value | Description |
---|---|
0 | Success |
Non-zero | Failure; refer to error codes. |
Note
None
Reference Code
int32_t s32Ret = 0;
VENC_CHN VeChn = 0;
int32_t Width = 1920;
int32_t Height = 1080;
VENC_H265_SLICE_SPLIT_S pstSliceSplit1;
memset(&pstSliceSplit1, 0, sizeof(VENC_H265_SLICE_SPLIT_S));
VENC_CHN_ATTR_S m_VencChnAttr;
memset(&m_VencChnAttr, 0, sizeof(VENC_CHN_ATTR_S));
m_VencChnAttr.stVencAttr.enType = PT_H265;
m_VencChnAttr.stVencAttr.u32PicWidth = Width;
m_VencChnAttr.stVencAttr.u32PicHeight = Height;
m_VencChnAttr.stVencAttr.enMirrorFlip = DIRECTION_NONE;
m_VencChnAttr.stVencAttr.enRotation = CODEC_ROTATION_0;
m_VencChnAttr.stVencAttr.stCropCfg.bEnable = HB_FALSE;
m_VencChnAttr.stGopAttr.u32GopPresetIdx = 2;
m_VencChnAttr.stGopAttr.s32DecodingRefreshType = 2;
m_VencChnAttr.stRcAttr.enRcMode = VENC_RC_MODE_H265CBR;
VENC_RC_ATTR_S *pstRcParam = &(m_VencChnAttr.stRcAttr);
s32Ret = HB_VENC_GetRcParam(VeChn, pstRcParam);
pstRcParam->stH265Cbr.u32BitRate = 3000;
pstRcParam->stH265Cbr.u32FrameRate = 30;
pstRcParam->stH265Cbr.u32IntraPeriod = 30;
pstRcParam->stH265Cbr.u32VbvBufferSize = 3000;
s32Ret = HB_VENC_CreateChn(VeChn, &m_VencChnAttr);
HB_VENC_SetChnAttr(VeChn, &m_VencChnAttr);
pstSliceSplit1.h265_dependent_slice_arg = 1;
pstSliceSplit1.h265_dependent_slice_mode = 1;
pstSliceSplit1.h265_independent_slice_arg = 1;
pstSliceSplit1.h265_independent_slice_mode = 1;
s32Ret = HB_VENC_SetH265SliceSplit(VeChn, &pstSliceSplit1);
VENC_H265_SLICE_SPLIT_S pstSliceSplit2;
memset(&pstSliceSplit2, 0, sizeof(VENC_H265_SLICE_SPLIT_S));
s32Ret = HB_VENC_GetH265SliceSplit(VeChn, &pstSliceSplit2);
s32Ret = HB_VENC_DestroyChn(VeChn);
HB_VENC_GetH265SliceSplit
Function Declaration
int32_t HB_VENC_GetH265SliceSplit(VENC_CHN VeChn, VENC_H265_SLICE_SPLIT_S *pstSliceSplit);
Function Description
Retrieves the configuration for H.265 slice splitting.
Parameter Descriptions
Parameter Name | Description | Input/Output |
---|---|---|
VeChn | Encoding channel number. Range: [0, VENC_MAX_CHN_NUM) | Input |
pstSliceSplit | H.265 stream's slice splitting parameters | Output |
Return Values
Return Value | Description |
---|---|
0 | Success |
Non-zero | Failure; see error codes for details. |
Note
None
Reference Code HB_VENC_SetH265SliceSplit reference code
HB_VENC_SetH265PredUnit
Function Declaration
int32_t HB_VENC_SetH265PredUnit(VENC_CHN VeChn, const VENC_H265_PU_S *pstPredUnit);
Function Description
Sets the configuration for H.265 prediction unit (PU).
Parameter Descriptions
Parameter Name | Description | Input/Output |
---|---|---|
VeChn | Encoding channel number. Range: [0, VENC_MAX_CHN_NUM) | Input |
pstPredUnit | H.265 protocol's PU configuration for the encoding channel | Input |
Return Values
Return Value | Description |
---|---|
0 | Success |
Non-zero | Failure; see error codes for details. |
Note
None
Reference Code
int32_t s32Ret = 0;
VENC_CHN VeChn = 0;
int32_t Width = 1920;
int32_t Height = 1080;
VENC_H265_PU_S pstPredUnit1;
memset(&pstPredUnit1, 0, sizeof(VENC_H265_PU_S));
VENC_CHN_ATTR_S m_VencChnAttr;
memset(&m_VencChnAttr, 0, sizeof(VENC_CHN_ATTR_S));
m_VencChnAttr.stVencAttr.enType = PT_H265;
m_VencChnAttr.stVencAttr.u32PicWidth = Width;
m_VencChnAttr.stVencAttr.u32PicHeight = Height;
m_VencChnAttr.stVencAttr.enMirrorFlip = DIRECTION_NONE;
m_VencChnAttr.stVencAttr.enRotation = CODEC_ROTATION_0;
m_VencChnAttr.stVencAttr.stCropCfg.bEnable = HB_FALSE;
m_VencChnAttr.stGopAttr.u32GopPresetIdx = 2;
m_VencChnAttr.stGopAttr.s32DecodingRefreshType = 2;
m_VencChnAttr.stRcAttr.enRcMode = VENC_RC_MODE_H265CBR;
VENC_RC_ATTR_S *pstRcParam = &(m_VencChnAttr.stRcAttr);
s32Ret = HB_VENC_GetRcParam(VeChn, pstRcParam);
pstRcParam->stH265Cbr.u32BitRate = 3000;
pstRcParam->stH265Cbr.u32FrameRate = 30;
pstRcParam->stH265Cbr.u32IntraPeriod = 30;
pstRcParam->stH265Cbr.u32VbvBufferSize = 3000;
s32Ret = HB_VENC_CreateChn(VeChn, &m_VencChnAttr);
pstPredUnit1.constrained_intra_pred_flag = 1;
pstPredUnit1.intra_nxn_enable = 0;
pstPredUnit1.max_num_merge = 1;
pstPredUnit1.strong_intra_smoothing_enabled_flag = 1;
s32Ret = HB_VENC_SetH265PredUnit(VeChn, &pstPredUnit1);
VENC_H265_PU_S pstPredUnit2;
memset(&pstPredUnit2, 0, sizeof(VENC_H265_PU_S));
s32Ret = HB_VENC_GetH265PredUnit(VeChn, &pstPredUnit2);
HB_VENC_SetChnAttr(VeChn, &m_VencChnAttr);
s32Ret = HB_VENC_DestroyChn(VeChn);
HB_VENC_GetH265PredUnit
Function Declaration
int32_t HB_VENC_GetH265PredUnit(VENC_CHN VeChn, VENC_H265_PU_S *pstPredUnit);
Function Description
Retrieves the configuration for prediction units in H.265 encoding.
Parameter Descriptions
Parameter Name | Description | Input/Output |
---|---|---|
VeChn | Encoding channel number. Range: [0, VENC_MAX_CHN_NUM) | Input |
pstPredUnit | H.265 protocol's PU configuration | Output |
Return Values
Return Value | Description |
---|---|
0 | Successful |
Non-zero | Failure; refer to error codes. |
Notes
None
Reference Code
See HB_VENC_SetH265PredUnit reference code
HB_VENC_SetH265Trans
Function Declaration
int32_t HB_VENC_SetH265Trans(VENC_CHN VeChn, const VENC_H265_TRANS_S *pstH265Trans);
Function Description
Sets the transformation and quantization configurations for H.265 encoding.
Parameter Descriptions
Parameter Name | Description | Input/Output |
---|---|---|
VeChn | Encoding channel number. Range: [0, VENC_MAX_CHN_NUM) | Input |
pstH265Trans | H.265 protocol's transformation and quantization settings | Input |
Return Values
Return Value | Description |
---|---|
0 | Successful |
Non-zero | Failure; refer to error codes. |
Notes
None
Example Reference Code
int32_t s32Ret = 0;
VENC_CHN VeChn = 0;
int32_t Width = 1920;
int32_t Height = 1080;
VENC_H265_TRANS_S pstH265Trans1;
memset(&pstH265Trans1, 0, sizeof(VENC_H265_TRANS_S));
VENC_CHN_ATTR_S m_VencChnAttr;
memset(&m_VencChnAttr, 0, sizeof(VENC_CHN_ATTR_S));
m_VencChnAttr.stVencAttr.enType = PT_H265;
m_VencChnAttr.stVencAttr.u32PicWidth = Width;
m_VencChnAttr.stVencAttr.u32PicHeight = Height;
m_VencChnAttr.stVencAttr.enMirrorFlip = DIRECTION_NONE;
m_VencChnAttr.stVencAttr.enRotation = CODEC_ROTATION_0;
m_VencChnAttr.stVencAttr.stCropCfg.bEnable = HB_FALSE;
m_VencChnAttr.stGopAttr.u32GopPresetIdx = 2;
m_VencChnAttr.stGopAttr.s32DecodingRefreshType = 2;
m_VencChnAttr.stRcAttr.enRcMode = VENC_RC_MODE_H265CBR;
VENC_RC_ATTR_S *pstRcParam = &(m_VencChnAttr.stRcAttr);
s32Ret = HB_VENC_GetRcParam(VeChn, pstRcParam);
pstRcParam->stH265Cbr.u32BitRate = 3000;
pstRcParam->stH265Cbr.u32FrameRate = 30;
pstRcParam->stH265Cbr.u32IntraPeriod = 30;
pstRcParam->stH265Cbr.u32VbvBufferSize = 3000;
s32Ret = HB_VENC_CreateChn(VeChn, &m_VencChnAttr);
pstH265Trans1.chroma_cb_qp_offset = 6;
pstH265Trans1.chroma_cr_qp_offset = 6;
pstH265Trans1.user_scaling_list_enable = HB_TRUE;
s32Ret = HB_VENC_SetH265Trans(VeChn, &pstH265Trans1);
VENC_H265_TRANS_S pstH265Trans2;
memset(&pstH265Trans2, 0, sizeof(VENC_H265_TRANS_S));
s32Ret = HB_VENC_GetH265Trans(VeChn, &pstH265Trans2);
s32Ret = HB_VENC_DestroyChn(VeChn);
HB_VENC_GetH265Trans
Function Declaration
int32_t HB_VENC_GetH265Trans(VENC_CHN VeChn, VENC_H265_TRANS_S *pstH265Trans);
Function Description
Retrieves the H.265 encoding transformation and quantization configurations.
Parameter Descriptions
Parameter Name | Description | Input/Output |
---|---|---|
VeChn | Encoding channel number. Range: [0, VENC_MAX_CHN_NUM) | Input |
pstH265Trans | H.265 protocol's encoding channel transformation/quantization settings | Output |
Return Values
Return Value | Description |
---|---|
0 | Success |
Non-zero | Failure; refer to error codes. |
Note
None
Reference Code HB_VENC_SetH265Trans reference code
HB_VENC_SetH265Dblk
Function Declaration
int32_t HB_VENC_SetH265Dblk(VENC_CHN VeChn, const VENC_H265_DBLK_S *pstH265Dblk);
Function Description
Sets the H.265 encoding deblocking configuration.
Parameter Descriptions
Parameter Name | Description | Input/Output |
---|---|---|
VeChn | Encoding channel number. Range: [0, VENC_MAX_CHN_NUM) | Input |
pstH265Dblk | H.265 protocol's encoding channel deblocking configuration | Input |
Return Values
Return Value | Description |
---|---|
0 | Success |
Non-zero | Failure; refer to error codes. |
Note
None
Example Reference Code
int32_t s32Ret = 0;
VENC_CHN VeChn = 0;
int32_t Width = 1920;
int32_t Height = 1080;
VENC_H265_DBLK_S pstH265Dblk1;
memset(&pstH265Dblk1, 0, sizeof(VENC_H265_DBLK_S));
VENC_CHN_ATTR_S m_VencChnAttr;
memset(&m_VencChnAttr, 0, sizeof(VENC_CHN_ATTR_S));
m_VencChnAttr.stVencAttr.enType = PT_H265;
m_VencChnAttr.stVencAttr.u32PicWidth = Width;
m_VencChnAttr.stVencAttr.u32PicHeight = Height;
m_VencChnAttr.stVencAttr.enMirrorFlip = DIRECTION_NONE;
m_VencChnAttr.stVencAttr.enRotation = CODEC_ROTATION_0;
m_VencChnAttr.stVencAttr.stCropCfg.bEnable = HB_FALSE;
m_VencChnAttr.stGopAttr.u32GopPresetIdx = 2;
m_VencChnAttr.stGopAttr.s32DecodingRefreshType = 2;
m_VencChnAttr.stRcAttr.enRcMode = VENC_RC_MODE_H265CBR;
VENC_RC_ATTR_S *pstRcParam = &(m_VencChnAttr.stRcAttr);
s32Ret = HB_VENC_GetRcParam(VeChn, pstRcParam);
pstRcParam->stH265Cbr.u32BitRate = 3000;
pstRcParam->stH265Cbr.u32FrameRate = 30;
pstRcParam->stH265Cbr.u32IntraPeriod = 30;
pstRcParam->stH265Cbr.u32VbvBufferSize = 3000;
s32Ret = HB_VENC_CreateChn(VeChn, &m_VencChnAttr);
HB_VENC_SetChnAttr(VeChn, &m_VencChnAttr);
pstH265Dblk1.slice_beta_offset_div2 = 3;
pstH265Dblk1.slice_tc_offset_div2 = 3;
pstH265Dblk1.slice_deblocking_filter_disabled_flag = 1;
s32Ret = HB_VENC_SetH265Dblk(VeChn, &pstH265Dblk1);
VENC_H265_DBLK_S pstH265Dblk2;
memset(&pstH265Dblk2, 0, sizeof(VENC_H265_DBLK_S));
s32Ret = HB_VENC_GetH265Dblk(VeChn, &pstH265Dblk2);
s32Ret = HB_VENC_DestroyChn(VeChn);
HB_VENC_GetH265Dblk
Function Declaration
int32_t HB_VENC_GetH265Dblk(VENC_CHN VeChn, VENC_H265_DBLK_S *pstH265Dblk);
Function Description
Retrieves the deblocking configuration for H.265 encoding.
Parameter Descriptions
Parameter Name | Description | Input/Output |
---|---|---|
VeChn | Encoding channel number. Range: [0, VENC_MAX_CHN_NUM) | Input |
pstH265Dblk | H.265 protocol's deblocking configuration pointer | Output |
Return Values
Return Value | Description |
---|---|
0 | Successful |
Non-zero | Failure, refer to error codes |
Notes
None
Reference Code
See reference code for HB_VENC_SetH265Dblk