openh264 User Guide
Overview
At present, openh264 official website has only a few questions and answers, the key development information is all on the GitHub page wiki page (Https://github.com/cisco/openh264/wiki)
The same official binary library is also available for download on the release page of the GitHub page (https://github.com/cisco/openh264/releases)
This article describes all Windows platforms, and other platforms use similar. The openh264 version used for this article does not provide an import library for 1.6,openh264 and can only be used in dynamic load mode. Use Get Object
The function interfaces provided by the DLL are obtained first using LoadLibrary and Getprocaddressapi. A total of 6 interfaces
Welscreatedecoder;
Welscreatesvcencoder;
Welsdestroydecoder;
Welsdestroysvcencoder;
welsgetcodecversion;
Welsgetcodecversionex;
Call the Welscreatedecoder interface to get the decoder object.
Call the Welscreatesvcencoder interface to get the Encoder object.
This section is not documented in the official documentation, so this is specifically stated here.
Gets the pointer to a C + + object through which the object's methods can be called. The header file of the object is codec_api.h in the Codec\api\svc directory of the source code (this is not stated in the official documentation). Encoder Device
The object obtained through the Welscreatesvcencoder interface is a pointer to the Isvcencoder type. Initialize
First call the object's Getdefaultparams method to get to the default parameter structure, and then overwrite its own parameters, depending on the actual situation, the meaning of the parameter reference document.
It is important to note that ispatiallayernum, which specifies the number of streams to output, is usually set to 1.
The parameters of the Sspatiallayers stream parameter array in the parameter are then also filled in with the parameters of the specified bitstream. The number of array elements is determined by ispatiallayernum.
Invokes the Initializeext method of the object, passing in the modified parameter, initializing the Encoder object.
and then call
int videoformat = videoFormatI420;
SetOption (Encoder_option_dataformat, &videoformat);
Set the format of the incoming image, currently only supports yuv420, so this sentence is fixed.
The encoder parameter setting is now complete. Coding
The true encoding requires the Encodeframe method of the calling object. The method requires two parameters, a ssourcepicture pointer type to hold the YUV data to be encoded, and a sframebsinfo pointer type to obtain the encoded NAL cell data.
The object contents of the Ssourcepicture type are as follows:
Ipicwidth: Incoming image width.
Ipicheight: Incoming image height.
Icolorformat: Incoming image format, there is only one videoFormatI420.
A line-wide array of istride:yuv3 channels.
An array of data pointers to the Pdata:yuv3 channel.
Call the Encodeframe method, pass in the correctly populated ssourcepicture pointer type parameter, and zero the Sframebsinfo pointer type parameter.
Then look at the return value if the return value is 0 and the Eframetype field of the Sframebsinfo type parameter is not equal to videoframetypeskip indicating that the data is encoded.
The data is stored in an array of slayerinfo structures of the Sframebsinfo type parameter. Pbsbuf in each of these structures represents the encoded data,
The length is the same as the structure Pnallengthinbyteint array, and the length of the array is represented by the Inalcount member of the struct body.
While the encoded data memory does not need to be freed, the encoder reuses the memory every time the object's Encodeframe method is called, meaning that the encoded data is valid before the next call to the object's Encodeframe method. This memory is freed when the encoder is destroyed. destroyed
Call the Encoder object's Uninitialize method, and then call the Welsdestroysvcencoder interface, passing in the previously obtained encoder object pointer. You can destroy objects and release resources. Decoding Device
The object obtained through the Welscreatedecoder interface is a pointer to the Isvcdecoder type. Initialize
Establish a Sdecodingparam type of empty parameter structure, the specific value according to the actual situation, the meaning of the parameter reference document. In particular, the Bparseonly field, which is to parse the content only, is usually used for testing, so it is set to False when it is used normally.
Invokes the Initialize method of the decoder object, passing in the correct sdecodingparam type parameter. decoding
The true decoding needs to call the decoder object's Decodeframenodelay method, which requires 4 parameters, the first unsigned char pointer type parameter represents the address of the incoming NAL cell start, and the second int parameter represents the length of the nal cell. The third unsigned char pointer array type parameter is used to receive the decoded image data, and the array space needs to be allocated in advance, but the actual memory pointed to by each pointer is not allocated. The fourth is an empty sbufferinfo pointer-type parameter that gets some information about the decoded data.
Call the Decodeframenodelay method of the decoder object, pass in the corresponding parameter, receive the return value, and if return equals 0 and the Sbufferinfo type parameter, Ibufferstatus equals 1. On behalf of the successful decoding of the data.
The decoded image data is stored in a pointer array of the third parameter passed in by the channel. The UsrData.sSystemBuffer.iWidth in the Sbufferinfo type parameter indicates the width of the image, the UsrData.sSystemBuffer.iHeight in the Sbufferinfo type parameter indicates the height of the image, the Sbufferinfo type argument The sDstBufInfo.UsrData.sSystemBuffer.iStride array in the number indicates the line width for each channel.
According to these 3 parameters can be decoded to get the valid image data in the data out. destroyed
Call the Uninitialize method of the decoder object, and then call the Welsdestroydecoder interface, passing in the decoder object pointer that was obtained before. You can destroy objects and release resources.