ios AVFoundation - how to deal with UIDeviceOrientationFaceUp and UIDeviceOrientationFaceDown

StackOverflow https://stackoverflow.com/questions/22268237

  •  11-06-2023
  •  | 
  •  

Domanda

I'm using AVFoundationFramework to capture video. When I starting capturing I set video orientation based on current device orientation. I do it like this:

startRecordingOrientation = [[UIDevice currentDevice] orientation];
AVCaptureVideoOrientation avcaptureOrientation;
if ( startRecordingOrientation == UIDeviceOrientationLandscapeLeft )
{
    avcaptureOrientation  = AVCaptureVideoOrientationLandscapeRight;
}
else if ( startRecordingOrientation == UIDeviceOrientationLandscapeRight )
{
    avcaptureOrientation  = AVCaptureVideoOrientationLandscapeLeft;
}
else if(startRecordingOrientation == UIDeviceOrientationPortrait)
{
    avcaptureOrientation = AVCaptureVideoOrientationPortrait;
}
else if(startRecordingOrientation == UIDeviceOrientationPortraitUpsideDown)
{
    avcaptureOrientation = AVCaptureVideoOrientationPortraitUpsideDown;
}

[videoConnection setVideoOrientation:avcaptureOrientation];

But I have problem with UIDeviceOrientationFaceUp and UIDeviceOrientationFaceDown. I need to know what is device oriention to properly set recording video orientation becouse If I don't do that my video output will be rotated. I can't use InterfaceOrientation instead of AVCaptureVideoOrientation becouse my application use only portrait orientation. Is there any way to determine if iOS device is in exactly portrait/landscape orientation? If not, I can load my recorded video and then determine video orientation and rotate it to portrait but is there any way to determine orientation of already recorded video?

È stato utile?

Soluzione

UIDeviceOrientationFaceUp and UIDeviceOrientationFaceDown haven't a corresponding interface rotation, by default you can match the orientation that you prefer, I use portrait.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top