0

I am using Mediacodec on Android for H264 stream Decoding. The raw data stream consists of a series of NAL Units. Every frame(640*480) in the video is divided into four parts in the stream.

Each time I send a buffer(One NAL Unit) into Mediacodec Decoder and wait for the outputbuffer.

It turns out that the outputbuffer capacity is as big as a YUV Frame,but the number of outputbuffers that come up is nearly four times the Frame number.I guess the outputbuffer only returns 1/4 of the decode result.If it is so ,how can I get continuous YUV Frame Data ?

public void setDataToDecoder(byte[] videoBuffer,int size,int id){
        Log.e("Decoder","-----------"+id);
        inputBufferIndex = mediaCodec.dequeueInputBuffer(-1);
        //Log.e("Decoder","InputIndex "+inputBufferIndex);
        if(inputBufferIndex>=0){
            ByteBuffer inputBuffer=inputBuffers[inputBufferIndex];
            inputBuffer.clear();
            inputBuffer.put(videoBuffer,0,size);
            mediaCodec.queueInputBuffer(inputBufferIndex, 0, size, timeStamp, 0);
            timeStamp++;
        }
        BufferInfo bufferInfo = new BufferInfo();
        outputBufferIndex = mediaCodec.dequeueOutputBuffer(bufferInfo, 0);
        while(outputBufferIndex>=0){
            ByteBuffer outputData=outputBuffers[outputBufferIndex];
            if(bufferInfo.size!=0){
                outputData.position(bufferInfo.offset);
                outputData.limit(bufferInfo.offset+bufferInfo.size);
                Log.e("P","oooo"+outputData.position());
                Log.e("P","oooo"+outputData.limit());
            }
            int tmp;
            if(FrameCt<=20){
                try {
                    tmp = fc.write(outputData);
                    Log.e("P",""+tmp);
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
            FrameCt++;
            mediaCodec.releaseOutputBuffer(outputBufferIndex, false);
            outputBufferIndex = mediaCodec.dequeueOutputBuffer(bufferInfo, 0);
        }
        Log.e("Decoder","-----------"+id);
    }
samgak
  • 23,944
  • 4
  • 60
  • 82
  • 1
    You can't generally feed one frame to the decoder and wait for the result. It's possible for video to be generated with frames slightly out of order. You want to feed video frames in as quickly as possible, and handle the output as it becomes available. See http://bigflake.com/mediacodec/ for more information about MediaCodec. – fadden Apr 23 '15 at 15:38
  • Do you mean the encodeDecodeTest...I can't figure it out how is the frame generated...The actual data I stream in has only 1/4 the number of frames of the output – Siberiamark Apr 24 '15 at 02:30

0 Answers0