When implementing the VENC function, you can set basic parameters during channel creation or set advanced parameters by calling the corresponding set API to optimize the video encoding quality. The following optimization settings are available and can be used jointly:
The encoding quality of videos with different resolutions is related to the video frame rate, GOP, and bit rate. When a channel is created by calling hi_mpi_venc_create_chn, you can set the encoding profile and parameters such as the frame rate, GOP, and bit rate in CBR/VBR/AVBR/CVBR/QVBR mode for H.264/H.265 encoding to optimize the video encoding quality.
Picture Quality/Resolution |
Frame Rate (FPS) |
GOP |
Bit Rate (Mbit/s) |
|---|---|---|---|
4K 3840 x 2160/4096 x 2160 |
25 or 30 |
50 or 60 |
|
2K 2560 x 1440 |
25 or 30 |
50 or 60 |
|
1080p (Blu-ray) 1920 x 1080 |
25 or 30 |
50 or 60 |
|
720p (HD) 1280 x 720 |
25 or 30 |
50 or 60 |
|
480p/D1_N (SD) 854 x 480/720 x 480 |
25 or 30 |
50 or 60 |
|
576p/D1 (SD) 720 x 576 |
25 or 30 |
50 or 60 |
|
270p (smooth) 480 x 270 |
25 or 30 |
50 or 60 |
|
CIF P/N 352 x 288/320 x 240 |
25 or 30 |
50 or 60 |
You can call the APIs listed in the following table to set the bit rate control mode, macroblock-level bit rate control parameters, and encoding scene mode to tune video encoding quality.
Item |
API |
Parameter |
Description |
|---|---|---|---|
Bit rate control mode |
rc_mode in the hi_venc_chn_attr.rc_attr struct |
Set this parameter to CBR if a stable bit rate or a large peak signal to noise ratio (PSNR) and qualified bit rate is required. Set this parameter to VBR to save the bit rate and improve the subjective quality of encoding. Set this parameter to AVBR to save the bit rate and improve the subjective quality of encoding with lots of still images in the scene. Set this parameter to QVBR if a large PSNR is required and there is no strict requirement on the bit rate increase. Set this parameter to CVBR to save the bit rate and improve the subjective quality of encoding when the bandwidth and storage space can also be used for optimization. |
|
Statistical time of the bit rate control model |
stats_time in the hi_venc_chn_attr.rc_attr struct |
Set this parameter to a large value in the scenario where long-term bit rate stability is required without considering short-term fluctuations, for example, DVR storage. This setting increases the threshold for re-encoding to cut the number of re-encoding times, but also increases bit rate fluctuations at the same time. |
|
Macroblock-level bit rate control |
threshold_i, threshold_p, threshold_b, direction, and row_qp_delta in the hi_venc_rc_param struct |
Disable this function when encoding complex images with rich details, or when objective indicators such as the PSNR are concerned. |
|
Start QP value of the first frame |
first_frame_start_qp in the hi_venc_rc_param struct |
In typical scenarios, if the configured bit rate is less than the reference value provided in Table 1 and the first frame of the encoded video is blurry, you are advised to set first_frame_start_qp to the middle value of [min_i_qp, max_i_qp]. For example, if [min_i_qp, max_i_qp] is [30, 40], set first_frame_start_qp to 35. In addition, set max_reencode_times to 0. |
|
Encoding scene mode |
hi_venc_scene_mode |
Set this parameter to HI_VENC_SCENE_0 for security scenes. Set this parameter to HI_VENC_SCENE_1 for autonomous driving, livestreaming, gaming, animations, and movies. |