0

我正在尝试使用和库解码h264视频。我正在使用这个例子。ffmpegstagefright

该示例显示了如何解码mp4文件,但我只想解码h264视频。

这是我的一段代码..

    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一片空白。我做错了什么??mVideoTrack->extradata我的问题是,kKeyAVCC应该包含什么?

请帮助我,我需要你的帮助。提前致谢。

4

1 回答 1

2

如果您的输入是原始 h.264 文件,它已经是附件 B 格式。所以你不需要做“h264_mp4toannexb”转换。此外,在附件 B 中,SPS/PPS 与第一个(或每个)IDR 帧一起发送。所以不需要额外的数据。在此处阅读更多信息:H.264 流的序列/图片参数集的可能位置

于 2014-03-06T17:36:16.410 回答