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.