I want to use AVCaptureConnection to set the orientation of the device when shooting a video (Swift)

Asked 2 years ago, Updated 2 years ago, 81 views

I use iOS Swift to create a video save process.

I can now save videos, but when I check the video taken with the iPhone facing up with the camera roll, it is facing sideways.To avoid this, we found that you need to configure the orientation of the device using AVCaptureConnection.

I tried to rewrite the Swift version based on the Objective-C source below.

AVCaptureConnection*captureConnection=<#Acapture connection#>
if ([captureConnection isVideoOrientationSupported])
{
    AVCaptureVideoOrientation orientation = AVCaptureVideoOrientationLandscapeLeft;
    captureConnection setVideoOrientation:orientation;
}

I actually rewritten the following sources:

I was wondering if the image would be like this, so I was forced to rewrite it, so I got an error, but I don't know how to correct it.(I've looked it up online, but I'm at a loss.)

var captureConnection=AVCaptureConnection()
if(captureConnection.videoOrientation)
{
    variations —AVCaptureVideoOrientation=AVCaptureVideoOrientationLandscapeLeft
    captureConnection.videoOrientation;
}

Could someone give me some advice?
Thank you for your cooperation.

ios objective-c swift avfoundation camera

2022-09-30 14:19

1 Answers

The execution test was not successful, but the errors and warnings disappeared.
How about the following?

varcaptureConnection = AVCaptureConnection()
if(captureConnection.supportVideoOrientation)
{
    variations:AVCaptureVideoOrientation=AVCaptureVideoOrientation.LandscapeLeft
    captureConnection.videoOrientation=orientation
}


2022-09-30 14:19

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.