【问题标题】:Mirror flip video taken from front camera in Android从Android中的前置摄像头拍摄的镜像翻转视频
【发布时间】:2016-08-05 01:49:49
【问题描述】:

我有一个能够捕捉图像和录制视频的相机应用程序。但是,当从设备的前置摄像头捕获图像或录制视频时,结果会翻转,就像您在看镜子一样。我想再次翻转它,使其看起来正常。我设法通过使用Matrix 翻转Bitmap 来处理图像:

   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 对不起我的英语

【问题讨论】:

  • 您好,您找到解决方案了吗?谢谢
  • @dangling_refrenz 不,在这个线程和我在这里得到的答案之后从未尝试过解决这个问题,无论如何祝你好运。
  • @DAVIDBALAS1 我面临同样的问题。你找到解决办法了吗?

标签: android ffmpeg


【解决方案1】:

使用前置摄像头拍摄图像或录制视频总是会产生翻转的图像,这是预期的,因为前置摄像头的工作方式就像您在看镜子一样。

从相机中获取图片后,通过将图像绘制到新的上下文中来翻转图像。

请尝试以下代码 sn-ps。参考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);

【讨论】:

  • 您不能一次翻转视频,因为您必须覆盖 onPreviewFrame() 回调,然后需要在写入缓冲区之前翻转每一帧。
  • 好的,谢谢.. 我想这需要很长时间。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-11-05
  • 1970-01-01
  • 1970-01-01
  • 2016-10-25
相关资源
最近更新 更多