Why AVCodecContext extradata is NULL?

拜拜、爱过 提交于 2021-02-11 18:20:02

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/22219370/why-avcodeccontext-extradata-is-null

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!