Jay Kansagara
Jay Kansagara

Reputation: 83

android video orientation change after captureing video

When we will trying to record the video using MediaRecorder video is recorded properly in android and in device it will display as like recording, but when we can play video in VLC or other player in Desktop that time it will rotate the video and it will not display properly. and i can set the MediaRecorder setOrientationHint to 90 degree.

what's the problem for changing the orientation and Why?

Upvotes: 3

Views: 1714

Answers (2)

Jitendra ramoliya
Jitendra ramoliya

Reputation: 69

we Can not directly apply fix orientation while capturing video. I mean to say that you used fix 90 degree orientation in MediaRecorder setOrientationHint. you need to set setOrientationHint(dynamic degree);

First of all you need to get display rotation and get angle using display rotation. after then set That Degree to setOrientationHint method. That will work for all. Here is code.

Display display = getWindowManager().getDefaultDisplay();
int mDisplayRotation = display.getRotation();

public int getDisplayOrientationAngle() {
    Log.e("", "setDisplayOrientationAngle is call");
    int angle;

    // switch (MeasurementNativeActivity.DisplayRotation) {
    switch (mDisplayRotation) {
    case Surface.ROTATION_0: // This is display orientation
        angle = 90; // This is camera orientation
        break;
    case Surface.ROTATION_90:
        angle = 0;
        break;
    case Surface.ROTATION_180:
        angle = 270;
        break;
    case Surface.ROTATION_270:
        angle = 180;
        break;
    default:
        angle = 90;
        break;
    }
    Log.v("", "media recorder displayRotation: " + mDisplayRotation);
    Log.v("", "media recorder angle: " + angle);
    return angle;

}

mMediaRecorder.setOrientationHint(getDisplayOrientationAngle());

Upvotes: 1

Sebastian Ghetu
Sebastian Ghetu

Reputation: 77

Extracted from the Android Documentation for MediaRecorder's setOrientationHint(int degrees) function:

This method will not trigger the source video frame to rotate during video recording, but to add a composition matrix containing the rotation angle in the output video if the output format is OutputFormat.THREE_GPP or OutputFormat.MPEG_4 so that a video player can choose the proper orientation for playback.

To sum it up, setOrientationHint just adds some sort of header to the video file that "tells" video players that they should rotate the video when playing it. In my experience, VLC player ignores this header and plays the video as it was recorded.

The only workaround I can think of would be to post-process the video by rotating it to your needs, although it seems quite a bad decision resource-wise.

Upvotes: 0

Related Questions