JPEGE Functions and Restrictions
Function
JPEG Encoder (JPEGE) encodes YUV images into JPEG images, for example, .jpg images.
Resolution Restrictions
|
Model |
Resolution Range |
|---|---|
|
|
32 × 32 to 8192 × 8192 |
|
|
32 × 32 to 16384 × 16384 |
|
|
32 × 32 to 32768 × 32768 |
Output resolution range
JPEGE encodes images without changing the image resolution. Therefore, the output image resolution is the same as the input image resolution.
APIs for Buffer Allocation and Freeing
The size of the input buffer refers to the actual size occupied by the input stream. For details about the size of the output buffer, see the formula in Restrictions on Image Formats, Width and Height Alignment, and Buffers.
- APIs for input buffer allocation and freeing
During JPEGE image encoding, call hi_mpi_dvpp_malloc to allocate the input buffer on the device, and hi_mpi_dvpp_free to free the buffer. The buffer lifetime is managed by the user.
- APIs for output buffer allocation and freeing
- Managed by DVPP: Call hi_mpi_venc_send_frame to send source images for encoding.
When creating a channel by calling hi_mpi_venc_create_chn, you must properly set hi_venc_chn_attr.venc_attr.buf_size. For details about the parameter description, see hi_venc_attr.
In this method, the JPEG header of the output data does not contain the COM comment field, and the data length is smaller. However, you need to copy the output data from the buffer returned by DVPP to the specified memory.
- Managed by users: Call hi_mpi_venc_send_jpege_frame to send source images for encoding.
When creating a channel by calling hi_mpi_venc_create_chn, set hi_venc_chn_attr.venc_attr.buf_size to 0 (see hi_venc_attr). Call hi_mpi_venc_get_jpege_predicted_size to predict the output buffer size, and call hi_mpi_dvpp_malloc or hi_mpi_dvpp_free to allocate or free the output buffer.
In this mode, the output buffer address is set when hi_mpi_venc_send_jpege_frame is called. The output data is directly stored in the buffer set by the user. Compared with the other mode, this mode does not require you to copy the output data from the buffer returned by DVPP to the specified memory. However, the JPEG header of the output data may contain the COM comment field (whose length ranges from 4 bytes to 19 bytes), and thus the data length is larger.
- Managed by DVPP: Call hi_mpi_venc_send_frame to send source images for encoding.
For the following product models, you can call the aclrtMalloc or aclrtFree API to allocate or free the input and output buffers on the device. The lifetime of the buffers is managed by users.
hi_mpi_dvpp_malloc allocates a dedicated buffer for processing media data. However, the address space of the dedicated buffer is limited. If buffer planning is considered or buffer resources are limited, you are advised to allocate a buffer by calling aclrtMalloc. When calling aclrtMalloc to allocate a buffer, you are advised to allocate the buffer of the ACL_MEM_MALLOC_HUGE_FIRST type. Huge page buffer has better performance and is preferred.
Restrictions on Image Formats, Width and Height Alignment, and Buffers
For details about the definition of the input image format, see hi_pixel_format. For details about the concepts such as width stride and height stride, see Basic Concepts.
|
Input Image Format |
Input Width and Height Alignment |
Input Width Stride, Height Stride, and Buffer Size |
Output Image Format |
|---|---|---|---|
|
YUV420SP NV12 8-bit |
Width: Must be a multiple of 2. Height: Must be a multiple of 2. |
Width stride: No alignment requirements. The value is the same as the width. The height stride does not need to be configured. Buffer size (in bytes) = Width stride × Height × 3/2 |
JPEG, for example, .jpg Only Huffman coding is supported. Arithmetic coding and progressive coding are not supported. |
|
YUV420SP NV21 8-bit |
|||
|
YUV422 Packed YUYV 8-bit |
Width: Must be a multiple of 2. Height: No alignment requirements. |
Width stride: No alignment requirements. The value is the same as the width. The height stride does not need to be configured. Buffer size (in bytes) = Width stride × Height |
|
|
YUV422 Packed UYVY 8-bit |
|||
|
YUV422 Packed YVYU 8-bit |
|||
|
YUV422 Packed VYUY 8-bit |
|
Input Image Format |
Input Width and Height Alignment |
Input Width Stride, Height Stride, and Buffer Size |
Output Image Format |
|---|---|---|---|
|
YUV420SP NV12 8-bit |
Width: Must be a multiple of 2. Height: Must be a multiple of 2. |
Width stride: Round up the width to the nearest multiple of 16 or any multiple of 16, for example, 128 (which offers better performance). The height stride does not need to be configured. Buffer size (in bytes) = Width stride × Height × 3/2 |
JPEG, for example, .jpg Only Huffman coding is supported. Arithmetic coding and progressive coding are not supported. |
|
YUV420SP NV21 8-bit |
|||
|
YUV422 Packed YUYV 8-bit |
Width: Must be a multiple of 2. Height: No alignment requirements. |
Width stride: Double the width and then round up the result to the nearest multiple of 16. The height stride does not need to be configured. Buffer size (in bytes) = Width stride × Height |
|
|
YUV422 Packed UYVY 8-bit |
|||
|
YUV422 Packed YVYU 8-bit |
|||
|
YUV422 Packed VYUY 8-bit |