How to find the image cropping percentage when using CONTROL_VIDEO_STABILIZATION_MODE_ON?

176 views Asked by At

I am recording video using MediaRecorder. With CONTROL_VIDEO_STABILIZATION_MODE_OFF the entire camera image is visible on my surface view, however when I set CONTROL_VIDEO_STABILIZATION_MODE_ON the video and preview appear to be cropped slightly.

I would like to know the cropping amount so I can find the actual zoom level.

The value of CaptureRequest.CONTROL_ZOOM_RATIO does not change when stabilization is on or off.

Is it possible to find the amount of horizontal and vertical image cropping for the active stabilization mode?

Or are there any alternatives to CONTROL_ZOOM_RATIO that take into account the amount of cropping added by the image stabilization?

--

I am not sure if SCALER_CROP_REGION is adjusted when enabling stabilization:

Rect zoomCrop = mCaptureRequestBuilder.get(CaptureRequest.SCALER_CROP_REGION);
Log.d(TAG, "ZOOM_1: " + zoomCrop);
   
mCaptureRequestBuilder.set(CaptureRequest.CONTROL_VIDEO_STABILIZATION_MODE, CameraMetadata.CONTROL_VIDEO_STABILIZATION_MODE_ON);
mCaptureRequestBuilder.set(CaptureRequest.LENS_OPTICAL_STABILIZATION_MODE, CameraMetadata.LENS_OPTICAL_STABILIZATION_MODE_ON);

Rect zoomCrop2 = mCaptureRequestBuilder.get(CaptureRequest.SCALER_CROP_REGION);
Log.d(TAG, "ZOOM_2: " + zoomCrop2);

Both print the same:

ZOOM_1: Rect(0, 0 - 4032, 3024)

ZOOM_2: Rect(0, 0 - 4032, 3024)

I also tried printing the results after camera initialization:

surfaceCaptureCallback = new CameraCaptureSession.CaptureCallback() {
    @Override
    public void onCaptureStarted(CameraCaptureSession session, CaptureRequest request, long timestamp, long frameNumber) {
        super.onCaptureStarted(session, request, timestamp, frameNumber);

        Rect zoomCrop = mCaptureRequestBuilder.get(CaptureRequest.SCALER_CROP_REGION);
        Log.d(TAG, "ZOOM: " + zoomCrop);

Prints:

ZOOM: Rect(0, 0 - 4032, 3024)

I see the video from the camera is still being cropped if image stabilization is enabled. But the SCALER_CROP_REGION values are not changing.

I have tried setting a cropping value using SCALER_CROP_REGION, this further increases the apparent zoom of the image and seems to add to the image stabilization cropping, however the values in SCALER_CROP_REGION print the same values that I set. Still I can see slight additional cropping from the stabilization.

I'm just not sure how to find the total cropping being applied to the output video.

1

There are 1 answers

3
Wasim Ansari On

As per documentation, "If enabled, video stabilization can modify the android.scaler.cropRegion to keep the video stream stabilized."

Try checking SCALER_CROP_REGION before and after VDIS.