The VDEC video decoding output format and resolution are properly selected for better performance.

Background

If you want to use the DVPP to decode videos and obtain RGB images, the current video decoding API aclvdecSendFrame supports the YUV420SP or RGB888 output format and image resizing during decoding. Therefore, to improve the performance, the code logic can be optimized to directly call the video decoding API aclvdecSendFrame to output the RGB888 format.

Figure 1 VDEC output scenarios

Principles

The video decoding interface aclvdecSendFrame on some AI processor supports the YUV420SP or RGB888 format. You can set the interface parameters to output different formats. In this way, you do not need to call acldvppVpcConvertColorAsync to convert the format, reducing the number of interface calls.

If the resolution of the video stream is different from that of the input image, the decoded image needs to be resized. You can also set the resolution of the output image in the video decoding API aclvdecSendFrame so that the image can be resized during decoding. In this way, you do not need to call the resizing API separately, reducing the number of API calls.

To sum up, the decoding, scaling, and CSC functions can be implemented in the video decoding API aclvdecSendFrame to reduce the number of API calls and improve performance.

Example

You can click vdec_resnet50_classification to obtain the sample.

If the RGB888 format needs to be output for video decoding and resizing is required, you need to set the image format, width, height, width stride, and height stride in the output parameter (indicating the description of the output image) of the aclvdecSendFrame call. For example:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// Create output image description.
acldvppPicDesc picOutputDesc = acldvppCreatePicDesc();

// Define the output image format, width, height, width stride, height stride, and output buffer.
uint32_t width = 224;
uint32_t height = 224;
uint32_t widthStride = 224 * 3;
uint32_t heightStride = 224;
uint32_t size = widthStride * heightStride;
void *picOutBufferDev = nullptr;
acldvppMalloc(&picOutBufferDev, size);

//Set the output image format, width, height, width stride, height stride, and buffer for storing the output image data.
acldvppSetPicDescData(picOutputDesc, picOutBufferDev);
acldvppSetPicDescSize(picOutputDesc, size);
acldvppSetPicDescFormat(picOutputDesc, PIXEL_FORMAT_RGB_888);
acldvppSetPicDescWidth(picOutputDesc, width);
acldvppSetPicDescHeight(picOutputDesc, height);
acldvppSetPicDescWidthStride(picOutputDesc, widthStride);
acldvppSetPicDescHeightStride(picOutputDesc, heightStride);

// Call the decoding API.
aclvdecSendFrame(channelDesc, picInputDesc, picOutputDesc, nullptr, nullptr);