androidorientationandroid-mediacodecgrafika

Orientation Issue while video recording in Portrait Mode android grafika


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


Solution

  • 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

    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();