4

I am developing an Android App in which I'm using ImageReader to get image from a Surface. The surface's data is achieved from the VirtualDisplay when i record screen in Lollipop version. The problem is the image is available with very low rate (1 fps) (OnImageAvailableListener.onImageAvailable() function is invoked). When i tried to use MediaEncoder with this surface as an input surface the output video looks smooth under 30fps. Is there any suggestion for me to read the image data of surface with high fps?

            ImageReader imageReader = ImageReader.newInstance(width, height, PixelFormat.RGBA_8888, 2);
            mImageReader.setOnImageAvailableListener(onImageListener, null);
            mVirtualDisplay = mMediaProjection.createVirtualDisplay("VideoCap",
                mDisplayWidth, mDisplayHeight, mScreenDensity,
                DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR,
                imageReader.getSurface(), null /*Callbacks*/, null /*Handler*/);

               //
               //

               OnImageAvailableListener onImageListener = new OnImageAvailableListener() {

    @Override
    public void onImageAvailable(ImageReader reader) {
        // TODO Auto-generated method stub
        if(reader != mImageReader)
            return;
        Image image = reader.acquireLatestImage();
        if(image == null)
            return;

        // do some stuff

        image.close();
      }
    };
nhanndt
  • 43
  • 1
  • 4

2 Answers2

3

FPS increased extremely when I switched to another format :

mImageReader = ImageReader.newInstance(mVideoSize.getWidth(), mVideoSize.getHeight(), ImageFormat.YUV_420_888, 2);

Hope this will help you.

Vikash Pandey
  • 5,407
  • 6
  • 41
  • 42
umnix
  • 46
  • 4
  • I got following error when I use this(ImageFormat.YUV_420_888) format at reader.acquireNextImage() https://code.google.com/p/chromium/issues/detail?id=459914 But, PixelFormat.RGBA_8888 works without any issue. Any idea ? – Narendrasinh Dodiya Dec 23 '15 at 13:16
0

I found that in addition to selecting the YUV format, I also had to select the smallest image size available for the device in order to get a significant speed increase.

Chris B
  • 401
  • 6
  • 10