openh264 icon indicating copy to clipboard operation
openh264 copied to clipboard

Failed to decode on android

Open miss-o-hara opened this issue 12 years ago • 7 comments

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 (&param, 0, sizeof(SEncParamBase));

  param.fMaxFrameRate = 30.0f;
  param.iPicWidth = 320;
  param.iPicHeight = 240;
  param.iTargetBitrate = 5000;
  param.iInputCsp = videoFormatI420;
  int retVal = encoder_->Initialize(&param);

  //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?

miss-o-hara avatar Mar 05 '14 13:03 miss-o-hara

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?

licaiguo avatar Mar 06 '14 02:03 licaiguo

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 .. } }

octalflow avatar Mar 11 '14 15:03 octalflow

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.

huili2 avatar Mar 13 '14 01:03 huili2

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?

miss-o-hara avatar Mar 17 '14 20:03 miss-o-hara

what is the layerSize for your decoder ? what is the total encoded length ?

octalflow avatar Mar 18 '14 04:03 octalflow

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.

huili2 avatar Mar 18 '14 05:03 huili2

Is the issue still existing? If not, I'll close it in one day.

huili2 avatar Mar 27 '14 06:03 huili2