Android Front Camera录制视频但播放颠倒......!

问题描述 投票:1回答:3

我设法创建一个Android应用程序来录制视频,但问题是前置摄像头视频的方向。输出不符合要求。它会自动旋转。

应用方向是景观。因此,我需要在横向模式下使用前凸轮进行录制。

什么都没有成功。

android orientation android-camera landscape screen-rotation
3个回答
2
投票

您可能想看看AOSP VideoCamera activity是如何实现这一点的:

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

my answer for another question here中有更多细节。


1
投票

在setAudioSource下方开始录制视频时添加此项

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);用于前置摄像头倒置问题


0
投票

检查摄像机ID,如果为1,则按照媒体播放器“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);
}

然后在媒体播放器预览中准备方法为:

if(cameraId == FRONT_CAMERA) {
     mMediaRecorder.setOrientationHint(REAR_ORIENTATIONS.get(rotation));
}
© www.soinside.com 2019 - 2024. All rights reserved.