UsageExampleForDecoder - shihuade/openh264 GitHub Wiki

This page is about the example of decoder usage

Decoder usage example

  • An example for using the decoder

Step 1:decoder declaration

//decoder declaration
ISVCDecoder *pSvcDecoder;
//input: encoded bitstream start position; should include start code prefix
unsigned char *pBuf =...;
//input: encoded bit stream length; should include the size of start code prefix
int iSize =...;
//output: [0~2] for Y,U,V buffer
unsigned char *pData[3] =...;
//in-out: declare and initialize the output buffer info
SBufferInfo sDstBufInfo;
memset(&sDstBufInfo, 0, sizeof(SBufferInfo));

Step 2:decoder creation

CreateDecoder(pSvcDecoder);

Step 3:declare required parameter

SDecodingParam sDecParam = {0};
sDecParam.sVideoProperty.eVideoBsType = VIDEO_BITSTREAM_AVC;

Step 4:initialize the parameter and decoder context, allocate memory

Initialize(&sDecParam);

Step 5:do actual decoding process in slice level; this can be done in a loop until data ends

iRet = DecodeFrame2(pBuf, iSize, pData, &sDstBufInfo);
//decode failed
If (iRet != 0){
    RequestIDR or something like that.
}
//pData can be used for render.
if (sDstBufInfo.iBufferStatus==1){
    output pData[0], pData[1], pData[2];
}

Step 6:uninitialize the decoder and memory free

Uninitialize();

Step 7:destroy the decoder

DestroyDecoder();
⚠️ **GitHub.com Fallback** ⚠️