3

我设置了设备方向Landscape模式,然后它完美地保存了视频。如果我拍摄双方的视频。

但是我设置了设备方向Portrait模式这个工作很奇怪。

例如:

下面是我录制视频时的屏幕截图:

但是当我保存视频并在 MXPlayer 中查看时,它看起来像这样:

我使用下面的代码:

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

更新:

我也尝试在我开始的地方添加setOrientationHintMediaMuxer

4

1 回答 1

1

最后两天后我解决了我的问题。

该解决方案适用于Grafika ContinuousCaptureActivity.java

drawFrame()方法中,我将更改一些代码portrait

我在方法中添加以下 2 行drawFrame

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

drawFrame方法 2 类型中设置glViewport

  • 首先为填充SurfaceView。(这意味着用户录制视频时此方向发生变化)
  • 第二个用于将其发送到视频编码器。(这意味着保存视频后这个方向改变)

所以我会在第二个选项中改变

请在下面找到完整的代码:

 // 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();
于 2018-12-01T06:33:50.363 回答