使用前置摄像头时需要镜像视频方向和手柄旋转 [英] Need to Mirror Video Orientation and Handle Rotation When Using Front Camera

查看:102
本文介绍了使用前置摄像头时需要镜像视频方向和手柄旋转的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不太清楚如何处理前置摄像头的视频捕获方向.拍摄视频和图片时,我对后置摄像头进行了所有旋转处理,拍摄照片时,我对前摄像头进行了所有处理,并以正确的方向保存了捕获的视频和图片,但前置摄像头视频捕获除外.

I can't quite figure out how to handle front facing camera video capture orientations. I have all rotations handled for the back camera when capturing video and pictures and all rotations handled for the front camera when taking pictures, as well as saving the captured videos and pictures with the correct orientations as well, except for the front camera video capture.

第一个问题是,在任一横向模式下,视频都没有正确地以正确的方向保存.第二个问题是已保存的视频已镜像.尽管我知道如何使用前置摄像头来处理图片的这种镜像效果,但是我不确定调用视频处理该如何调用.

The first problem is when in either landscape mode, the video is not saved correctly with the correct orientation. The second problem is that the saved video is mirrored. Although i know how to handle this mirroring effect for picture using the front camera, I am not sure what to call to handle it for videos.

我很难找到专门针对此问题的任何东西,但未能做到.如果有人能指出我要解决这个特定问题的线程,那将是很好的.

I had a lot of trouble trying to find anything specifically for this one issue and failed to do so. If anybody could point me to a thread that addresses this specific issue, that would be great.

无论哪种方式,这都是在设备方向更改时处理视频方向的方法.如果使用前置摄像头,我不确定要在代码中添加什么内容.

Either way, here is the method that is called that handles video orientation when device orientation changes. I am not sure exactly what to add to my code if the front camera is being used.

/**************************************************************************
    DEVICE ORIENTATION DID CHANGE
    **************************************************************************/
    func deviceOrientationDidChange() {

        println("DEVICE ORIENTATION DID CHANGE CALLED")

        let orientation: UIDeviceOrientation = UIDevice.currentDevice().orientation

        //------ IGNORE THESE ORIENTATIONS ------
        if orientation == UIDeviceOrientation.FaceUp || orientation == UIDeviceOrientation.FaceDown || orientation == UIDeviceOrientation.Unknown || orientation == UIDeviceOrientation.PortraitUpsideDown || self.currentOrientation == orientation {

            println("device orientation does not need to change --- returning...")

            return
        }


        self.currentOrientation = orientation


        //------ APPLY A ROTATION USING THE STANDARD ROTATION TRANSFORMATION MATRIX in R3 ------

        /*

            x       y       z
            ---           ---
        x | cosø    sinø    0 |
        y | -sinø   consø   0 |
        z | 0       0       1 |
            ---           ---

        */


        //----- PERFORM BUTTON AND VIDEO DATA BUFFER ROTATIONS ------
        switch orientation {

        case UIDeviceOrientation.Portrait:

            rotateButtons(self.degrees0)

            if self.usingFrontCamera == true {


            }
            else {

            }

            println("Device Orientation Portrait")

            break

        case UIDeviceOrientation.LandscapeLeft:

            println("Device Orientation LandScapeLeft")

            rotateButtons(self.degrees90)

            if self.usingFrontCamera == true {

                println("Using front camera, rotation in landscape left")

//                if let connection = self.captureConnection {
//                    
//                    connection.videoOrientation = AVCaptureVideoOrientation.LandscapeRight
//                    
//                    println("Capture connection Orientation is LandScape Right")
//                }
//                else {
//                    
//                    println("Capture connection is nil, could not change video orientation")
//                }
            }
            else {

                if let connection = self.captureConnection {

                    connection.videoOrientation = AVCaptureVideoOrientation.LandscapeRight

                    println("Capture connection Orientation is LandScape Right")
                }
                else {

                    println("Capture connection is nil, could not change video orientation")
                }
            }

            break

        case UIDeviceOrientation.LandscapeRight:

            println("Device Orientation LandscapeRight")

            rotateButtons(-self.degrees90)

            if self.usingFrontCamera == true {

                println("Using front camera, rotation in landscape right")

//                if let connection = self.captureConnection {
//                    
//                    connection.videoOrientation = AVCaptureVideoOrientation.LandscapeRight
//                    
//                    println("Capture connection Orientation is LandScape Left")
//                }
//                else {
//                    
//                    println("Capture connection is nil, could not change video orientation")
//                }
            }
            else {

                if let connection = self.captureConnection {

                    connection.videoOrientation = AVCaptureVideoOrientation.LandscapeLeft

                    println("Capture connection Orientation is LandScape Left")
                }
                else {

                    println("Capture connection is nil, could not change video orientation")
                }
            }

            break

        default:

            break
        }
    }

推荐答案

基于此答案:我也遇到了同样的问题,并且能够在这篇文章之后予以解决.

I faced the same issue and was able to fix it following this post.

var videoConnection:AVCaptureConnection?
  for connection in self.fileOutput.connections {
    for port in connection.inputPorts! {
      if port.mediaType == AVMediaTypeVideo {
        videoConnection = connection as? AVCaptureConnection
          if videoConnection!.supportsVideoMirroring {
            videoConnection!.videoMirrored = true
          }
        }
      }
   }
}

请告诉我,这对詹姆斯有没有帮助

Please let me know if it helps you James

这篇关于使用前置摄像头时需要镜像视频方向和手柄旋转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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