1

I need to speed-up capturing of camera2 API. I tried to build "android-Camera2Basic" project from google samples. For default capture request from example:

 if (null == activity || null == mCameraDevice) {
            return;
        }
        // This is the CaptureRequest.Builder that we use to take a picture.
        final CaptureRequest.Builder captureBuilder =
                mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);
        captureBuilder.addTarget(mImageReader.getSurface());

        // Use the same AE and AF modes as the preview.
        captureBuilder.set(CaptureRequest.CONTROL_AF_MODE,
                CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE);
        captureBuilder.set(CaptureRequest.CONTROL_AE_MODE,
                CaptureRequest.CONTROL_AE_MODE_ON_AUTO_FLASH);

        // Orientation
        int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
        captureBuilder.set(CaptureRequest.JPEG_ORIENTATION, ORIENTATIONS.get(rotation));

        CameraCaptureSession.CaptureCallback CaptureCallback
                = new CameraCaptureSession.CaptureCallback() {

            @Override
            public void onCaptureCompleted(CameraCaptureSession session, CaptureRequest request,
                                           TotalCaptureResult result) {
                showToast("Saved: " + mFile);
                unlockFocus();
            }
        };

        mCaptureSession.stopRepeating();
        mCaptureSession.capture(captureBuilder.build(), CaptureCallback, null);

It takes 200-300ms from send request

mCaptureSession.capture(captureBuilder.build(), CaptureCallback, null);

And get result in

onImageAvailable(ImageReader reader)

Is it possible to reduce this time? I tried set different parameters for capture request, such as TEMPLATE_ZERO_SHUTTER_LAG, NOISE_REDUCTION_MODE_OFF, EDGE_MODE_OFF, etc. But it has no any effect. If I try to capture burst, then all images, except first are comes very fast, no more then in 30-40ms. How can I reduce capturing time for first image?

Maxim Metelskiy
  • 1,389
  • 14
  • 29
  • I'm pretty sure that initial time is a hardware limitation and you won't be able to make it smaller. That's just how long it takes for the request to go through the sensor controller, the sensor captures it, the raw data get decoded and the results dispatched back to your app control. – Budius Feb 17 '15 at 17:07
  • I guess it. But In burst capturing frames are captured very fast, except first one. Besides I tried not to stop preview capturing, so camera should be "hot", and not need to initiate all parameters. But the result is the same. And I think ZERO_SHUTTER_LAG option can't have same results. – Maxim Metelskiy Feb 17 '15 at 17:29
  • @MaximMetelskiy How did you get the burst to capture so quickly? My pictures are spaced 200-300 ms apart even when using captureBurst. I can just ask a new question if you'd like. – acheroncaptain Mar 25 '15 at 04:29
  • @acheroncaptain I think it may depends from device model and camera2 supported version. My data is actual for Nexus 5 with FULL support of camera2 API. According to my experience same result may have Nexus 6 and LG G Flex 2. If you have one of this devices and can't get 30-40 ms between frames, then I may help you. But I need to see your capturing code. – Maxim Metelskiy Mar 25 '15 at 07:53
  • @MaximMetelskiy I've got a Nexus 5. I posted a new question here: http://stackoverflow.com/questions/29265126/android-camera2-capture-burst-is-too-slow – acheroncaptain Mar 25 '15 at 19:47

1 Answers1

6

replying to your comment, but making it into a proper answer:

If you check those slides from the Samsung dev. conference on slide #22 it shows the camera2 model. As you can see, there're several queues:

  • Pending Request queue
  • In flight capture queue
  • output image queue to the Surface showing the camera preview
  • and the callback to onCaptureComplete

Camera2 API core operation model

that explains why the 1st capture is slow, but in burst mode the next images comes very fast. The requests and processing are queued and the 1st takes 300ms to arrive all the way back on the callback but the next one is already "right behind it".

If you're interested in the new API (and who wouldn't be, camera2 is amazing), you can also check the full video from the Samsung Dev. conference on YouTube. And the official docs. Lot's of good info on those.

Budius
  • 39,391
  • 16
  • 102
  • 144