Reputation: 795
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.
Upvotes: 18
Views: 2946
Reputation: 41
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.
Upvotes: 4
Reputation: 41
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.
Upvotes: 3