2014-03-06 46 views
0

我正在嘗試使用ffmpegstagefright庫來解碼h264視頻。我正在使用this示例。爲什麼AVCodecContext extradata是NULL?

該示例顯示如何解碼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爲NULL。我在做什麼錯了?我的問題是,應該在mVideoTrack->extradata中爲kKeyAVCC ??

請幫助我,我需要你的幫助。 在此先感謝。

+0

您可能會在這裏找到所有必需的信息http://aviadr1.blogspot.com/2010/05/h264-extradata-partially-explained-for.html –

回答

2

如果輸入是一個原始的H.264文件,它已經在附錄B格式。所以你不需要做「h264_mp4toannexb」轉換。另外,在附件B中,SPS/PPS與第一個(或每個)IDR幀一起內聯發送。所以不需要額外的數據。在這裏閱讀更多:Possible Locations for Sequence/Picture Parameter Set(s) for H.264 Stream

+0

非常感謝您的回覆。正如我理解的,在h264'的'這個頭..'00 00 00 01 67 64 00 1F交流D9 40 50 04 5F 10 9A 00 00 3E 90 00 0B 08 B8 83 F1 19 60 00 00 00 01 68 EB EC B2 2c'。這些數據是SPS和PPS。所以......我不需要這個代碼** mFormat->使用setData(kKeyAVCC,kTypeAVCC,mVideoTrack->而額外,mVideoTrack-> extradata_size); **。我對嗎? –

+0

正確,並且您不需要比特流篩選器。 – szatmary

+0

非常感謝... –