how to change video orientation in MediaRecorder to portrait

前端 未结 5 1386
孤城傲影
孤城傲影 2020-12-13 19:11

When I record video by MediaRecorder, it always records in landscape mode, regardless of real device orientation. How to force MediaRecorder/Camera use real orientation ?

5条回答
  •  忘掉有多难
    2020-12-13 19:25

    Add the following two lines of code:

    Camera.setDisplayOrientation(90); // use for set the orientation of the preview
    mRecorder.setOrientationHint(90); // use for set the orientation of output video
    

    before:

    mRecorder.setCamera(mCamera);
    

    Full example:

    mRecorder = new MediaRecorder();
    
    // Both are required for Portrait Video
    mCamera.setDisplayOrientation(90);
    mRecorder.setOrientationHint(90);
    
    // Step 1: Unlock and set camera to MediaRecorder
    mCamera.unlock();
    mRecorder.setCamera(mCamera);
    
    // Step 2: Set sources
    mRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
    mRecorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
    
    // Step 3: Set a CamcorderProfile (requires API Level 8 or higher)
    mRecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_480P));
    

提交回复
热议问题