Is it possible to combine Preview, ImageAnalysis, and VideoCapture with CameraX?
Asked Answered
A

1

10

Is it possible to bind Preview, ImageAnalysis, and VideoCapture at the same time? Combined in pairs, all possible combinations (ie. Preview+ImageAnalysis, Preview+VideoCapture, and ImageAnalysis+VideoCapture) work perfectly fine but binding all three together throws the following exception.

java.lang.IllegalArgumentException: No supported surface combination is found for camera device - Id : 1.  May be attempting to bind too many use cases.
    at androidx.camera.camera2.internal.Camera2DeviceSurfaceManager.getSuggestedResolutions(Camera2DeviceSurfaceManager.java:193)
    at androidx.camera.core.CameraX.calculateSuggestedResolutions(CameraX.java:943)
    at androidx.camera.core.CameraX.bindToLifecycle(CameraX.java:293)
    at androidx.camera.lifecycle.ProcessCameraProvider.bindToLifecycle(ProcessCameraProvider.java:229)

Is there any workaround that allows me to use ImageAnalysis and at the same time record a video?

Appraisal answered 30/4, 2020 at 13:36 Comment(3)
This limitation could be device dependent, I am not sure. But if you have ImageAnalysis, you can run your custom video recorder (based on MediaCodec).Moiramoirai
Any success on this one?Parenthesis
Unfortunately not. I ended up implementing my own solution using Camera2. I don't know if anything has changed with CameraX since my original post.Appraisal
E
2

There are limits to the number of simultaneous outputs that are due to the camera hardware pipeline's scaler unit limitations.

In general, 3 parallel YUV outputs aren't supported outside of high-end devices.

You can look at the many tables here: https://developer.android.com/reference/android/hardware/camera2/CameraDevice#createCaptureSession(android.hardware.camera2.params.SessionConfiguration)

and see what kinds of parallel outputs can be set up, on the various hardware levels (PRIV and YUV are what these usecases operate on).

A FULL device can do it, as long as the analysis runs at 640x480 or lower. But LEGACY and LIMITED cannot.

That said, you can use ImageAnalysis frames to drive a preview, but it's certainly a bit less convenient - may require using the NDK or other annoyances.

Electronic answered 3/5, 2021 at 23:29 Comment(2)
Using ImageAnalysis for the preview is not possible in some cases. For example, when doing image recognition you need the frames to be quite small to minimise delays. I ended up using Camera2 and passing 3 surfaces to CameraDevice.createCaptureSession() for preview, image analysis, and video capture, respectively. That worked smoothly and the million dollar question now is: if I can do it with Camera2, why can't I do it with CameraX?Appraisal
It may work on your test device, but there are likely many devices it won't work on. CameraX should work similarly on your device, however, so it's odd that there's a problem. Possibly a higher resolution was selected by CameraX than what you manually set up?Electronic

© 2022 - 2024 — McMap. All rights reserved.