Optimization of Video Encoding Quality

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:

Setting Basic Parameters for Overall Quality Optimization

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.

Table 1 Values of the frame rate, GOP, and bit rate in typical scenarios

Picture Quality/Resolution

Frame Rate (FPS)

GOP

Bit Rate (Mbit/s)

4K

3840 x 2160/4096 x 2160

25 or 30

50 or 60

  • Video capture

    8 to 12 for H.264/H.265 streams

  • Show/Livestreaming/Short video

    6 to 12 for H.265 streams

    N/A for H.264 streams

  • Game video

    10 to 16 for H.264/H.265 streams

2K

2560 x 1440

25 or 30

50 or 60

  • Video capture

    6 to 10 for H.264/H.265 streams

  • Show/Livestreaming/Short video

    4.8 to 8 for H.265 streams

    N/A for H.264 streams

  • Game video

    6 to 10 for H.264/H.265 streams

1080p (Blu-ray)

1920 x 1080

25 or 30

50 or 60

  • Video capture

    1 to 4 for H.265 streams

    2 to 6 for H.264 streams

  • Show/Livestreaming/Short video

    1.4 to 3.6 for H.265 streams

    2 to 4.8 for H.264 streams

  • Game video

    3 to 6 for H.264/H.265 streams

720p (HD)

1280 x 720

25 or 30

50 or 60

  • Video capture

    0.8 to 2 for H.265 streams

    1 to 3 for H.264 streams

  • Show/Livestreaming/Short video

    1 to 2 for H.265 streams

    1 to 3 for H.264 streams

  • Game video

    2 to 4 for H.264/H.265 streams

480p/D1_N (SD)

854 x 480/720 x 480

25 or 30

50 or 60

  • Video capture

    0.3 to 0.7 for H.265 streams

    0.6 to 1.4 for H.264 streams

  • Show/Livestreaming/Short video

    0.25 to 0.6 for H.265 streams

    0.3 to 0.7 for H.264 streams

  • Game video

    N/A

576p/D1 (SD)

720 x 576

25 or 30

50 or 60

  • Video capture

    0.3 to 0.7 for H.265 streams

    0.6 to 1.4 for H.264 streams

  • Show/Livestreaming/Short video

    0.25 to 0.6 for H.265 streams

    0.3 to 0.7 for H.264 streams

  • Game video

    N/A

270p (smooth)

480 x 270

25 or 30

50 or 60

  • Video capture

    N/A

  • Show/Livestreaming/Short video

    0.2 for H.265 streams

    0.3 for H.264 streams

  • Game video

    N/A

CIF P/N

352 x 288/320 x 240

25 or 30

50 or 60

  • Video capture

    0.25 for H.264/H.265 streams

  • Show/Livestreaming/Short video

    N/A

  • Game video

    N/A

Setting Advanced Parameters for Quality Tuning

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.

Table 2 Advanced settings

Item

API

Parameter

Description

Bit rate control mode

hi_mpi_venc_create_chn

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

hi_mpi_venc_create_chn

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

hi_mpi_venc_set_rc_param

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

hi_mpi_venc_create_chn

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_mpi_venc_set_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.