高速捕获请求Android Marshmallow

时间:2016-01-27 21:18:22

标签: android android-camera

我在设置高速视频捕获请求时遇到了一些问题。我打算在Nexus 6P上以120 FPS拍摄。我将最低API设置为23,因为我不打算将此应用部署到任何其他手机。

我不太了解如何让我的捕获请求工作。现在,我正在尽力改变谷歌样本中Camera2Video样本中的代码。 Link to sample from Google

以下是所有相关代码:

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);

}

我将代码更新到预览没有问题。不幸的是,从那里开始,我遇到了如何为setRepeatingBurst提供捕获请求的障碍。我知道构造函数与示例的setRepeatingRequest不同。因此,我需要找到一种方法来为我的表面,我的CONTROL_MODE请求和我的TARGET_FPS_RANGE请求提供setRepeatingBurst。

/**
 * 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;

任何有助于确定如何正确工作的帮助都会非常有帮助。我没有在网上找到太多帮助,而且StackOverflow中没有任何文章提到任何高速捕获功能。这里我最大的问题是试图理解createConstrainedHighSpeedCaptureSession如何给出CameraConstrainedHighSpeedCaptureSession会话。这样我就可以使用createHighSpeedRequestList。

1 个答案:

答案 0 :(得分:2)

我有类似的问题,但是使用你的问题解决了它。

在你的情况下,我认为如果你打电话

它应该有用
mPreviewSession.setRepeatingBurst(mPreviewBuilder2, null, mBackgroundHandler);

而不是

{{1}}

因为您正在CameraConstrainedHighSpeedCaptureSession上设置RepeatingBurst

我创建了一个github存储库,展示了如何使用camera2 api创建高速录制会话。

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