在人像模式下录制视频时出现方向问题android grafika [英] Orientation Issue while video recording in Portrait Mode android grafika

查看:228
本文介绍了在人像模式下录制视频时出现方向问题android grafika的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设置了设备方向Landscape模式,然后完美保存了视频. 如果我拍了两边的视频.

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

但是我将设备方向设置为Portrait模式,这项工作很奇怪.

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

例如:

以下是我录制视频时的截图:

Below Screenshot while i Recording video :

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

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

我使用以下代码:

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

更新:

我还尝试添加 setOrientationHint ,在此我启动 MediaMuxer

UPDATE:

Also i try to add setOrientationHint where i start the MediaMuxer

推荐答案

最后两天后,我解决了我的问题.

Finally after 2 day i solve my problem.

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

我在drawFrame方法的2行下方添加:

I add below 2 line in drawFrame method:

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

drawFrame方法2中,键入以设置glViewport

In drawFrame Method 2 type to set the glViewport

  • 首先SurfaceView填入. (这意味着用户录制视频时此方向会发生变化)
  • 第二次发送到视频编码器. (这意味着在保存视频后此方向会发生变化)
  • 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)

因此,我将进行第二次更改

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

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

这篇关于在人像模式下录制视频时出现方向问题android grafika的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