mediacodec surfaceview解碼失敗

原來在configure的時候設置了sps/pps(如下),發現有些機型解碼失敗,dequeueInputBuffer、queueInputBuffer這些老是異常



MediaFormat format = MediaFormat.createVideoFormat("video/avc", 480, 480);

//format.setByteBuffer("csd-0", ByteBuffer.wrap(spsPps[0]));

//format.setByteBuffer("csd-1", ByteBuffer.wrap(spsPps[1]));

try {    mDecoder = MediaCodec.createDecoderByType("video/avc");} catch (IOException e) {  e.printStackTrace();}

 mDecoder.configure(format, surface.getHolder().getSurface(), null, 0);//blind surfaceView

 mDecoder.start(); //start decode thread




解決方案:

configure時候不設置sps/pps,在queueInputBuffer設置config(如下):

int value = mReadH264Buf[4] & 0x0f;

if (value == 7 || value == 8) {

    mDecoder.queueInputBuffer(inputIndex, 0, realDataLen, timestamp, MediaCodec.BUFFER_FLAG_CODEC_CONFIG);

}else if(value == 5){    

   mDecoder.queueInputBuffer(inputIndex, 0, realDataLen, timestamp, MediaCodec.BUFFER_FLAG_KEY_FRAME);

}else{    

   mDecoder.queueInputBuffer(inputIndex, 0, realDataLen, timestamp, 0);

 }


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章