Similar to this question, I'm trying to change parameters of the android camera after calling startPreview(). I'm processing video input frame by frame from the preview and need to adjust exposure settings in real time. lock() doesn't seem to be helpful and stopping the preview doesn't work at frame rate. However, just like the linked question has pointed out, once startPreview() is called, none of the param changes seem to go through to the camera.
In case it's relevant, I'm doing this on Google Glass... but that shouldn't make a difference.
Related
I want to capture video without showing a preview. The android docs here say this is possible, but don't explain how:
http://developer.android.com/guide/topics/media/camera.html#capture-video
Note: It is possible to use MediaRecorder without creating a camera preview first and skip the first few steps of this process. However, since users typically prefer to see a preview before starting a recording, that process is not discussed here.
what are the "first few steps" to skip?
Thank you
You misinterpret the documentation. What it really says (emphasis mine):
It is possible to use MediaRecorder without creating a camera preview first and skip the first few steps of this process. However, since users typically prefer to see a preview before starting a recording, that process is not discussed here.
In other words, you can create a preview and immediately start recording. There is no hint that MediaRecorder will let you run a hidden recording session.
Moreover, I agree with the document that the added value of not starting preview before starting recording, is negligible.
You can just skip step 5 of configuring media recorder given in the above link and preview wont be shown. But user will be interested in viewing its preview.
Even though the documentation states it is possible, most of SO answers say otherwise. Take a look at this answer (and the answers linked in it).
The work around this limitation is to create a 1 x 1 px SurfaceView and use it to display the camera preview.
i am trying to change camera2 basic example so camera starts showing preview on FACING_FRONT, but in that case snapshot stops working.
Here is a link to the example:
https://github.com/pinguo-yuyidong/Camera2/blob/master/camera2/src/main/java/us/yydcdut/camera2
I am sure, that besides cameraId change i need a lot more additional changes, but i couldn't find what else.
Many front-facing cameras are fixed-focus, so autofocus (AF) state remains INACTIVE, and the AF trigger does nothing.
You need to check if the camera actually supports focusing, and if not, don't use the AF trigger or wait for AF state to change.
To check if the camera supports focusing, look at http://developer.android.com/reference/android/hardware/camera2/CameraCharacteristics.html#LENS_INFO_MINIMUM_FOCUS_DISTANCE
I try to create an application allowing me to make video recordings. My problem is that when I use the preview of the camera, the recording is very poor of quality. And without the preview, the quality is perfect.
Can anyone explain this result?
To display the preview of the camera, I call this method : camera.setPreviewDisplay(holder);
To better explain my problem, I make screenshots of the result :
In case A, I call the method camera.setPreviewDisplay(holder);
In case B, I delete the method
NOTE: To download my project, click HERE.
I had exactly the same problem (but using back camera). I was showing the preview from the camera, but when I started recording (after using setCamera), no matter what I tried, I either ended up with really poor quality, crashing or freezing.
I explained my solution over here: https://stackoverflow.com/a/26098734/1135847
Following camera2basic guide on Android L preview page, I am able to capture normal images, i.e. without flash or using auto-focus mechanism (I rely on passive focus)
However, I would like to take a flash image. The documentation states before taking flash image, I should call android.control.aePrecaptureTrigger to determine correct exposure.
My question:
How can I call AE Precapture trigger, wait for it to complete and then take the image using capture(CaptureRequest, CameraCaptureSession.CaptureListener, Handler)?
Method I've already tried:
After user clicks capture image button, I start a preview
Set CONTROL_AE_PRECAPTURE_TRIGGER to CONTROL_AE_PRECAPTURE_TRIGGER_START
Monitor AE_STATE result in CaptureListener's onCaptureCompleted method
When AE_STATE converges, I set AE lock and take image using capture() method
However, the flash image is still over-exposed and sometimes, I get complete garbage image.
Has anyone able to get this working?
Once this is working, auto-focus mechanism can be used in similar fashion.
Thanks
Thanks for trying out the new camera2 API!
You shouldn't need to lock AE; once you see AE_STATE as CONVERGED (or FLASH_REQUIRED), submit the still capture request.
Things to verify:
Is your AE_MODE either ON_AUTO_FLASH or ON_ALWAYS_FLASH for both the preview and the still capture requests? If not, the metering routines won't be controlling flash power or firing correctly. The still capture and preview templates may just have AE mode set to ON, which means the flash won't be fired under AE control.
Are you using CAPTURE_INTENT_STILL_PICTURE for the still capture? If not, the flash won't be fired by the automatics. This is automatically set for TEMPLATE_STILL_CAPTURE.
If you're seeing garbage images, please feel free to file a bug on our Android AOSP tracker:
http://b.android.com
Detailing the set of outputs you have for your session would be especially helpful, since we know there are some current bugs for certain output Surface sets.
I am not sure you got answer or not. I just figure it out as follows:
First I did for capturebuilder
captureBuilder.set(CaptureRequest.CONTROL_MODE,
CameraMetadata.CONTROL_MODE_AUTO);
captureBuilder.set(CaptureRequest.FLASH_MODE,
CameraMetadata.FLASH_MODE_TORCH);
I set both because I think that flash can be able to take while auto mode.
But the result is can't get flash image when capture.
Now I get flash image after I set boolean value for flash on/off.
if (isFlashOn)
captureBuilder.set(CaptureRequest.FLASH_MODE,
CameraMetadata.FLASH_MODE_SINGLE);
else
captureBuilder.set(CaptureRequest.CONTROL_MODE,
CameraMetadata.CONTROL_MODE_AUTO);
when I make a call to mCamera.takePicture(null, null, null, null); (for simplicity I have omitted the callbacks) the preview freezes and shows a preview of the scene that was just captured. Why is that the case. Can I somehow control this behaviour? And, what does actually happen? Is there a new view that gets attached or does my camera preview simple stop?
What does actually happen? Is there a new view that gets attached or does my camera preview simply stop?
No new view gets attached by default. The preview just stops. The documentation for Camera states this clearly:
Preview will be stopped after the image is taken; callers must call startPreview() again if they want to re-start preview or take more pictures.
It also goes on to say:
After calling this method, you must not call startPreview() or take another picture until the JPEG callback has returned.
So, the best place to call startPreview() again would be the JPEG callback. Any time before that, the camera hardware is still processing the previous image, and wouldn't be able to give you a preview. That's the main reason that it "freezes"; the camera hardware is just busy.
It's also a visual cue to the user that:
a picture was taken
the picture looks like "this"
That's icing on the cake, but even if you didn't care about that, it would still do it.
Can I somehow control this behaviour?
Through the publicly expose API? Definitely not. You can restart the preview once the camera is done processing(as above), but you can't prevent it from freeze-framing when you call takePicture().
Whether it's possible by going further into the camera firmware, I can't really say. However, since there are roughly a bazillion different cameras used in Android devices, this would likely be an exercise in futility if you weren't working on one specific device.
Even with one specific device, I can't see how you'd overcome it altogether. At a bare minimum, the camera will be busy processing the image for some amount of time. Even high-end DSLR cameras that I've seen freeze the preview at least for the duration of the exposure.
After calling takePicture() you can hide the preview surface under another view (e.g. ImageView). If you use OpenGL to render the preview texture instead of SurfaceView, you have even more tricks in your sleeve.