Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recorded video is 90 degree rotated after uploading to Internet

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.

like image 580
Iam619 Avatar asked Aug 23 '12 18:08

Iam619


People also ask

How do I rotate a video on my phone?

Locate your video and tap it to begin playback. While the video plays, tap the screen once to bring up the options menu, then tap Edit. Scroll through the options at the bottom and tap Crop. In the Crop section, tap the middle rotate icon to rotate the video—repeat this until the video is rotated to the right position.

How do you fix an upside down video on Android?

Open Google Photos on your Android phone and tap the search bar. Choose Videos, then select the video you want to rotate. Tap the slider bar icon (it's at the bottom of the screen in the middle). Select Rotate until the video is oriented the way you want it.

Can you turn a video?

First, find the video that you'd like to rotate. Next, tap the screen to bring up the controls—if they aren't already visible—and tap “Edit.” Switch over to the “Crop” tab in the bottom toolbar. Now tap the rotate icon until the video is in your desired orientation.


2 Answers

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.

like image 136
Vishesh Kamdar Avatar answered Sep 28 '22 02:09

Vishesh Kamdar


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.

like image 27
Rafael Lima Avatar answered Sep 28 '22 04:09

Rafael Lima