I am trying to record a video in portrait orientation.
Setting the Camera DisplayOrientation to 90 degrees makes the preview to video be displayed in portrait.
But When calling setOrientationHint() with any given number(0,90,180,270) the video that was created is created always in portrait orientation.
When I have tested it on Jellybean and on ICS, the video orientation was the one I set with the setOrientationHint() method.
Here is the MediaRecorder initialization code:
private void initRecorder() {
Camera camera = Camera.open();
camera.setDisplayOrientation(90);
camera.unlock();
recorder.reset();
recorder.setCamera(camera);
recorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
recorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
recorder.setVideoEncoder(MediaRecorder.VideoEncoder.MPEG_4_SP);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
file = new File("/sdcard/test.mp4");
if (!file.exists()) {
try {
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
recorder.setOrientationHint(90);//doesn't seem to work on 2.3
recorder.setOutputFile(file.getAbsolutePath());
recorder.setMaxDuration(30000);
recorder.setMaxFileSize(1000000);
}
And this is where I prepare the MediaRecorder:
public void surfaceCreated(SurfaceHolder holder) {
this.holder = holder;
recorder.setPreviewDisplay(holder.getSurface());
try {
recorder.prepare();
} catch (IllegalStateException e) {
e.printStackTrace();
finish();
} catch (IOException e) {
e.printStackTrace();
finish();
}
}
EDIT:
Tested on:
Samsung Galaxy S running android 2.2.
Samsung Galaxy W running android 2.3.
Samsung galaxy S2 running ICS - worked.
Samsung galaxy s3 running Jelly Bean - worked.