Failed to decode on android
Hi!
I have faced with error when I try to decode the frame. My application gets the frames from camera, after that I convert them into I420 format using libyuv library.
I pass the frame in I420 format to encoder, and it seems that it encodes successfully, I get the type of the first frame - IDR, and the following frames' type is P.
Encoder and decoder initialization:
SEncParamBase param;
memset (¶m, 0, sizeof(SEncParamBase));
param.fMaxFrameRate = 30.0f;
param.iPicWidth = 320;
param.iPicHeight = 240;
param.iTargetBitrate = 5000;
param.iInputCsp = videoFormatI420;
int retVal = encoder_->Initialize(¶m);
//decoder
SDecodingParam decParam;
memset(&decParam, 0, sizeof(SDecodingParam));
decParam.sVideoProperty.size = sizeof (decParam.sVideoProperty);
decParam.iOutputColorFormat = videoFormatI420;
decParam.uiTargetDqLayer = (uint8_t) - 1;
decParam.uiEcActiveFlag = 1;
decParam.sVideoProperty.eVideoBsType = VIDEO_BITSTREAM_AVC;
long rv = decoder_->Initialize(&decParam);
This is how I copy the buffer:
int iSliceSize;
iSliceSize = CalcBufferSize(kI420, inputImage.width(), inputImage.height());
uint8_t* encodedBuf;
uint8_t* encodedBufHead;
encodedBuf = new uint8_t [iSliceSize];
encodedBufHead = encodedBuf;
int freespace = iSliceSize;
int layerSize = 0;
for (int i = 0; i < encodedOutput.iLayerNum; ++i)
{
const SLayerBSInfo& layerInfo = encodedOutput.sLayerInfo[i];
layerSize = 0;
for (int j = 0; j < layerInfo.iNalCount; ++j)
{
layerSize += layerInfo.iNalLengthInByte[j];
}
if (freespace >= layerSize)
{
memcpy(encodedBufHead, layerInfo.pBsBuf, layerSize);
encodedBufHead += layerSize;
}
}
Then I pass encodedBuf to DecodeFrame2() method:
SBufferInfo sDstBufInfo;
memset (&sDstBufInfo, 0, sizeof (SBufferInfo));
void* pData[3] = {NULL};
pData[0] = NULL;
pData[1] = NULL;
pData[2] = NULL;
decoder_->DecodeFrame2 (encodedBuf, layerSize, pData, &sDstBufInfo);
As a result I have sDstBufInfo.iBufferStatus != 1. All the fields in sDstBufInfo are empty.
What do I do wrong? Or this is a bug?
Hi, The decoder's init code seems ok . Could you save the bitstream to file and decode it on PC using JM's decoder? If JM's decoder can decode it successfully. Can you check the return value of DecodeFrame2?
pls try as below. In my case, first DecodeFrame2 always return iBufferStatus == 0.
if(ret = m_decoder->DecodeFrame2((unsigned char_)h264_data, h264_data_size, (void__)output_yuv, &bufInfo), ret == 0) { if(bufInfo.iBufferStatus != 1) { int iEndOfStreamFlag = 1; m_decoder->SetOption(DECODER_OPTION_END_OF_STREAM, &iEndOfStreamFlag); ret = m_decoder->DecodeFrame2(NULL, 0, (void_*)output_yuv, &bufInfo); } if(ret == 0) { // do .. } }
if the h264_data contains only one NAL, it will results in iBufferStatus = 0, because the decision of output or not depends on the following packet detection. So I think "first DecodeFrame2 always return iBufferStatus == 0." has no problem.
Hi,
I have got return value from DecodeFrame2 - 16 (dsNoParamSets = 0x10, /* No parameter set NALs involved */)
Could you please clarify what does it mean?
As a result I have empty data from DecodeFrame2. After EncodeFrame method I have layerSize less then 1000. Is it normal? Frame type is always idr or p.
BUT. From the first frame I have got the return value from DecodeFrame2 method - 0. If I call DecodeFrame2 method the second time as octalflow suggested, the return value is 4. After that I have always return value -16.
My application takes the frames from camera one by one (lifestream). It does not write to file, it converts them one by one to I420 format and sends them to encoder. As the encoder encodes one frame it passes the output to the decoder, and after receives the new one. Should I set any other option for encoder/decoder in this case?
what is the layerSize for your decoder ? what is the total encoded length ?
Hi miss-o-hara, layerSize is related to resolution and encoder efficiency, so smaller than 1000 may be possible for very small pictures and static background. But I guess 1000 bytes is not enough for IDR. The decoder information indicates your input compressed data into decoder has error, (may lose some data) so the decoder will ouput dsNoParamSets. So generally I think there is something wrong before decoder.
Is the issue still existing? If not, I'll close it in one day.