Ask Your Question

Revision history [back]

Analyse image from a video/avc (h264) Android

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

click to hide/show revision 2
No.2 Revision

Analyse image from a video/avc (h264) Android

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();

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