Android翻转前置摄像头镜翻转视频

Android flip front camera mirror flipped video

我正在尝试从Android前置摄像头录制视频,同时也在表面视图上显示。

我用前置摄像头发现的是,即使表面视图显示为普通视图,前置摄像头也会在录制过程中通过镜子翻转视频。

有什么办法可以防止或解决此问题?

我阅读了其他stackoverflow文章,例如如何防止android反转来自前置摄像头的图像?

但这似乎只是在谈论用前置摄像头拍照和反转图像,而这我已经使用矩阵自己解决了。 但是,对于视频使用矩阵似乎无效。


就我而言,我只需要在播放时水平翻转即可。录制时,它已经翻转了镜面效果,而且我认为无法对其进行修改。但是下面的代码在播放时解决了我的问题。

1
videoPlayer.setScaleX(-1);

我没有解决方案,但是在我看来,关键是:

MediaRecorder.setOrientationHint

Sets the orientation hint for output video playback. This method should be called before prepare(). This method will not trigger the source video frame to rotate during video recording, but to add a composition matrix containing the rotation angle in the output video if the output format is OutputFormat.THREE_GPP or OutputFormat.MPEG_4 so that a video player can choose the proper orientation for playback. Note that some video players may choose to ignore the compostion matrix in a video during playback.

我正在用H264录制视频,但对我不起作用:(
但这可能对您有帮助。尝试过吗?


在setDisplayOrientation方法的文档(http://developer.android.com/reference/android/hardware/Camera.html)中,我们可以找到:

Note that preview display of front-facing cameras is flipped
horizontally before the rotation, that is, the image is reflected
along the central vertical axis of the camera sensor. So the users can
see themselves as looking into a mirror.

因此,应该翻转预览显示,但不要翻转录制的视频。通过预览显示,您是否看到自己正照镜子?如果是这样,则一切正常。


您必须应用矩阵转换,例如:

1
2
3
4
5
if(isFrontCamera) {
    m.preScale(-ratio, ratio);
} else {
    m.preScale(ratio, ratio);
}

假设您不调整任何比例大小,则比例将为1,从而使非前置摄像头preScale过时。