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 .
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.
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
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