4

My app provides a camera, which allows user to either take a picture or record a video. I have no possibility to know which action user is going to choose. So I need to provide camera preview for both actions. With old camera API there was no problem at all, but I'm not sure about camera2 API.

I have thoroughly looked through both Google examples: Camera2Basic and Camera2Video, and I noticed that for taking pictures the preview builder uses CameraDevice.TEMPLATE_PREVIEW:

mPreviewRequestBuilder = mCameraDevice.createCaptureRequesT(CameraDevice.TEMPLATE_PREVIEW);

For Video recording it uses CameraDevice.TEMPLATE_RECORD;

mPreviewBuilder = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_RECORD);

I have checked the descriptions for all templates in CameraDevice class, but still am not sure what is the right way in my case. I have tried to set TEMPLATE_PREVIEW for video recording, and it worked ok, but do I understand it correctly that in this case the quality of the video may be lower? Cause in docs it says the following:

Specifically, this means that high frame rate is given priority over the highest-quality post-processing.

tanya_sv
  • 41
  • 3
  • Did you get any solution ? I asked on SO. Link is : http://stackoverflow.com/questions/36174807/how-to-programmatically-take-photos-while-recording-video-using-camera2-api-in-a I am stuck here. If u have any idea then help me. – Khushbu Shah Mar 23 '16 at 11:16
  • Hello, I am having same problem. I want video and image in same fragment. Can you please share code if possible ? – Hardik Joshi Mar 12 '17 at 17:13

1 Answers1

1

The templates just have default values for the various CaptureRequest settings. Each template is aimed at some specific use case.

But for simplicity, TEMPLATE_PREVIEW for preview before you start recording should be fine; I'd recommend switching to TEMPLATE_RECORD while actually recording. Then switch back to TEMPLATE_PREVIEW once the user stops recording.

Eddy Talvala
  • 17,243
  • 2
  • 42
  • 47
  • Thank you for the answer, but wouldn't changing templates on the fly mess up the actual preview? I mean I need to display the preview in TextureView whilst recording video. – tanya_sv Sep 21 '15 at 09:51
  • 1
    The template just sets defaults for the capture request. Just make sure to add the right target Surfaces, and it'll work fine. – Eddy Talvala Sep 22 '15 at 21:11
  • @EddyTalvala can you please check the next issue. Does video stabilization only works when `TEMPLATED_RECORDING` is used? https://stackoverflow.com/questions/71712448/camera2-api-failed-to-take-photo-when-template-record-is-used-for-preview-and – user924 Apr 04 '22 at 09:58