Updated on 2022-03-13 GMT+08:00

VENC Functions and Parameters

You are not advised to use the VENC function of the earlier version, which will be removed in later versions. The VENC function in the earlier version has been migrated to new VENC APIs. For details, see VENC Function Interfaces.

Function

The VENC module is used to encode YUV420 and YVU420 image data.

  • The VENC supports the following input formats:

    YUV420 semi-planner NV12/NV21-8bit

  • The VENC supports the following output formats:

    H264 BP/MP/HP

    H265 MP

VENC Performance Specifications

Scenario

Total Frame Rate

1080p, 1 channel (multi-channel is not supported)

30fps

Input Parameter: venc_in_msg

Member Variable

Description

Value Range

Int width

Image width

The value is an even number ranging from 128 to 1920.

Int height

Image height

The value is an even number ranging from 128 to 1920.

Int coding_type

Video encoding protocol

0~3

  • 0: H.265 MP
  • 1: H.264 BP
  • 2: H.264 MP
  • 3: H.264 HP

Int YUV_store_type

YUV image storage format

The value is 0 or 1.

  • 0: YUV420 Semi-Planar
  • 1: YVU420 Semi-Planar

char* input_data

Address of the input image data

The value cannot be null.

Int input_data_size

Size of the input image data

The value is a positive number.

shared_ptr<AutoBuffer> output_data_queue

Address for output encoded stream

The buffer needs to be configured. This parameter is a smart pointer transferred into the DVPP, used for the caller to allocate the output buffer. You can read this buffer to obtain the output image.

This parameter is mandatory.

Output Parameter

None

Calling Example

void TEST_3() //venc demo
{
    int read_file_size;
    int unit_file_size;
    FILE *fp = fopen(in_file_name, "rb");
    if (fp == NULL) {
        printf("open file: %s failed.\n", in_file_name);
        return;
    }
    printf("open yuv success \n");
    fseek(fp, 0L, SEEK_END);
    int file_size = ftell(fp);
    fseek(fp, 0L, SEEK_SET);

    venc_in_msg venc_msg;
    venc_msg.width = gWidth;
    venc_msg.height = gHigh;
    venc_msg.coding_type = gFormat;
    venc_msg.YUV_store_type = gBitwidth;
    venc_msg.output_data_queue = make_shared<AutoBuffer>();
    unit_file_size = gWidth * gHigh * 3 / 2 * MAX_FRAME_NUM_VENC; // The size of a single file is 16 frames.
    dvppapi_ctl_msg dvppApiCtlMsg;
    dvppApiCtlMsg.in = (void *)(&venc_msg);
    dvppApiCtlMsg.in_size = sizeof(venc_in_msg);
    IDVPPAPI *pidvppapi = NULL;
    CreateDvppApi(pidvppapi);
    char out_filename[] = "venc.bin";
    FILE *outputBufferFile;
    outputBufferFile = fopen (out_filename, "wb+");

    do{
       read_file_size = file_size>unit_file_size? unit_file_size:file_size; // The size of the file to be read each time cannot exceed 16 frames.
        venc_msg.input_data = (char *)malloc(read_file_size);
        int read_len = fread(venc_msg.input_data, 1, read_file_size, fp);
        printf("file size is %d,read len is %d.\n", read_file_size, read_len);
        venc_msg.input_data_size = read_len;        

        if (pidvppapi != NULL) {
            if (DvppCtl(pidvppapi, DVPP_CTL_VENC_PROC, &dvppApiCtlMsg) != 0) {
                printf("call dvppctl process faild!\n");
                DestroyDvppApi(pidvppapi);
                fclose(fp);
                fclose(outputBufferFile);
                return;
            }
            if (venc_msg.output_data_queue->getBufferSize() > 100) {// This is used to ensure that the encoding result does not contain only the header information.
                char* out_buf = venc_msg.output_data_queue->getBuffer();
                int out_buf_size = venc_msg.output_data_queue->getBufferSize();
                int write_size = fwrite(out_buf, 1, out_buf_size, outputBufferFile);
                fflush(outputBufferFile);               
            } else {
                printf("venc output data is too small : %d \n", venc_msg.output_data_queue->getBufferSize());
            }

        } else {
            printf("pidvppapi is null!\n");
        }

        if (venc_msg.input_data != NULL) {
            free(venc_msg.input_data);
            venc_msg.input_data = NULL;
        }

        file_size = file_size - unit_file_size;
    } while (file_size > 0);

    DestroyDvppApi(pidvppapi);
    fclose(outputBufferFile);
    fclose(fp);
    return;
}