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.
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With