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

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

问题描述

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

这是相机预览的样子

但最终的视频是这样的(左边的所有项目,出现在右边)

到目前为止我尝试过的:

我尝试在准备记录器时应用 matrix,但它似乎确实改变了任何东西.

private boolean prepareRecorder(int cameraId){//# 创建一个新的 MediaRecorder 实例mRecorder = new MediaRecorder();setCameraDisplayOrientation(this,cameraId,mCamera);int 角度 = getVideoOrientationAngle(this,cameraId);mRecorder.setOrientationHint(angle);if(cameraId == Camera.CameraInfo.CAMERA_FACING_FRONT){矩阵矩阵 = 新矩阵();matrix.preScale(1.0f,-1.0f);}//所有其​​他代码在这里准备记录器}

我已经阅读了下面的所有问题,但这一切似乎都没有解决我的问题.有关信息,我使用 SurfaceView 进行相机预览,所以这里的这个问题没有帮助.

1)

这是你的同龄人看到相同场景的方式

通常,视频的录制是从您的同伴的角度完成的,如第二张图片所示.这是视频会议等的自然设置.

但是 Snapchat 和其他一些社交应用程序选择存储前置视频剪辑,就像您从镜子中录制它一样(就像第一张照片上的录音机在您手中一样).有些人喜欢这个功能,有些人讨厌它(见 https://forums.androidcentral.com/general-help-how/664539-front-camera-pics-mirrored-reversed-only-snapchat.htmlhttps://www.reddit.com/r/nexus6/comments/3846ay/has_anyone_found_a_aping)

您不能为此使用 MediaRecorder.您可以使用 MediaCodec 的底层 API 来记录处理过的帧.您需要手动"翻转每一帧,这可能会严重影响性能,因为通常 MediaRecorder 以非常有效的方式将相机连接"到硬件编码器,甚至不需要将像素复制到用户内存.这个答案展示了如何操纵相机渲染到纹理的方式.

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天全站免登陆