0

I am trying to decode h264 video using ffmpeg and stagefright library. I'm using this example.

The example shows how to decode mp4 files, but i want to decode only h264 video.

Here is piece of my code..

    AVFormatSource::AVFormatSource(const char *videoPath) 
    {
        av_register_all();

        mDataSource = avformat_alloc_context();
        avformat_open_input(&mDataSource, videoPath, NULL, NULL);
        for (int i = 0; i < mDataSource->nb_streams; i++) 
        {
            if (mDataSource->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO) 
            {
                mVideoIndex = i;
                break;
            }
        }
        mVideoTrack = mDataSource->streams[mVideoIndex]->codec;

        size_t bufferSize = (mVideoTrack->width * mVideoTrack->height * 3) / 2;
        mGroup.add_buffer(new MediaBuffer(bufferSize));
        mFormat = new MetaData;

        switch (mVideoTrack->codec_id == CODEC_ID_H264) 
        {
            mConverter = av_bitstream_filter_init("h264_mp4toannexb");
            mFormat->setCString(kKeyMIMEType, MEDIA_MIMETYPE_VIDEO_AVC);
            if (mVideoTrack->extradata[0] == 1) //SIGSEGV Here
            {
                mFormat->setCString(kKeyMIMEType, MEDIA_MIMETYPE_VIDEO_AVC);
                mFormat->setData(kKeyAVCC, kTypeAVCC, mVideoTrack->extradata,
                                 mVideoTrack->extradata_size);
            }
         }

        mFormat->setInt32(kKeyWidth, mVideoTrack->width);
        mFormat->setInt32(kKeyHeight, mVideoTrack->height);
    }

mVideoTrack->extradata is NULL. What i'm doing wrong?? My question is, what should be in mVideoTrack->extradata for kKeyAVCC ??

Please help me, I need Your help. Thanks in advance.

Arsen Davtyan
  • 1,531
  • 7
  • 20
  • 32
  • You may find all required information here http://aviadr1.blogspot.com/2010/05/h264-extradata-partially-explained-for.html – Cedric Fung Mar 06 '14 at 09:29

1 Answers1

2

If your input is a raw h.264 file, It is already in annex B format. So you do not need to do the "h264_mp4toannexb" conversion. In addition, in annex B, the SPS/PPS are sent inline with the first (or every) IDR frame. So no extra data is needed. Read more here: Possible Locations for Sequence/Picture Parameter Set(s) for H.264 Stream

Community
  • 1
  • 1
szatmary
  • 27,213
  • 7
  • 39
  • 54
  • Thanks very much for your reply. As i understood, in this header of `h264`.. `00 00 00 01 67 64 00 1f ac d9 40 50 04 5f 9a 10 00 00 3e 90 00 0b b8 08 f1 83 19 60 00 00 00 01 68 eb ec b2 2c`. This data is SPS and PPS. So... I don't need this code **mFormat->setData(kKeyAVCC, kTypeAVCC, mVideoTrack->extradata, mVideoTrack->extradata_size);**. Am i right? – Arsen Davtyan Mar 07 '14 at 08:40
  • Correct, and you don't need the bitstream filter. – szatmary Mar 07 '14 at 18:08