Orientation Issue while video recording in Portrait Mode android grafika
Asked Answered
A

1

3

I set the device Orientation Landscape mode then it saves the video perfectly. if I capture a video with both sides.

But I set the device orientation Portrait Mode this work weird.

For Example:

Below Screenshot while i Recording video :

But when i save the video and see in MXPlayer then it's look like this:

I use below code :

Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay();

        if (display.getRotation() == Surface.ROTATION_0) {
            mCamera.setDisplayOrientation(90);
            //  layout.setAspectRatio((double) cameraPreviewSize.height / cameraPreviewSize.width);
        } else if (display.getRotation() == Surface.ROTATION_270) {
            // layout.setAspectRatio((double) cameraPreviewSize.height / cameraPreviewSize.width);
            mCamera.setDisplayOrientation(180);
        } else {
            // Set the preview aspect ratio.
            //layout.setAspectRatio((double) cameraPreviewSize.width / cameraPreviewSize.height);
        }

UPDATE:

Also i try to add setOrientationHint where i start the MediaMuxer

Ayer answered 29/11, 2018 at 7:31 Comment(1)
@fadden do you have any idea why this work weird in portrait mode.Ayer
A
1

Finally after 2 day i solve my problem.

This Solution for Grafika ContinuousCaptureActivity.java

In drawFrame() Method i'll change some code for portrait.

I add below 2 line in drawFrame method:

Matrix.rotateM(mTmpMatrix, 0, 270, 0, 0, 1);
Matrix.translateM(mTmpMatrix, 0, -1, 0, 0); 

In drawFrame Method 2 type to set the glViewport

  • First For Fill the SurfaceView with it. (it means this orientation change while user recording a video)
  • Second For Send it to the video encoder. (it means this orientation change after save the video)

So i'll be change in 2nd opetion

Please find full code at below :

 // Send it to the video encoder.
        if (!mFileSaveInProgress) {
            mEncoderSurface.makeCurrent();
            if (!AppSetting.getValue(activity, Config.ORIENTATION, "").equalsIgnoreCase("Select")) {
                if (AppSetting.getValue(activity, Config.ORIENTATION, "").equalsIgnoreCase("Portrait")) {
                    Matrix.rotateM(mTmpMatrix, 0, 270, 0, 0, 1);
                    Matrix.translateM(mTmpMatrix, 0, -1, 0, 0);
                }
            }
            GLES20.glViewport(0, 0, VIDEO_WIDTH, VIDEO_HEIGHT);
            mFullFrameBlit.drawFrame(mTextureId, mTmpMatrix);
            //drawExtra(mFrameNum, VIDEO_WIDTH, VIDEO_HEIGHT);
            mCircEncoder.frameAvailableSoon();
            mEncoderSurface.setPresentationTime(mCameraTexture.getTimestamp());
            mEncoderSurface.swapBuffers();
Ayer answered 1/12, 2018 at 6:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.