Cannot zoom as far out as built-in camera app
When I set the zoom in e.g. RtmpCamera2 I cannot zoom out as far as I can with the built-in camera app on my Galaxy S10 with Android 9. When I get the cameraIdList from the CameraManager, I get four cameras. So I think that it could be either that the library should use another camera for zooming out more (and the library now only uses the first back (or front) camera it finds), or zooming should not only set the SCALER_CROP_REGION, but also LENS_FOCAL_LENGTH for optical zoom, or perhaps both.
Hello,
First of all, remember that Camera api provided by Android not always can emulate built-in camera app, because the provider cap few features that only are available in built-in app (for example record 60fps)
The library select first back/front cameras because it is the main camera and other camera sometimes is used for few things like "portratit mode effect" or wide angle.
About zoom, I will try check about optical zoom to know if I can combine both zooms.
Anyway, since I haven't the same device and I can't know zoom used in your built-in camera app and compare results, I recommend you try modify Camera2ApiManager class by yourself and you can fix it better than me sharing you code that could not work multiples times for you device. Also, you can share code with me using a PR or copy change here to help you with this.
I think the easiest solution for me is to add a method switchCamera(String cameraId) to Camera2Base so that I can choose explicitly which camera to use. And since the camera id is actually a String (and it might be something else than "1" or "2" for external cameras) I have changed the cameraId field from int to String as well in my version. Now I can switch between two cameras and use a wider angle. It would be nice to have a smooth zoom over the different cameras, but for now I am happy with this, because I usually do not have to zoom in or out while streaming or recording anyway.
I have not used PRs yet, so here is my diff. (My version is at https://github.com/Ernovation/rtmp-rtsp-stream-client-java which I just merged with your latest version.) diff.txt
Your code was added to library here: https://github.com/pedroSG94/rtmp-rtsp-stream-client-java/commit/e6ae111971ccd53cc70ec809e8df41d4d14fdb1c Also, I did a commit that could usedfull for you. I'm not sure if optical zoom is working because I only receive 1 value and nothing happens but getCamerasAvailable could be usedfull to avoid hardcode camera IDs: https://github.com/pedroSG94/rtmp-rtsp-stream-client-java/commit/d8d2d1e615b75bca897a7cdd46ce8185075360ec
Let me know if optical zoom works for you and I will close this issue.
I've done some reasearch into multicamera api and the conclusion is that not all devices are created equal. For example google pixel 4 only lists one back facing camera with a zoom ratio android.control.zoomRatioRange = [1.0, 8.0] and does the automatically switch between main and telephoto based on the zoom. Pixel 6 for example lists zoom [0.6704426, 7.0] so setting a zoom level below 1 should in theory switch to ultrawide.
Other devices lists a logical camera id alongside the physical ones and require quite a bit of new api logic to seamlessly switch between them see docs - example Pixel 3 front facing cameras.
And at the very end of the spectrum you have samsung which on a regular S21 only exposes the main and ultra wide physical cameras. No telephoto camera id and no logical camera so you have to manually switch between them.
@pedroSG94 i don't think you are using the new CameraCharacteristics.CONTROL_ZOOM_RATIO_RANGE to get the zoom range and CaptureRequest.CONTROL_ZOOM_RATIO to set the zoom level right? They were added in api 30 and they are worth adding so pixel devices can take advantage.
I've compiled 4 device reports(pixel 4, pixel 6, S21 and a sony phone with multiple cameras) using this app. Maybe they help : camera2test devices.zip. Sony phone is on android 10 (29) so that's probably why it doesn't have a zoom range.
Hello,
I tested CameraCharacteristics.CONTROL_ZOOM_RATIO_RANGE but it is working exactly like use CaptureRequest.SCALER_CROP_REGION. It is a digital zoom but it is easy to implement because I don't need to create a Rect, etc. I only have range 1 to X support so I can't check it for zoom out. Test this branch and let me know if it is working for you: https://github.com/pedroSG94/rtmp-rtsp-stream-client-java/tree/checkcamera2zoom
Code looks okay to me. Yes, from my testing the code should behave exactly like CaptureRequest.SCALER_CROP_REGION.
Unfortunately i don't have access to a pixel 6 to test zooming out, only a S21 and pixel 3. Pixels 3 has 2 front cameras but it requires extra multi camera logic described in the docs to switch between them. Hopefully going forward OEM will go the pixel route and switch between cameras based on zoom 🤞.
@Ernovation check your device camera2 ids using the Camera2Test. My S21 exposes 4 ids : main back, ultra wide, main front and main front but a bit wider, even though the phone has an extra telephoto which is hidden.