Description
Creates an encoding channel.
The Ascend 310 AI Processor does not support this API in the current version.
The Ascend 910 AI Processor does not support this API in the current version.
Restrictions
- The channel ID of a single device must not be greater than the maximum channel ID.
- An encoding channel has the encoder attributes, RC attributes, and group of pictures (GOP) attributes.
- The maximum width and height configured in the encoder attributes must meet the following conditions:
max_pic_width∈[MIN_WIDTH, MAX_WIDTH]
max_pic_height∈[MIN_HEIGHT, MAX_HEIGHT]
pic_width∈[MIN_WIDTH, MAX_WIDTH]
pic_height∈[MIN_HEIGHT, MAX_HEIGHT]
The maximum width and height of the VENC channel are integral multiples of MIN_ALIGN. The maximum width of the JPEGE channel is an integral multiple of MIN_ALIGN.
MIN_WIDTH, MAX_WIDTH, MIN_HEIGHT, MAX_HEIGHT, and MIN_ALIGN indicate the minimum width, maximum width, minimum height, maximum height, and minimum alignment (in pixels) of an encoding channel, receptively.
Table 1 describes the channel width and height supported by the encoder.
- In the encoder attributes, the stream buffer depth, stream fetching mode, and encoding profile must be set according to Table 2.
- The recommended encoding sizes are 3840 x 2160 (4K), 1920 x 1080 (1080p), and 1280 x 720 (720p).
- The encoder attributes except the channel width (pic_width) and channel height (pic_height) are static attributes. Once an encoding channel is created successfully, the static attributes are unmodifiable unless the channel is destroyed and re-created.
- For H.264/H.265 encoding, a frame buffer consists of YHeaderSize, CHeaderSize, YSize, CSize, PmeSize, PmeInfoSize, and TmvSize. The encoder calculates the buffer allocation based on the maximum width and height by default. When configuring the channel width and height, ensure that each frame buffer calculated based on the channel width and height is within that calculated based on the maximum channel width and height.
- For JPEG encoding, the channel width and height must meet the following condition: pic_width * pic_height ≤ max_pic_width * max_pic_height.
- You need to set the RC mode before setting the RC attributes. The RC attributes are required for H.264/H.265 encoding but are not required for JPEG encoding. The selected RC mode must match the encode protocol in use.
- For the H.264 and H.265 coding protocols, the bit rate control modes are as follows: CBR (Constant Bit Rate), VBR (Variable Bit Rate), AVBR (Adaptive Variable Bit Rate), QVBR (Quality Variable Bit Rate), CVBR (Constrained Variable Bit Rate), QPMAP (Quantization Parameter Map), and FIXQP (Fix Quantization Parameter). Currently, the CBR, VBR, AVBR, QVBR, and CVBR modes are supported. The attribute variables of each RC mode are basically consistent across the protocols. Table 3 describes the common attributes of the RC modes.
- In addition to the preceding attributes, the average bit rate needs to be set for the CBR mode. The unit of the average bit rate is kbit/s. The average bit rate is related to the width and height of the encoding channel and the image frame rate. Table 4 lists the typical settings of the average bit rate, with the assumption that the full encoding frame rate (30 FPS) is reached. If the encoding output frame rate is not set to the full frame rate, you can calculate the actual bit rate by the proportion of the configured frame rate to the full frame rate (30 FPS).
- In addition to the preceding attributes, MaxBitRate needs to be set for the VBR mode, indicating the maximum bit rate allowed by the encoding channel in the bit rate statistical period.
- When the H.264E encoding channel profile is set to the baseline profile, B-frame encoding is not supported.
Parameters
Parameter |
Input/Output |
Description |
chn |
Input |
Encoding channel ID. The value range of the encoding channel ID is [0, 256). The maximum number of channels is 256. |
attr |
Input |
Pointer to the encoding channel attributes. |
See Also
For the API call sequence, see JPEGE and VENC.
References
Table 1 Encoding channel width and height
W/H (Pixel) |
H.264 |
H.265 |
JPEG |
MIN_WIDTH |
128 |
128 |
32 |
MAX_WIDTH |
4096 |
4096 |
8192 |
MIN_HEIGHT |
128 |
128 |
32 |
MAX_HEIGHT |
4096 |
4096 |
8192 |
MIN_ALIGN |
2 |
2 |
2 |
Table 2 Restrictions on encoder attributes
Encode Protocol |
Encode Mode |
Stream Buffer Allocation |
Stream Fetching Mode |
Encode Profile |
H.264 |
Frame |
|
Frame/Slice |
Baseline Main Profile High Profile |
JPEG |
Frame |
- When mini_buf_mode = 0: Minimum buffer allocation for the YUV420 format = Source image width 16-aligned x Source image height 16-aligned x 3/2. Minimum buffer allocation for the YUV422 Packed format = Source image width 16-aligned x Source image height 16-aligned x 2
- When mini_buf_mode = 1: Buffer allocation ≥ 32 x 1024 bytes
|
Frame/Ecs |
Baseline |
H.265 |
Frame |
- When mini_buf_mode = 0: Buffer allocation ≥ max_pic_width x max_pic_height x 3/4
- When mini_buf_mode = 1: Buffer allocation ≥ 32 x 1024 bytes
|
Frame/Slice |
Main profile Main 10 Profile (not supported currently) |
|
|
Frame/Slice |
Main 10 profile (not supported currently) |
Table 3 Restrictions on RC attributes
RC Mode |
GOP |
StatTime (s) |
FrmRate (src_frame_rate/dst_frame_rate) |
CBR |
≥ 1 |
≥ 1 |
src_frame_rate ≥ dst_frame_rate |
VBR |
≥ 1 |
≥ 1 |
src_frame_rate ≥ dst_frame_rate |
AVBR |
≥ 1 |
≥ 1 |
src_frame_rate ≥ dst_frame_rate |
FIXQP |
≥ 1 |
≥ 1 |
src_frame_rate ≥ dst_frame_rate |
QPMAP |
≥ 1 |
≥ 1 |
src_frame_rate ≥ dst_frame_rate |
Table 4 Typical average bit rate settings
Image Size/Bit Rate Level |
1080p (1920 x 1080) |
4K (3840 x 2160) |
Low bit rate |
2 Mbit/s |
8 Mbit/s |
Mid bit rate |
2–8 Mbit/s |
8–30 Mbit/s |
High bit rate |
> 8 Mbit/s |
> 30 Mbit/s |