VideoEncodeConfig

Description

Stores video encoding parameters.

Structure Definition

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
struct VideoEncodeConfig {
    uint32_t maxPicWidth = 4096;
    uint32_t maxPicHeight = 4096;
    uint32_t width = 1920;
    uint32_t height = 1080;
    StreamFormat outputVideoFormat = StreamFormat::H264_MAIN_LEVEL;
    ImageFormat inputImageFormat = ImageFormat::YUV_SP_420;
    VideoEncodeCallBack callbackFunc = nullptr;
    uint32_t keyFrameInterval = 30;
    uint32_t srcRate = 30;
    uint32_t rcMode = 0;
    uint32_t shortTermStatsTime = 60;
    uint32_t longTermStatsTime = 120;
    uint32_t longTermMaxBitRate = 300;
    uint32_t longTermMinBitRate = 0;
    uint32_t maxBitRate = 300;
    uint32_t ipProp = 70;
    uint32_t sceneMode = 0;
    uint32_t displayRate = 30;
    uint32_t statsTime = 1;
    uint32_t firstFrameStartQp = 32;
    std::vector<uint32_t> thresholdI = {0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255};
    std::vector<uint32_t> thresholdP = {0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255};
    std::vector<uint32_t> thresholdB  = {0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255};
    uint32_t direction = 8;
    uint32_t rowQpDelta = 1;
};

Parameters

Parameter

Description

maxPicWidth

Maximum reserved width of an encoding channel, in pixels. The value range is [128, 4096]. The default value is 4096. It must be greater than width. Currently, only Atlas inference product support this parameter.

maxPicHeight

Maximum reserved height of an encoding channel, in pixels. The value range is [128, 4096]. The default value is 4096. It must be greater than height. Currently, only Atlas inference product support this parameter.

width

Width of the encoded video frame data. The value must be the same as the width (originalSize) of the image to be encoded. The default value is 1920.

  • For the Atlas 200/300/500 inference product, the value range is [128, 1920]. The input video width must be a multiple of 16.
  • Atlas 200I/500 A2 inference product: The value range is [114, 8192]. The input video width must be a multiple of 2.
  • Atlas inference product: The value range is [128, 4096]. The input video width must be a multiple of 2. The maximum resolution (width × height) for video encoding cannot exceed 4096 × 2304.

height

Height of the encoded video frame data. The value must be the same as the height (originalSize) of the image to be encoded. The default value is 1080.

  • Atlas 200/300/500 inference product: The value range is [128, 1920]. The input video height must be a multiple of 2.
  • Atlas 200I/500 A2 inference product: The value range is [114, 8192]. The input video height must be a multiple of 2.
  • Atlas inference product: The value range is [128, 4096]. The input video height must be a multiple of 2. The maximum resolution (width × height) for video encoding cannot exceed 4096 × 2304.

outputVideoFormat

Output video format after encoding. The default value is StreamFormat::H264_MAIN_LEVEL.

inputImageFormat

Input image format. The default value is ImageFormat::YUV_SP_420.

  • For the Atlas 200/300/500 inference product, YUV_SP_420 and YVU_SP_420 are supported.
  • For the Atlas 200I/500 A2 inference product, YUV_SP_420 and YVU_SP_420 are supported.
  • For the Atlas inference product, YUV_SP_420, YVU_SP_420, RGB_888, and BGR_888 are supported.

callbackFunc

Callback function after encoding. It cannot be a null pointer.

keyFrameInterval

I-frame interval. The default value is 30.

  • Atlas 200/300/500 inference product: The value range is [1, 2000].
  • Atlas 200I/500 A2 inference product: The value range is [1, 65536].
  • Atlas inference product: The value range is [1, 65536].

srcRate

Frame rate of input streams, in fps. The default value is 30.

  • Atlas 200/300/500 inference product: The value range is [1, 120].
  • Atlas 200I/500 A2 inference product: The value range is [1, 240].
  • Atlas inference product: The value range is [1, 240].

rcMode

Bit rate control mode.

  • Atlas 200/300/500 inference products
    • 0: CBR mode (default)
    • 1: VBR mode
    • 2: CBR mode
  • Atlas 200I/500 A2 inference products
    • 0: VBR mode (default)
    • 1: VBR mode
    • 2: CBR mode
  • Atlas inference product
    • 0 or 1: CBR mode
    • 2: VBR mode
    • 3: AVBR mode
    • 4: QVBR mode
    • 5: CVBR mode

shortTermStatsTime

Short-term statistical time of the bit rate, in seconds. The value range is [1, 120]. The default value is 60.

This parameter takes effect only when rcMode is set to 5 on Atlas inference product.

longTermStatsTime

Long-term statistical time of the bit rate, in minutes. The value range is [1, 1440]. The default value is 120.

