I want to open the `camera` and set the preview on the `SurfaceView` in order to record a video.Once done recording,intent to another activity and set the captured video URI in a `VideoView`.But my problem is,the video orientation is change automatically which is different to the camera preview.

This is the Camera preview(I expect the video capture is appear exactly the same):

[![enter image description here](https://i.stack.imgur.com/aFuVV.png)](https://i.stack.imgur.com/aFuVV.png)

But end up the video captured appear like below: 

[![enter image description here](https://i.stack.imgur.com/TInDE.png)](https://i.stack.imgur.com/TInDE.png)

As you can see,the video is appear in Landscape mode,while the preview is in Portrait mode.

**Here is my code for `surfaceCreated` when open `Camera`**

```
@Override
public void surfaceCreated(SurfaceHolder holder) {
    releaseCamera();
    cameraId = Camera.CameraInfo.CAMERA_FACING_BACK;
    try{
        mCamera = Camera.open(cameraId);
    }catch (RuntimeException ex){
        ex.printStackTrace();
    }

    Camera.Parameters parameters;
    parameters = mCamera.getParameters();

    List<Camera.Size> mSupportedPreviewSizes = parameters.getSupportedPreviewSizes();
    List<Camera.Size> mSupportedVideoSizes = parameters.getSupportedVideoSizes();
    optimalSize = getOptimalVideoSize(mSupportedVideoSizes,
            mSupportedPreviewSizes, videoSurface.getWidth(), videoSurface.getHeight());

    CamcorderProfile profile = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH);
    profile.videoFrameWidth = optimalSize.width;
    profile.videoFrameHeight = optimalSize.height;

    parameters.setPreviewFrameRate(20);
    parameters.setPreviewSize(profile.videoFrameWidth,profile.videoFrameHeight);
    mCamera.setParameters(parameters);
    mCamera.setDisplayOrientation(90);

    try{
        mCamera.setPreviewDisplay(surfaceHolder);
        mCamera.startPreview();
        inPreview = true;
    }catch (Exception e){
        e.printStackTrace();
    }
}

```

Here is how I prepare the video recorder: 

```
private boolean prepareRecorder(){

        //# Create a new instance of MediaRecorder
        mRecorder = new MediaRecorder();
        mCamera.unlock();
        mRecorder.setCamera(mCamera);
        mRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
        mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
        mRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);

        //# Video settings
        mRecorder.setVideoSize(1920,1280);
        mRecorder.setVideoFrameRate(30);
        mRecorder.setVideoEncodingBitRate(3000000);
        mRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);

        //# Audio settings
        mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
        mRecorder.setAudioEncodingBitRate(16);
        mRecorder.setAudioSamplingRate(44100);

        //Max duration 30 seconds
        mRecorder.setMaxDuration(30000);

        //set preview display
        mRecorder.setPreviewDisplay(surfaceHolder.getSurface());

        //set the ouput of the Mp4 file
        MediaFileHelper mediaFileHelper = new MediaFileHelper();
        outputFile =mediaFileHelper.getOutputVideoFile();
        mRecorder.setOutputFile(outputFile.getAbsolutePath());

        try{
            mRecorder.prepare();
        } catch (IOException e) {
            Log.d(TAG, "IOException preparing MediaRecorder: " + e.getMessage());
            releaseMediaRecorder();
            return false;
        }catch (IllegalStateException e){
            Log.d(TAG, "IllegalStateException preparing MediaRecorder: " + e.getMessage());
            releaseMediaRecorder();
            return false;
        }
        return true;
    }

```

So my question is: 

1) What is the problem causing the Video captured's orientation rotate 180 degree?

2) How can I take the video which orientation is same as the Camera Preview in the surface view?

Thanks in advance.