Skip to content

Commit e552d95

Browse files
committed
Rotated video on inversed sensors bug fix
1 parent 5524e8b commit e552d95

1 file changed

Lines changed: 32 additions & 1 deletion

File tree

camerakit/src/main/api16/com/flurgle/camerakit/Camera1.java

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
import android.os.Handler;
1010
import android.util.Log;
1111
import android.support.annotation.Nullable;
12+
import android.util.SparseIntArray;
1213
import android.view.MotionEvent;
14+
import android.view.Surface;
1315
import android.view.SurfaceHolder;
1416
import android.view.View;
1517

@@ -49,6 +51,27 @@ public class Camera1 extends CameraImpl {
4951
private Camera.AutoFocusCallback mAutofocusCallback;
5052
private boolean capturingImage = false;
5153

54+
55+
private static final int SENSOR_ORIENTATION_DEFAULT_DEGREES = 90;
56+
private static final int SENSOR_ORIENTATION_INVERSE_DEGREES = 270;
57+
private static final SparseIntArray DEFAULT_ORIENTATIONS = new SparseIntArray();
58+
private static final SparseIntArray INVERSE_ORIENTATIONS = new SparseIntArray();
59+
60+
static {
61+
DEFAULT_ORIENTATIONS.append(Surface.ROTATION_0, 90);
62+
DEFAULT_ORIENTATIONS.append(Surface.ROTATION_90, 0);
63+
DEFAULT_ORIENTATIONS.append(Surface.ROTATION_180, 270);
64+
DEFAULT_ORIENTATIONS.append(Surface.ROTATION_270, 180);
65+
}
66+
67+
static {
68+
INVERSE_ORIENTATIONS.append(Surface.ROTATION_0, 270);
69+
INVERSE_ORIENTATIONS.append(Surface.ROTATION_90, 180);
70+
INVERSE_ORIENTATIONS.append(Surface.ROTATION_180, 90);
71+
INVERSE_ORIENTATIONS.append(Surface.ROTATION_270, 0);
72+
73+
}
74+
5275
private int mDisplayOrientation;
5376

5477
@Facing
@@ -492,8 +515,16 @@ private void initMediaRecorder() {
492515

493516
mVideoFile = new File(mPreview.getView().getContext().getExternalFilesDir(null), "video.mp4");
494517
mMediaRecorder.setOutputFile(mVideoFile.getAbsolutePath());
495-
mMediaRecorder.setOrientationHint(calculatePreviewRotation());
496518
mMediaRecorder.setVideoSize(mCaptureSize.getWidth(), mCaptureSize.getHeight());
519+
520+
switch (mCameraInfo.orientation) {
521+
case SENSOR_ORIENTATION_DEFAULT_DEGREES:
522+
mMediaRecorder.setOrientationHint(DEFAULT_ORIENTATIONS.get(mCameraInfo.orientation));
523+
break;
524+
case SENSOR_ORIENTATION_INVERSE_DEGREES:
525+
mMediaRecorder.setOrientationHint(INVERSE_ORIENTATIONS.get(mCameraInfo.orientation));
526+
break;
527+
}
497528
}
498529

499530
public void setProfile(CamcorderProfile profile, boolean audioEnabled) {

0 commit comments

Comments
 (0)