This parameter takes effect only when rcMode is set to 5 on Atlas inference product.

longTermMaxBitRate

Maximum long-term output bit rate of the encoder, in kbps. The default value is 300. Value range: [2, maxBitRate].

This parameter takes effect only when rcMode is set to 5 on Atlas inference product.

longTermMinBitRate

Minimum long-term output bit rate of the encoder, in kbps. The default value is 0. Value range: [0, longTermMaxBitRate].

This parameter takes effect only when rcMode is set to 5 on Atlas inference product.

maxBitRate

Output bit rate, in kbps. The default value is 300.

  • Atlas 200/300/500 inference product: The value range is [10, 30000].
  • Atlas 200I/500 A2 inference product: The value range is [2, 614400].
  • Atlas inference product: The value range is [2, 614400].

ipProp

I-frame to P-frame bit allocation ratio within a GOP. The value range is [1, 100]. The default value is 70.

sceneMode

Scene mode.

  • 0 (default): scene where the camera does not move or moves periodically and continuously. H.264 and H.265 are supported.
  • 1: motion scene where the bit rate is high. H.265 is supported.

This parameter takes effect only on Atlas inference product.

NOTE:

When the output video format is set to H.264 and sceneMode is set to 1, the value of sceneMode is automatically switched to 0 because H.264 does not support motion scenes where the bit rate is high.

displayRate

Frame rate for playing the output video. The value range is [1, 120]. The default value is 30.

This parameter takes effect only on Atlas inference product.

statsTime

Bit rate statistical time, in seconds. The value range is [1, 60]. The default value is 1.

This parameter takes effect only on Atlas inference product.

firstFrameStartQp

Start QP value of the first frame. The default value is 32. Different modes have different value ranges:

  • CBR: [10, 51]
  • VBR: [24, 51]
  • AVBR: [24, 51]
  • QVBR: [16, 51]
  • CVBR: [20, 47]

This parameter takes effect only on Atlas inference product.

thresholdI

MADi threshold for the macroblock-level bit rate of I-frames, used to measure the spatial texture complexity of the current frame. The value range is [0, 255]. The default value is [0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255].

If the value of the subtraction direction is set to 0 or the value of the addition direction is set to 255, the current profile is disabled.

This parameter takes effect only on Atlas inference product.

thresholdP

MADi threshold for the macroblock-level bit rate of P-frames, used to measure the spatial texture complexity of the current frame. The value range is [0, 255]. The default value is [0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255].

If the value of the subtraction direction is set to 0 or the value of the addition direction is set to 255, the current profile is disabled.

This parameter takes effect only on Atlas inference product.

thresholdB

MADi threshold for the macroblock-level bit rate of B-frames, used to measure the spatial texture complexity of the current frame. The value range is [0, 255]. The default value is [0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255].

If the value of the subtraction direction is set to 0 or the value of the addition direction is set to 255, the current profile is disabled.

This parameter takes effect only on Atlas inference product.

direction

Addition or subtraction direction control during texture-based macroblock-level bit rate control The value range is [0, 16]. The default value is 8.

This parameter takes effect only on Atlas inference product.

rowQpDelta

Maximum row-level adjustment range within one frame. The unit is the macroblock row. A larger adjustment amplitude indicates that the allowed QP row-level adjustment range is larger and the bit rate is more stable.

In the scenarios where the image complexity is unevenly distributed, the image quality may be uneven if the value of this parameter is too large.

The value range is [0, 10]. The default value is 1. If the value is set to 0, row-based macroblock-level bit rate control is disabled.

This parameter takes effect only on Atlas inference product.

Recommended Configuration

The following table lists the recommended parameter settings that ensure good video encoding quality during video capture. In other scenarios, adjust the parameter settings as required.

Image Quality/Resolution

srcRate

keyFrameInterval

maxBitRate

4K

3840 x 2160/4096 x 2160

25 or 30

50 or 60

  • H.264: 8000 to 12000
  • H.265: 8000 to 12000

2K

2560 x 1440

25 or 30

50 or 60

  • H.264: 6000 to 10000
  • H.265: 6000 to 10000

1080p (Blu-ray)

1920 x 1080

25 or 30

50 or 60

  • H.264: 2000 to 6000
  • H.265: 1000 to 4000

720p (HD)

1280 x 720

25 or 30

50 or 60

  • H.264: 1000 to 3000
  • H.265: 800 to 2000

480p/D1_N (SD)

854 x 480/720 x 480

25 or 30

50 or 60

  • H.264: 600 to 1400
  • H.265: 300 to 700

576P/D1 (SD)

720 x 576

25 or 30

50 or 60

  • H.264: 600 to 1400
  • H.265: 300 to 700

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

  • H.264: 250
  • H.265: 250