从Android的前置摄像头拍摄的镜像翻转视频
我有一个能够拍摄图像和录制视频的摄像头应用程序。但是,当从设备前置摄像头捕捉图像或录制视频时,结果会翻转,就像您在看镜子一样。我想再次翻转,所以看起来很正常。我设法与图像要做到这一点,通过使用Matrix
翻转Bitmap
:从Android的前置摄像头拍摄的镜像翻转视频
public Bitmap flip(Bitmap bitmap) {
int w = bitmap.getWidth();
int h = bitmap.getHeight();
Matrix matrix = new Matrix();
float[] mirrorY = {-1, 0, 0, 0, 1, 0, 0, 0, 1};
Matrix matrixMirrorY = new Matrix();
matrixMirrorY.setValues(mirrorY);
matrix.postConcat(matrixMirrorY);
matrix.postRotate(90);
return Bitmap.createBitmap(bitmap, 0, 0, w, h, matrix, true);
}
我无法弄清楚如何翻转由MediaRecorder
拍摄的视频,我知道我可以运行ffmpeg
命令:
-i /pathtooriginalfile/originalfile.mp4 -vf hflip -c:a copy /pathtosave/flippedfile.mp4
但我不知道如何从代码运行ffmpeg
命令,我找不到另一种方法。有很多议题讨论这个问题,但我找不到解决方案。注意:Snapchat有可能以某种方式工作。
谢谢。
P.S对不起,使用前置摄像头,我的英语
拍摄图像或录制视频将总是给人翻转的图像,其作为前置摄像头的工作原理像你照镜子的预期。
从相机获取图片后,通过将图像绘制到新的上下文中将图像翻转回来。
请尝试下面的代码片段。请参考Android- Taking a picture from front facing camera rotates the photo
Matrix rotateRight = new Matrix();
rotateRight.preRotate(90);
if(android.os.Build.VERSION.SDK_INT>13 && CameraActivity.frontCamera) {
float[] mirrorY = { -1, 0, 0, 0, 1, 0, 0, 0, 1};
rotateRight = new Matrix();
Matrix matrixMirrorY = new Matrix();
matrixMirrorY.setValues(mirrorY);
rotateRight.postConcat(matrixMirrorY);
rotateRight.preRotate(270);
}
final Bitmap rImg= Bitmap.createBitmap(img, 0, 0,
img.getWidth(), img.getHeight(), rotateRight, true);
再次阅读。我设法翻转图像而不是视频。 – DAVIDBALAS1
您无法一次翻转视频,因为您必须重写onPreviewFrame()回调,然后在写入缓冲区之前需要翻转每一帧。 –
好的,谢谢..我想这会花太长的时间。 – DAVIDBALAS1
嗨,你找到了解决方案吗?谢谢 –
@dangling_refrenz Nope,从来没有试图解决这个问题后,这个线程和我在这里得到的答案,无论如何,祝你好运。 – DAVIDBALAS1
@ DAVIDBALAS1我面临同样的问题。你找到解决方案吗? – Piyush