在人像模式下录制视频时出现方向问题android grafika [英] Orientation Issue while video recording in Portrait Mode 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屋!