Analyse image from a video/avc (h264) Android

asked 2016-12-18 14:56:09 -0600

Rivale gravatar image

updated 2016-12-18 15:14:21 -0600

Tetragramm gravatar image

Hi I want to analyse the frames from a streaming which is using a h264 encoding format.

this is the code I have to show each frame in a surfaceview inside the frame I have an array of byte which has the information of the next frame.

public void displayFrame(ARFrame frame) {
        mReadyLock.lock();



     if ((mMediaCodec != null)) {
            if (mIsCodecConfigured) {
                // Here we have either a good PFrame, or an IFrame
                int index = -1;

                try {
                    index = mMediaCodec.dequeueInputBuffer(VIDEO_DEQUEUE_TIMEOUT);
                } catch (IllegalStateException e) {
                    Log.e(TAG, "Error while dequeue input buffer");
                }
                if (index >= 0) {
                    ByteBuffer b;
                    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
                        b = mMediaCodec.getInputBuffer(index);
                    } else {
                        b = mBuffers[index];
                        b.clear();
                    }

                    if (b != null) {

                        b.put(frame.getByteData(), 0, frame.getDataSize());
                    }

                    try {
                        mMediaCodec.queueInputBuffer(index, 0, frame.getDataSize(), 0, 0);
                    } catch (IllegalStateException e) {
                        Log.e(TAG, "Error while queue input buffer");
                    }
                }
            }

            // Try to display previous frame
            MediaCodec.BufferInfo info = new MediaCodec.BufferInfo();
            int outIndex;
            try {
                outIndex = mMediaCodec.dequeueOutputBuffer(info, 0);

                while (outIndex >= 0) {
                    mMediaCodec.releaseOutputBuffer(outIndex, true);
                    outIndex = mMediaCodec.dequeueOutputBuffer(info, 0);
                }
            } catch (IllegalStateException e) {
                Log.e(TAG, "Error while dequeue input buffer (outIndex)");
            }
        }


        mReadyLock.unlock();
    }

My doubt is, in which part of this code can I extract the image to make it compatible with openCV and create a Mat variable so I can analyse the image

Thanks in advance

edit retag flag offensive close merge delete

Comments

I know this is extremely old, but has anyone tried Jcodec? It's supposedly a pure java based codec. I'm about to try doing just what you are doing, so wish me luck!!!

walter_morawa gravatar imagewalter_morawa ( 2019-04-25 02:58:55 -0600 )edit