2 Replies Latest reply on Jul 28, 2015 3:08 AM by ffranck

    AMF h.264 decode woes (GetDPBSize() undefined)


      Hi Gurus,


      Hope you can help me here.

      I'm trying to accomplish a setup where the following pipeline runs:  BGRA -> h.264 encode -> transmit over network -> h.264 decode -> BGRA.  The first three steps are done, and the x.264 frames are being received by the remote system (I know this because I can dump them to a file and review them with ffplay).  However, I can't seem to get the decode stage to work.


      I'm setting up a decode pipeline based loosely on the simpleDecode.cpp example from the SDK:


      1)  I create a DataStream:

          void *data = malloc(1024 * 1024);
          dataStream = AMFDataStream::Create(data, 1024 * 1024);


      2)  I receive frames which I then write to dataStream:

          dataStream->Write(buffer->value, buffer->length);


      3)  When I've collected one hundred frames, I initialize the h.264 parser:

          if (100 == recvframes) {
              parser = BitStreamParser::Create(dataStream, BitStreamH264AnnexB, context);


      4)  When that parser returns data from a QueryOutput() call, I feed that data to the decoder:

          res = parser->QueryOutput(&data); // read compressed frame into buffer
          if (NULL == data) {
          } else if (AMF_EOF == res) {
              break;// end of file

          res = decoder->SubmitInput(data);


      However, that call to SubmitInput() results in an exception and an error message in the output pane of Visual Studio:

      1DFC [H264Parser]   Error: ..\..\..\..\..\impl\components\VideoStreamParser\parsers\h264\H264Parser.cpp(2947):GetDPBSize() undefined level_idc=0
      1DFC [h264parser_util]   Error: ..\..\..\..\..\impl\components\VideoStreamParser\parsers\h264\h264_util.cpp(91):Assertion failed:false
      AMD Decode Init Test.exe has triggered a breakpoint.


      I have been searching the forums for hints, and AMF fails to decode live h.264 stream. seems to be the closest-related thread, however, the fix there seems to be to stall parsing in a live stream until keyframes with required info come by.  In my case, I can setup the system such that I have access to the entire h.264 stream being streamed, from the very first frame, and thus should not be starting in the middle of a stream.


      Any hints as to what I may be doing wrong?  Please let me know you need me to post more specifics about my code.




        • Re: AMF h.264 decode woes (GetDPBSize() undefined)

          Welcome! You're white listed, and this is moved into the Media SDK forum.

          • Re: AMF h.264 decode woes (GetDPBSize() undefined)

            To answer my own question here, the problem turned out to be that I'd forgotten to tell the decoder of the extra headers that come with the frames when they're submitted.  I.e., I'd left out the following piece of code from the simpleDecode example:


            if (parser->GetExtraDataSize())
            { // set SPS/PPS extracted from stream or container; Alternatively can use parser->SetUseStartCodes(true)
                amf::AMFBufferPtr buffer;
                context->AllocBuffer(amf::AMF_MEMORY_HOST, parser->GetExtraDataSize(), &buffer);

                memcpy(buffer->GetNative(), parser->GetExtraData(), parser->GetExtraDataSize());
                decoder->SetProperty(AMF_VIDEO_DECODER_EXTRADATA, amf::AMFVariant(buffer));


            Hope this might help someone else in the future.