JParrish88
JParrish88

Reputation: 597

High speed Capture request Android Marshmallow

I'm having some issues setting up a capture request for high speed video. I intend to capture at 120 FPS on Nexus 6P. I set the minimum API to 23, since I don't plan to deploy this app to any other phone.

Where I'm not quite understanding is how to get my capture request to work. Right now, I'm doing my best to change up the code within Camera2Video sample in google's samples. Link to sample from Google

Here is all of the relevant code:

private void startPreview() {
    if (null == mCameraDevice || !mTextureView.isAvailable() || null == mPreviewSize) {
        return;
    }
    try {
        setUpMediaRecorder();
        SurfaceTexture texture = mTextureView.getSurfaceTexture();
        assert texture != null;
        texture.setDefaultBufferSize(mPreviewSize.getWidth(), mPreviewSize.getHeight());
        mPreviewBuilder = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_RECORD);
        List<Surface> surfaces = new ArrayList<Surface>();

        Surface previewSurface = new Surface(texture);
        surfaces.add(previewSurface);
        mPreviewBuilder.addTarget(previewSurface);

        Surface recorderSurface = mMediaRecorder.getSurface();
        surfaces.add(recorderSurface);
        mPreviewBuilder.addTarget(recorderSurface);

        mCameraDevice.createConstrainedHighSpeedCaptureSession(surfaces, new CameraCaptureSession.StateCallback() {
        //mCameraDevice.createCaptureSession(surfaces, new CameraCaptureSession.StateCallback() {

            @Override
            public void onConfigured(CameraCaptureSession cameraCaptureSession) {
                //mPreviewSession = cameraCaptureSession;
                mPreviewSession2 = cameraCaptureSession;
                updatePreview();
            }

            @Override
            public void onConfigureFailed(CameraCaptureSession cameraCaptureSession) {
                Activity activity = getActivity();
                if (null != activity) {
                    Toast.makeText(activity, "Failed", Toast.LENGTH_SHORT).show();
                }
            }
        }, mBackgroundHandler);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}


/**
 * Update the camera preview. {@link #startPreview()} needs to be called in advance.
 */
private void updatePreview() {
    if (null == mCameraDevice) {
        return;
    }
    try {
        setUpCaptureRequestBuilder(mPreviewBuilder);
        HandlerThread thread = new HandlerThread("CameraPreview");
        thread.start();
        mPreviewBuilder2 =  mPreviewSession2.createHighSpeedRequestList(mPreviewBuilder.build());
        //mPreviewBuilder2 =


        //mPreviewSession.setRepeatingRequest(mPreviewBuilder.build(), null, mBackgroundHandler);
        mPreviewSession.setRepeatingBurst(mPreviewBuilder2, null, mBackgroundHandler);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch(Exception e){
        e.printStackTrace();
    }
}

private void setUpCaptureRequestBuilder(CaptureRequest.Builder builder) {
    builder.set(CaptureRequest.CONTROL_MODE, CameraMetadata.CONTROL_MODE_AUTO);
    Range<Integer> fpsRange = Range.create(120, 120);
    builder.set(CaptureRequest.CONTROL_AE_TARGET_FPS_RANGE, fpsRange);

}

I have no problem getting the code to updatepreview. Unfortunately, from there I've hit a roadblock on how to give setRepeatingBurst my capture requests. I know the constructor is different from the sample's setRepeatingRequest. Therefore, I need to find a way to give setRepeatingBurst my surfaces, my CONTROL_MODE request and my TARGET_FPS_RANGE request.

/**
 * Camera preview.
 */
private CaptureRequest.Builder mPreviewBuilder;
List<CaptureRequest> mPreviewBuilder2;

/**
 * A reference to the current {@link android.hardware.camera2.CameraCaptureSession} for
 * preview.
 */
private CameraCaptureSession mPreviewSession;
private CameraConstrainedHighSpeedCaptureSession mPreviewSession2;

Any help figuring out how to make this work correctly would be very helpful. I haven't found much on the net in order to help and there isn't any article in StackOverflow mentioning any of the highspeed capture functions. My largest issue here is trying to understand how createConstrainedHighSpeedCaptureSession gives a CameraConstrainedHighSpeedCaptureSession session. So that I can use the createHighSpeedRequestList.

Upvotes: 5

Views: 6163

Answers (1)

sleort
sleort

Reputation: 193

I had a similar problem, but solved it using your question.

In your case I think it should work if you call

mPreviewSession2.setRepeatingBurst(mPreviewBuilder2, null, mBackgroundHandler);

instead of

mPreviewSession.setRepeatingBurst(mPreviewBuilder2, null, mBackgroundHandler);

since you are then setting the RepeatingBurst on the CameraConstrainedHighSpeedCaptureSession


I made a github repository showing how to create a highspeed recording session using camera2 api.

https://github.com/thesleort/Android-Slow-Motion-Camera2.git

Upvotes: 4

Related Questions