Sample Overview

Sample Obtaining

Go to the Ascend samples repository on Gitee or GitHub and download the sample package that matches the required version. For the version mapping, see "Release Notes" in the README file. Find the "venc_image" sample in the cplusplus/level2_simple_inference/0_data_process/venc_image directory.

Description

In this sample, a YUV420SP (NV12) image is encoded for n consecutive times to generate a video stream in H.265 format. (n is defaulted to 16 and is configurable before running the app.)

Principles

The following table lists the key functions involved in this sample. For details about the APIs, see AscendCL API Reference.

Initialization

  • aclInit: initializes AscendCL.
  • aclFinalize: deinitializes AscendCL.

Device Management

  • aclrtSetDevice: sets the compute device.
  • aclrtGetRunMode: obtains the run mode of the software stack. The internal processing varies depending on the run mode.
  • aclrtResetDevice: resets the compute device and cleans up all resources associated with the device.

Context Management

  • aclrtCreateContext: creates a context.
  • aclrtDestroyContext: destroys a context.

Memory Management

  • acldvppMalloc: allocates device memory.
  • acldvppFree: frees device memory.

Data Transfer

aclrtMemcpy:

  • Transfers data from the host to the device for encoding.
  • Transfers the encoding result from the device to the host.

Data transfer is not required if your app runs in the board environment.

Media Data Processing

aclvencSendFrame: sends the images to be encoded to the encoder.

Directory Structure

The sample directory is organized as follows:

├── data
│   ├── dvpp_venc_128x128_nv12.yuv            //Test image. Obtain the test image according to the guide and save it to the data directory.

├── inc
│   ├── venc_process.h               //Header file that declares functions related to media data processing
│   ├── sample_process.h               //Header file that declares functions related to model processing
│   ├── utils.h                       //Header file that declares common functions (such as the file reading function)

├── src
│   ├── acl.json              //Configuration file for system initialization
│   ├── CMakeLists.txt         //Build script
│   ├── main.cpp               //Implementation file of the main function, for multi-image, multi-ROI cropping
│   ├── sample_process.cpp     //Implementation file of functions related to resource initialization and destruction
│   ├── utils.cpp              //Implementation file of common functions (such as the file reading function)
│   ├── venc_process.cpp       //Implementation file of functions related to media data processing

├── CMakeLists.txt    //Build script that calls the CMakeLists file in the src directory