Search code examples
androidandroid-camera2

Interpreting data from an ImageReader with format ImageFormat.Private


I have set up a ConstrainedHighSpeedCaptureSession targeting the surface of an ImageReader object. I aim to capture a short burst of high FPS footage that I'd like to further process (for instance, finding the acceleration of an object).

The HighSpeedCapture session only functions when the ImageReader's format is set to ImageFormat.PRIVATE -- this is forced in android.hardware.camera2.utils.SurfaceUtils.checkHighSpeedSurfaceFormat, compare android source. I'm aware that the PRIVATE format is implementation-specific so the raw bytes cannot be interpreted directly, however, the implementation should be aware of how to convert this image format to some standard format, which is what I need.

Currently, I am simply reacting to the captured image becoming available through the ImageReader.OnImageAvailable callback.

There must be some way of interpreting PRIVATE format ImageReaders, perhaps the data can be rendered to some Canvas or different Surface in the background.


Solution

  • You can use Vulkan to import images with private format. You'll need to import android HardwareBuffer memory to vulkan and use a sampler with Y′CBCR conversion configured with VkExternalFormatANDROID.

    I believe there also should be a similar way to import such an image in OpenGL, but I haven't used it.