简体   繁体   English

在人像模式下录制视频时出现方向问题android grafika

[英]Orientation Issue while video recording in Portrait Mode android grafika

I set the device Orientation Landscape mode then it saves the video perfectly. 我设置了设备“定向Landscape模式,然后完美保存了视频。 if I capture a video with both sides. 如果我拍摄双方的视频。

But I set the device orientation Portrait Mode this work weird. 但是我将设备方向设置为Portrait模式这一工作很奇怪。

For Example: 例如:

Below Screenshot while i Recording video : 在我录制视频时的屏幕截图下方:

But when i save the video and see in MXPlayer then it's look like this: 但是,当我保存视频并在MXPlayer中观看时,它看起来像这样:

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 我也尝试在启动MediaMuxer地方添加setOrientationHint

Finally after 2 day i solve my problem. 终于两天后,我解决了我的问题。

This Solution for Grafika ContinuousCaptureActivity.java Grafika ContinuousCaptureActivity.java此解决方案

In drawFrame() Method i'll change some code for portrait . drawFrame()方法中,我将为portrait更改一些代码。

I add below 2 line in drawFrame method: 我在drawFrame方法中添加以下2行:

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

In drawFrame Method 2 type to set the glViewport drawFrame方法2中,键入以设置glViewport

  • First For Fill the SurfaceView with it . 首先用它填充SurfaceView (it means this orientation change while user recording a video) (这意味着用户录制视频时此方向会发生变化)
  • Second For Send it to the video encoder . Second For 将其发送到视频编码器 (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();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM