如何使前置摄像头捕获的视频不是反Android? [英] How to make video captured by front camera not being inverse Android?

查看:233
本文介绍了如何使前置摄像头捕获的视频不是反Android?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用MediaRecorder录制视频.使用后置摄像头时,它可以正常工作,但是使用前置摄像头时,捕获的视频被翻转/反转.意味着右边的项目将出现在左侧.工作正常,只是将最终捕获的视频翻转了.

这是相机预览的样子

但最终视频显示如下(所有项目都在左侧,出现在右侧)

我到目前为止所做的尝试:

我在准备录音机时尝试应用matrix,但似乎并没有改变任何内容.

private boolean prepareRecorder(int cameraId){

    //# Create a new instance of MediaRecorder
    mRecorder = new MediaRecorder();

    setCameraDisplayOrientation(this,cameraId,mCamera);
    int angle = getVideoOrientationAngle(this,cameraId);
    mRecorder.setOrientationHint(angle);

    if(cameraId == Camera.CameraInfo.CAMERA_FACING_FRONT){
        Matrix matrix = new Matrix();
        matrix.preScale(1.0f,-1.0f);
    }

    //all other code to prepare recorder here
  }

我已经在下面阅读了所有问题,但是所有这些似乎都无法解决我的问题.有关信息,我使用SurfaceView进行摄像机预览,所以这里的问题无济于事.

1) Android翻转前置摄像头镜子翻转了视频

2)如何防止android反转来自前置摄像头的图像?

3)防止翻转前置摄像头

所以我的问题是:

1)如何通过前置摄像头捕获视频,而该视频不是反相的(与摄像头预览完全相同)?

2)当摄像机预览使用的是SurfaceView而不是TextureView时如何实现? (因为我上面提到的所有问题,告诉有关使用TextureView的问题)

欢迎所有可能的解决方案..Tq

编辑

我制作了2个简短的视频片段以澄清问题,请下载并查看

1)在摄像头预览期间录制的视频

2)录制最终产品的视频

解决方案

因此,如果系统摄像头应用程序产生的视频类似于您的应用程序,则您没有做错任何事情.现在是时候了解前置摄像头视频录制会发生什么了.

前置摄像头与后置摄像头在捕获静态图片或视频的方式上没有什么不同.手机在屏幕上显示相机预览的方式有所不同.为了使用户看起来更自然,Android(和所有其他系统)对预览进行镜像,以便您可以像在镜像中一样看到自己.

重要的是要了解这仅适用于向您呈现预览的方式.如果拿起任何视频会议应用程序,将两只手握住的两个设备连接起来,然后看着自己,您会惊讶地发现自己的两个实例被翻转了.

这不是错误,这是向对方展示视频的自然方法.

查看草图:

这是您看到场景的方式:

这是您的同伴看到同一场景的方式

通常,从对等方的视点开始录制视频,如第二张图片所示.这是例如视频会议的自然设置.

但是Snapchat和其他一些社交应用程序选择存储正面的视频剪辑,就像从镜子中录制一样(就像录像机在您的第一幅照片上一样).有些人喜欢此功能,其他人则讨厌它(请参阅 https://forums.androidcentral.com/general-help-how/664539-front-camera-pics-mirrored-reversed-only-snapchat.html 此答案显示了如何操纵相机渲染到纹理的方式.

I recording video using MediaRecorder.When using back-camera,it working fine,but when using front camera,the video captured is being flipped/inverse.Means that the item in right,will appear on the left.The camera preview is working fine,just final captured video flipped.

Here is the camera preview looks like

But the final video appear like this(all the item in left hand side,appear on right hand side)

What I tried so far:

I tried to apply the matrix when prepare recorder,but it seems does change anything.

private boolean prepareRecorder(int cameraId){

    //# Create a new instance of MediaRecorder
    mRecorder = new MediaRecorder();

    setCameraDisplayOrientation(this,cameraId,mCamera);
    int angle = getVideoOrientationAngle(this,cameraId);
    mRecorder.setOrientationHint(angle);

    if(cameraId == Camera.CameraInfo.CAMERA_FACING_FRONT){
        Matrix matrix = new Matrix();
        matrix.preScale(1.0f,-1.0f);
    }

    //all other code to prepare recorder here
  }

I already read for all this question below,but all this seems didnt solve my problem.For information,I using SurfaceView for the camera preview,so this question here doesn't help.

1) Android flip front camera mirror flipped video

2) How to keep android from inverting the image from the front facing camera?

3) Prevent flipping of the front facing camera

So my question is :

1) How to capture a video by front camera which the video not being inverse(exactly the same with camera preview)?

2) How to achieve this when the Camera preview is using SurfaceView but not TextureView ? (cause all the question I mention above,tell about using TextureView)

All possible solution is mostly welcome..Tq

EDIT

I made 2 short video clip to clarify the problem,please download and take a look

1) The video during camera preview of recording

2) The video of the final product of recording

解决方案

So, if the system camera app produces video similar to your app, you didn't do something wrong. Now it's time to understand what happens to front-facing camera video recording.

The front facing camera is not different from the rear facing camera in the way it captures still pictures or video. There is a difference how the phone displays camera preview on the screen. To make it look more natural to the user, Android (and all other systems) mirrors the preview, so that you can see yourself as if in a mirror.

It is important to understand that this only applies to the way the preview is presented to you. If you pick up any video conferencing app, connect two devices that you hold in two hands, and look at yourself, you will see to your surprise that the two instances of yourself are flipped.

This is not a bug, this is the natural way to present the video to the other party.

See the sketch:

This is how you see the scene:

This is how your peer sees the same scene

Normally, recording of a video is done from the point if view of your peer, as in the second picture. This is the natural setup for, e.g., video conferencing.

But Snapchat and some other social apps choose to store the front-facing video clip as if you record it from the mirror (as if the recorder is in your hand on the first picture). Some people like this feature, others hate it (see https://forums.androidcentral.com/general-help-how/664539-front-camera-pics-mirrored-reversed-only-snapchat.html and https://www.reddit.com/r/nexus6/comments/3846ay/has_anyone_found_a_fix_for_snapchat_flipping)

You cannot use MediaRecorder for that. You can use the lower-level API of MediaCodec to record processed frames. You need to flip each frame 'manually', and this may be a significant performance hit, because normally the MediaRecorder 'connects' the camera to hardware encoder in a very efficient way, without need even to copy the pixels to user memory. This answer shows how you can manipulate the way camera is rendered to texture.

这篇关于如何使前置摄像头捕获的视频不是反Android?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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