How to lock exposure?
Hi.
I am using Camera2Source and GenericStream, latest library version (2.6.2).
As the title says, I want to lock the exposure (like on the default camera app of the device).
How can I do that?
I tried disableAutoExposure() but it didn't work (On API 35, it turned black. On API 29, it turned dark orange).
Thank you.
Hello,
You can try use an exposure value instead of that. Try with:
source.setExposure(source.getExposure())
Hi. I tried it but it only changes at that position, when I move the camera back and forth it still jumps in brightness, not fixed like the default camera app of the device.
This is the exposure compensation lock feature of the default camera app on the Samsung S22 Ultra phone and it works well, as expected.
I found this code, it might work, but I don't know how to use it when integrating your library. Can you help me?
// Assuming you have a CaptureRequest.Builder instance, e.g., for preview
// previewRequestBuilder: CaptureRequest.Builder
// cameraCaptureSession: CameraCaptureSession
// To lock exposure:
previewRequestBuilder.set(CaptureRequest.CONTROL_AE_LOCK, true)
cameraCaptureSession.setRepeatingRequest(previewRequestBuilder.build(), captureCallback, backgroundHandler)
// To unlock exposure (allow auto-exposure to resume):
previewRequestBuilder.set(CaptureRequest.CONTROL_AE_LOCK, false)
cameraCaptureSession.setRepeatingRequest(previewRequestBuilder.build(), captureCallback, backgroundHandler)
@pedroSG94 Can you hepl me ? I really need it :-(
Hello,
I did a branch for it. Can you try this gradle and let me know if it is working for you?
implementation 'com.github.pedroSG94.RootEncoder:library:25aba37e36'
//Optional, allow use CameraXSource and CameraUvcSource
implementation 'com.github.pedroSG94.RootEncoder:extra-sources:25aba37e36'
Usage:
camera2Source.lockExposure(true) // enable, return true if success
camera2Source.lockExposure(false) // disable, return true if success
camera2Source.isLockExposureEnabled() // check status
If all is working fine. I will upload this in the next version.
Hi @pedroSG94 I tried it but it doesn't seem to work.
Try call enableAutoExposure first and confirm that you have a return true in the methods. You must call this methods after start the camera (when you have the preview or streaming running)
Hi @pedroSG94
Yes, I tried it and the status check when calling the functions is correct. Here is the log I printed out to check the status:
10:20:37.120 Loggers *** E Check_Exposure: enableAutoExposure: true
10:20:37.121 Loggers *** E Check_Exposure: isLockExposureEnabled: false
10:20:41.033 Loggers *** E Check_Exposure: lockExposure: true
10:20:41.033 Loggers *** E Check_Exposure: isLockExposureEnabled: true
Try call enableAutoExposure first and confirm that you have a return true in the methods. You must call this methods after start the camera (when you have the preview or streaming running)
Hi @pedroSG94 Do you have any updates on this issue? I think it's quite important and necessary for livestreaming as well as recording. With the default camera application of the device, I can completely do that, but with the above commit and the current version (2.7.5) still can't do that locking.
If you don't have time to do that or haven't found a solution, you can write the following function so I can check it myself ? (add in Camera2ApiManager class and can call it in Camera2Source class).
I really need this quite urgently right now, I hope you can reply soon. Thank u so much.
/**
* Applies a series of settings to a CaptureRequest.Builder.
*
* @param settings A Map containing the CaptureRequest.Key and their corresponding values.
*/
fun applyCustomCaptureRequestSettings(settings: Map<CaptureRequest.Key<*>, Any?>) {
// Iterate through each key-value pair in the map
val builderInputSurface = this.builderInputSurface ?: return
for ((key, value) in settings) {
try {
builderInputSurface.set(key, value)
applyRequest(builderInputSurface)
} catch (e: Exception) {
// Log an error if the value's data type does not match the type required by the key
// This makes debugging easier
Log.e(TAG, "Apply custom capture setting error for key: ${key.name}, and value: '$value'.", e)
}
}
}
Hello,
Currently I'm on holidays so I'm not in my home. This will have to wait until next week. You can download the project and add it yourself to test. Also, you can create your own Camera2ApiManager class and Camera2Source class (coping original classes) and use it to extend functionality.