Search code examples
androidvideo-captureandroid-mediarecorderandroid-camera2

Nexus 5X records video rotated upside down using MediaRecorder and camera2


I'm facing the problem with recording video by new camera2 api. I'm playing with project from https://github.com/googlesamples/android-Camera2Video which demonstrates video recording using new camera2 api. Recording works well but rotation of recorded mp4 video is different because of different devices.

Nexus 9 result video is fine but Nexus 5X not.

I've heard that Nexus 5X has camera rotated upside down. In this case I would set MediaRecorder flags to record properly but...

My question is, how to recognize programmatically whether device has or doesn't have camera rotated upside down?

Thanks for any help!


Solution

  • I've found the solution...

    CameraManager manager = (CameraManager) activity.getSystemService(Context.CAMERA_SERVICE);
    String cameraId = manager.getCameraIdList()[0];
    CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraId);
    int sensorOrientation = characteristics.get(CameraCharacteristics.SENSOR_ORIENTATION);
    

    sensorOrientation value: Default camera orientation used to be 90 degrees. For Nexus 5X it is 270 degrees.