Reputation: 3687
I'm trying to modify the basic Camera2 API sample (https://github.com/googlesamples/android-Camera2Basic) so that it takes a picture every x seconds (and then processes it on the background thread; I don't even need to save the image to the disk), while showing smooth preview. Unfortunately, calling capture()
on the capture session freezes the preview for a second or two, resulting in poor user experience.
Is there a way to get to the preview surface directly and read image bytes? I don't care about the image quality, smooth UX is the priority.
Upvotes: 0
Views: 744
Reputation: 18137
If the camera device is a LEGACY-level device, this is unfortunately expected.
Even for a LIMITED device, the camera has to support the BURST_CAPTURE capability to guarantee full-resolution capture at a fast rate. All FULL-level or better devices do support BURST_CAPTURE.
However, even on lower-capability devices, you can typically capture uncompressed YUV frames at video recording resolutions smoothly. That means adding in an ImageReader with a YUV_420_888 format to your session configuration, and then processing the Images that come out of that. JPEGs on LEGACY devices are unfortunately always slow, and some LEGACY devices don't have enough CPU power to smoothly produce the YUV data either (because there have to be some conversions under the hood).
For more detail, you can inspect the outputs of StreamConfigurationMap and see what output YUV resolutions run at a minimum frame duration of 1/30s; those should guarantee smooth operation for LIMITED or better devices.
Upvotes: 1