3 Replies Latest reply on Nov 24, 2015 12:10 AM by pinform

    VCE2: wrong SPS/PPS headers


      We are integrating VCE that in MediaSDK 1.1 beta, the one based on AMFCreateComponent API.

      Here is my code to create encoder (according with simpleEncode sample code):

      AMF_ERROR( AMFCreateComponent(m_pContext, AMFVideoEncoderVCE_AVC, &m_pEncoder) );
      // Usage is preset that will set many parameters
      AMF_ERROR( PushParamsToPropertyStorage(&params, ParamEncoderUsage, m_pEncoder) );
      // override some usage parameters
      AMF_ERROR( PushParamsToPropertyStorage(&params, ParamEncoderStatic, m_pEncoder) );
      AMF_ERROR( m_pEncoder->Init(amf::AMF_SURFACE_NV12, pParams->width, pParams->height) );
      AMF_ERROR( PushParamsToPropertyStorage(&params, ParamEncoderDynamic, m_pEncoder) );


      and then I make following call to get SPS/PPS headers:

      AMF_ERROR( m_pEncoder->GetProperty(AMF_VIDEO_ENCODER_EXTRADATA, &extradata) );


      But received SPS/PPS is wrong. So resulting mp4 file can not be played by Windows Media Player. But first frame contains proper SPS/PPS. I tried to use hex editor and change mp4 headers with SPS/PPS from first frame and Windows Media Player plays this file fine. Can you please guide me what I did wrong?


      Next I will try to do is to apply ParamEncoderDynamic parameters before m_pEncoder->Init call (just swap these lines). But the above code is from sample in media SDK. And I even tried to set parameters according with config file and do not set any parameter at all (just use all default) - same result. But I do not think this will help. Seems there some bug in encoder.


      We can also work around this - by encoding 1 frame, read result, get SPS/PPS and reinitialize encoder. But we looking for proper solution.

        • Re: VCE2: wrong SPS/PPS headers



          Sorry for the delayed response.


          The way the encoder is created and initialized is correct. 


          Coming to your observations, firstly AMF Encoder will only generate elementary stream.  It does not generate any container format.  So to understand, are you wrapping the output from the encoder into mp4 file?


          Secondly, dynamic encoder parameters can only be applied once the encoder is intialized.  Not earlier to it.


          Could you help us with the following:

          Confirm that the encoded elementary stream is correct?  You could test this using standard tools to play elementary H.264 streams such as Elecard.

            • Re: VCE2: wrong SPS/PPS headers

              Bitstream is correct, we record mp4 and can play it. But SPS/PPS from AMF_VIDEO_ENCODER_EXTRADATA and from first frame was different. So we made SPS/PPS probe - submit 1 black frame, flush, extract SPS/PPS from output, then reinitialize encoder and start using it. No more issues after that work around. But now I think this issue can be related to another recently reported issue AMF VCE - Wrong encoding bitrate (fps). This maybe makes sense to retest AMF_VIDEO_ENCODER_EXTRADATA.

              Personally I think this makes good sense to support unified parameters input. It is because developers need to remember Variant type for every parameter and apply every parameter in proper way. And if AMD change some type later this may make many issues. For example, x264 have following function:

              int x264_param_parse(x264_param_t *param, const char *name, const char *value);

              So you can apply every parameter as string and don't care about it's type. So I added converters for all parameters that doesn't have converter assigned and I can submit string value for any parameter and encoder works properly now.