Reputation: 3971
I'm attempting to stream video using MediaRecorder on Android with the screen fixed to portrait mode (android:screenOrientation="portrait"). The camera hardware is naturally aligned to landscape mode. I can rotate the preview video display 90 degrees so the local preview displays correctly in portrait mode. However the captured video is still 90 degrees out:
Camera mCamera;
MediaRecorder mMediaRecorder;
...
mCamera.setDisplayOrientation(90);
mCamera.setPreviewDisplay(holder);
mCamera.startPreview();
Parameters params = mCamera.getParameters();
params.setRotation(90);
mCamera.setParameters(params);
mCamera.unlock();
mMediaRecorder.setCamera(mCamera);
The params.setRotation seems to have no effect whatsoever on the captured video. My target API is Android 2.2. My test hardware is Android 3.1.
Any ideas on how to rotate the captured video? Or is it not even possible?
Upvotes: 0
Views: 3488
Reputation: 7976
I know your issue,
Video use Media Recorder
from Camera
, so you need rotate Media Recorder
. use below codes should be fixed your issue.
/**
*
* @param mMediaRecorder
* @return
*/
public static MediaRecorder rotateBackVideo(MediaRecorder mMediaRecorder) {
/**
* Define Orientation of video in here,
* if in portrait mode, use value = 90,
* if in landscape mode, use value = 0
*/
switch (CustomCamera.current_orientation) {
case 0:
mMediaRecorder.setOrientationHint(90);
break;
case 90:
mMediaRecorder.setOrientationHint(180);
break;
case 180:
mMediaRecorder.setOrientationHint(270);
break;
case 270:
mMediaRecorder.setOrientationHint(0);
break;
}
return mMediaRecorder;
}
Should add before prepare()
method :
// Step 5: Set the preview output
/**
* Define Orientation of image in here,
* if in portrait mode, use value = 90,
* if in landscape mode, use value = 0
*/
CustomCamera.mMediaRecorder = Utils.rotateBackVideo(CustomCamera.mMediaRecorder);
CustomCamera.mMediaRecorder.setPreviewDisplay(mCameraPreview.getHolder().getSurface());
Thank you
Upvotes: 1
Reputation: 91
Try using this:
mediaRecorder.setOrientationHint(rotation); // eg rotation=270
Upvotes: 2