Search code examples
androidandroid-camera2

camera2 createConstrainedHighSpeedCaptureSession on pixel 4a fails


I am trying to capture a high fps video utilizing createConstrainedHighSpeedCaptureSession, the same code runs OK on OnePlus 8T / Honor 10 but does fail on Pixel 4a

startPreview code:

        surfaces.clear();
        SurfaceTexture texture = mTextureView.getSurfaceTexture();
        assert texture != null;

        texture.setDefaultBufferSize(mPreviewSize.getWidth(), mPreviewSize.getHeight());

        mPreviewBuilder = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_RECORD);
        Surface previewSurface = new Surface(texture);

        surfaces.add(previewSurface);
        mPreviewBuilder.addTarget(previewSurface);

        setUpMediaRecorder();
        surfaces.add(mMediaRecorder.getSurface());
        mPreviewBuilder.addTarget(mMediaRecorder.getSurface());
        
        mCameraDevice.createConstrainedHighSpeedCaptureSession(surfaces, new CameraCaptureSession.StateCallback() { ...

the error:

01-11 16:12:22.335 11406 11438 W System.err: java.lang.IllegalArgumentException: Surface size 1841x1036 is not part of the high speed supported size list [1280x720, 1920x1080]
    01-11 16:12:22.336 11406 11438 W System.err:    at android.hardware.camera2.utils.SurfaceUtils.checkConstrainedHighSpeedSurfaces(SurfaceUtils.java:266)
    01-11 16:12:22.336 11406 11438 W System.err:    at android.hardware.camera2.impl.CameraDeviceImpl.createCaptureSessionInternal(CameraDeviceImpl.java:741)
    01-11 16:12:22.336 11406 11438 W System.err:    at android.hardware.camera2.impl.CameraDeviceImpl.createConstrainedHighSpeedCaptureSession(CameraDeviceImpl.java:638)
    01-11 16:12:22.336 11406 11438 W System.err:    at com.revelio.highspeedvideodemo.CaptureHighSpeedVideoModeFragment.startPreview(CaptureHighSpeedVideoModeFragment.java:527)
    01-11 16:12:22.336 11406 11438 W System.err:    at com.revelio.highspeedvideodemo.CaptureHighSpeedVideoModeFragment.access$300(CaptureHighSpeedVideoModeFragment.java:64)
    01-11 16:12:22.336 11406 11438 W System.err:    at com.revelio.highspeedvideodemo.CaptureHighSpeedVideoModeFragment$2.onOpened(CaptureHighSpeedVideoModeFragment.java:190)
    01-11 16:12:22.336 11406 11438 W System.err:    at android.hardware.camera2.impl.CameraDeviceImpl$1.run(CameraDeviceImpl.java:168)
    01-11 16:12:22.336 11406 11438 W System.err:    at android.os.Handler.handleCallback(Handler.java:938)
    01-11 16:12:22.336 11406 11438 W System.err:    at android.os.Handler.dispatchMessage(Handler.java:99)
    01-11 16:12:22.336 11406 11438 W System.err:    at android.os.Looper.loopOnce(Looper.java:201)
    01-11 16:12:22.336 11406 11438 W System.err:    at android.os.Looper.loop(Looper.java:288)
    01-11 16:12:22.336 11406 11438 W System.err:    at android.os.HandlerThread.run(HandlerThread.java:67)

CaptureHighSpeedVideoModeFragment.java:527 is the mCameraDevice.createConstrainedHighSpeedCaptureSession from the code snippet above

I am setting the previewSize and videoSize to 1920x1080, but somehow that is not respected on the Pixel 4a

where does that 1841x1036 resolution come from? why does this code work on other phones but not on the Pixel 4a?

How do I make the preview surface stick with the resolution I want it to stick to?

thanks for any hints


Solution

  • for anyone else that would have the same problem, i solved it by changing the layout from match_parent to fixed resolution, in my case I want full hd so i just set the

    <com.revelio.highspeedvideodemo.AutoFitTextureView
        android:id="@+id/texture"
        android:layout_width="1920px"
        android:layout_height="1080px" />
    

    its not the prettiest solution, but solves my immediate problem

    probably would be better to use a SurfaceView instead of TextureView, but couldn't find any examples how to do that

    as for the answer proposed by Eternal Life - fps is not the problem here, pls see the error that i got, the textureView resolution did not match the createConstrainedHighSpeedCaptureSession supported resolutions even that i was setting it, the only thing that works seams to be the layout fixed resolution ... but thx for trying to help, appreciated