Android Front Camera recording video but plays upside down…!

浪子不回头ぞ 提交于 2019-12-23 02:39:48

问题


I have managed to create an android application to record videos but the problem is with the orientation of front camera video . The output is not the as per requirements . It gets automatically rotated .

Application orientation is landscape . So, I need to record using front cam in landscape mode.

Nothing is working out .


回答1:


You might want to look at how the AOSP VideoCamera activity is implementing this:

    if (info.facing == CameraInfo.CAMERA_FACING_FRONT) {
        rotation = (info.orientation - mOrientation + 360) % 360;
    } else {  // back-facing camera
        rotation = (info.orientation + mOrientation) % 360;
    }

There are some more details in my answer for another question here.




回答2:


Add this where you start you video recording below setVideoSource

mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
if (cameraId == 1) {
    mediaRecorder.setProfile(CamcorderProfile
        .get(CamcorderProfile.QUALITY_LOW));
    mediaRecorder.setOrientationHint(270);
} else if (cameraId == 0) {
    mediaRecorder.setProfile(CamcorderProfile
        .get(CamcorderProfile.QUALITY_HIGH));
    mediaRecorder.setOrientationHint(orientation);
}

mediaRecorder.setOrientationHint(270); is for front camera upside down issue




回答3:


Check the camera ID, if it is 1 then follow the orientation change for media player "setOrientationHit()

private static final SparseIntArray REAR_ORIENTATIONS = new SparseIntArray();
static {
    REAR_ORIENTATIONS.append(Surface.ROTATION_0, 270);
    REAR_ORIENTATIONS.append(Surface.ROTATION_90, 0);
    REAR_ORIENTATIONS.append(Surface.ROTATION_180, 90);
    REAR_ORIENTATIONS.append(Surface.ROTATION_270, 180);
}

Then in media player preview preparing methods as :

if(cameraId == FRONT_CAMERA) {
     mMediaRecorder.setOrientationHint(REAR_ORIENTATIONS.get(rotation));
}


来源:https://stackoverflow.com/questions/12916280/android-front-camera-recording-video-but-plays-upside-down

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!