Recorded video is 90 degree rotated after uploading to Internet
Asked Answered
U

2

18

I found that recorded video in portrait mode will rotate 90 degree. Thus I used the following code to rotate it when I set the mediaRecorder:

 if (this.getResources().getConfiguration().orientation !=Configuration.ORIENTATION_LANDSCAPE)
{
     mediaRecorder.setOrientationHint(270);
}
 else
{
     mediaRecorder.setOrientationHint(0);
}

mediaRecorder.setOutputFile(file_name);                  
mediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.DEFAULT);
mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);

The preview is also in right orientation since I used the following code in surfaceCreated method:

Camera.Parameters params = camera.getParameters();

if (this.getResources().getConfiguration().orientation
     !=Configuration.ORIENTATION_LANDSCAPE)
{   
  camera.setDisplayOrientation(90);

}
else
{   
  camera.setDisplayOrientation(0);                  
}

  params.setRotation(90);
  camera.setParameters(params);

In this way, the recorded video is in right orientation when played on the device. However the video is still 90 degree rotated after uploading to Internet. Does anyone have advises on this? Thanks a lot.

Undergird answered 23/8, 2012 at 18:45 Comment(4)
Did you find a solution for your problem?Plasterboard
@LazyNinja, I guess not, I have to send the rotated images and change them back later...Undergird
Thanks for your reply. I was facing the same problem and wanted to figure out how to solve it @lam619Plasterboard
Is the issue exist on all devices or for a particular device? If it happening only for a particular device mention the device name please.Vauban
F
4

Use mMediaRecorder.setOrientationHint(int) This definately works. You might need to work the various orientations to get int values for all cameras in potrait and landscape.

Floorer answered 14/8, 2015 at 18:19 Comment(0)
A
3

Some video players considers the orientation hint when playing a video. Other players don't. Just try to play this video in your PC with Windows Media Player, Quick Time and Real Player and see the differences.
Probably the problem is not your code, but the video player you are using to view your video.

Antimissile answered 2/8, 2013 at 15:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.