How to populate "extradata" field in AVCodecContext with SPS and PPS data?

Here is the problem, when decoding an H264 stream with ffmpeg

I can get the raw SPS and PPS data, but I don't know how to fill it in the field extradata

AVCodecContext

. Without, extradata

I cannot decode the frames correctly. Every time I call avcodec_decodec_video2

, the return value is positive, but the flag is got_picture

always zero

. Can anyone help me with this issue?

The stream I'm dealing with looks like this:

[0x67]...[0x68]...[0x61]...[0x61]...  .......  [0x61]...[0x67]...[0x68]...  ......

      

Thanks in advance!

+3


source to share


2 answers


The data you mentioned is a byte stream containing NAL units for SPS and PPS. extradata

in turn expects a pointer to an AVC decoder configuration record, which is the data you have with additional formatting.

For details, see "Advanced Video Coding (AVC) File Format" in 5.2.4.1 MPEG-4 Part 15.



5.2.4.1.1 Syntax 

aligned(8) class AVCDecoderConfigurationRecord { 
   unsigned int(8) configurationVersion = 1; 
   unsigned int(8) AVCProfileIndication; 
   unsigned int(8) profile_compatibility; 
   unsigned int(8) AVCLevelIndication;  
   bit(6) reserved = ‘111111’b;
   unsigned int(2) lengthSizeMinusOne;  
   bit(3) reserved = ‘111’b;
   unsigned int(5) numOfSequenceParameterSets; 
   for (i=0; i< numOfSequenceParameterSets;  i++) { 
      unsigned int(16) sequenceParameterSetLength ; 
  bit(8*sequenceParameterSetLength) sequenceParameterSetNALUnit; 
 } 
   unsigned int(8) numOfPictureParameterSets; 
   for (i=0; i< numOfPictureParameterSets;  i++) { 
  unsigned int(16) pictureParameterSetLength; 
  bit(8*pictureParameterSetLength) pictureParameterSetNALUnit; 
 } 
}

      

0


source


c_v->extradata = (uint8_t*)av_malloc(flvBufSize + FF_INPUT_BUFFER_PADDING_SIZE);
                                    if(!c_v->extradata){
                                        loge("Could not av_malloc extradata");
                                    }
                                    logv("extradata_size =%d", c_v->extradata_size);
                                    c_v->extradata_size = flvBufSize;
                                    memcpy(c_v->extradata, avpkt.data, avpkt.size);

                                    if (avcodec_open2(c_v, codec_v, NULL) < 0) {
                                        loge("could not open video codec");                             
                                    }

      



0


source







All Articles