2

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 .

Nishant Mendiratta
  • 760
  • 13
  • 25

3 Answers3

3

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.

Joe
  • 14,039
  • 2
  • 39
  • 49
  • im trying to use `mrec.setOrientationHint(0);` in `private void startRecording()` function but it dosen't allow me to start the video – Nishant Mendiratta Oct 16 '12 at 17:07
  • what is mOrientation?? and could you provide the full code? i am trying to reslove it from past two days – Rahul Khurana Jul 07 '17 at 06:34
  • 1
    @RahulKhurana, I updated the stale omapzoom link to androidxref so you can look at the full code. – Joe Jul 09 '17 at 13:53
  • Hi thanks for your code but i ended up with [afollestad's material-camera](https://www.github.com/afollestad/material-camera) library on github, because i was getting late but i will surely look into your code – Rahul Khurana Jul 10 '17 at 03:40
1

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

Dovydas Šopa
  • 2,282
  • 8
  • 26
  • 34
0

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));
}
Sampath Kumar
  • 4,433
  • 2
  • 27
  • 42