Search code examples
androidandroid-cameravideo-capturecommonsware-cwac

How to keep cwac video preview aspect ratio consistent between pre and during recording


I'm using the cwac-camera library on android with useFullBleedPreview() == true. When I start recording a video, the aspect ratio of the preview changes. It also stays like that even after I stop recording until I restart/reload the camera fragment.

Is there a way to keep the aspect ratio of the preview consistent between non-recording and recording?

If not, is there a way to set enable/disable the video recording preview aspect ratio before the recording starts? This way I could have a video mode which changes the preview aspect ratio and the user can see in advance what the preview during recording will be.

using version 6.2 of the library


Solution

  • Don't know if this is totally correct but this seems to have solved the problem for me. (Need to test on more devices):

    In the class extending the SimpleCameraHost or implementing CameraHost add the following:

    @Override
    public Camera.Size getPreferredPreviewSizeForVideo(int displayOrientation, int width, int height, Camera.Parameters parameters, Camera.Size deviceHint) {
        return CameraUtils.getOptimalPreviewSize(displayOrientation, width, height, parameters);
    }