Decodificación h264 ByteStream en Android siempre obtiene INFO_TRY_AGAIN_LATER de dequeueOutputBuffer ()

Tratando de utilizar el códec multimedia para decodificar los paquetes codificados de datos de gramas, pero siempre obtiene -1 en dequeueOutputBuffer ().

Por favor, ayúdame, ¿qué estoy haciendo mal? Estoy tratando de enfrentar este problema durante días sin éxito.

Private void decodeVideo () {

new Thread(new Runnable() { @Override public void run() { int n = 0; MediaFormat mediaFormat = new MediaFormat(); mediaFormat.setString(MediaFormat.KEY_MIME, "video/avc"); mediaFormat.setInteger(MediaFormat.KEY_MAX_INPUT_SIZE, 100000); mediaFormat.setInteger(MediaFormat.KEY_WIDTH, surfaceView.getWidth()); mediaFormat.setInteger(MediaFormat.KEY_HEIGHT, surfaceView.getHeight()); mediaFormat.setInteger( MediaFormat.KEY_PUSH_BLANK_BUFFERS_ON_STOP, 1); mediaFormat.setInteger(MediaFormat.KEY_COLOR_FORMAT, MediaCodecInfo.CodecCapabilities.COLOR_FormatL2);// TODO byte[] csd_info = { 0, 0, 0, 1, 103, 100, 0, 40, -84, 52, -59, 1, -32, 17, 31, 120, 11, 80, 16, 16, 31, 0, 0, 3, 3, -23, 0, 0, -22, 96, -108, 0, 0, 0, 1, 104, -18, 60, -128 }; mediaFormat.setByteBuffer("csd-0", ByteBuffer.wrap(csd_info)); mediaFormat.setInteger(MediaFormat.KEY_MAX_INPUT_SIZE, 1920 * 1080); mediaFormat.setInteger("durationUs", 63446722); MediaCodec codec = MediaCodec.createDecoderByType("video/avc"); codec.configure(mediaFormat, mHolder.getSurface(), null, 0); codec.start(); ByteBuffer[] inputBuffers = codec.getInputBuffers(); ByteBuffer[] outputBuffers = codec.getOutputBuffers(); BufferInfo info = new BufferInfo(); while (flag) { int inputBufferIndex = codec.dequeueInputBuffer(-1); if (inputBufferIndex >= 0) { while (mPackets.size() <= 0) { try { Log.d(TAG, "nopackets"); Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } } Log.d(TAG, "now I have packets!"); inputBuffers[inputBufferIndex].clear(); DatagramPacket currentDatagram = mPackets.remove(); byte[] byteBuffer = (ByteBuffer.wrap(currentDatagram .getData())).array(); inputBuffers[inputBufferIndex].put(byteBuffer, 0, byteBuffer.length); codec.queueInputBuffer(inputBufferIndex, 0, byteBuffer.length, timestamp(), 0); } int outputBufferIndex = codec.dequeueOutputBuffer(info,-1);//always get-1 if (outputBufferIndex == MediaCodec.INFO_OUTPUT_BUFFERS_CHANGED) { outputBuffers = codec.getOutputBuffers(); Log.d(TAG, "INFO_OUTPUT_BUFFERS_CHANGED"); } else if (outputBufferIndex == MediaCodec.INFO_OUTPUT_FORMAT_CHANGED) { // Subsequent data will conform to new format. mediaFormat = codec.getOutputFormat(); Log.d(TAG, "INFO_OUTPUT_FORMAT_CHANGED"); } else if (outputBufferIndex >= 0) { Log.d(TAG, "outputBufferIndex>=0"); if (n > 2) { Log.d(TAG, "n>2"); // We have successfully encoded and decoded an image // ! int length = info.size; codec.releaseOutputBuffer(outputBufferIndex, false); n++; } } } codec.stop(); codec.release(); codec = null; } }).start(); } 

Muchas gracias por dar su tiempo.

FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.