IOS - Capture video in landscape mode when the device is in portrait mode

Can I capture video in landscape orientation when the device is in portrait mode?

something like that:
enter image description here

in fact, what I need is a capture in the portrait, but with a width> height, I do not want the user to rotate the device, but I want to capture a wider image, as in landscape mode.

just changing the preview frame will be wide (width> height), of course, not enough.

I tried to change the orientation of the video of the preview layer, but this will rotate the image, and this is not what I want.

previewLayer.connection.videoOrientation = .landscapeRight 

- is that any meaning?

+5
source share
3 answers

No, this is not possible, since you have to physically rotate the camera.

You can watch the output video in any format you want.

This, however, will cause your vertical resolution to be no more than what your horizontal resolution is.

Also reduce the field of view.

If you still want to crop the video to simulate this “smaller landscape mode” in real time, I suggest you use the “GPUImageCropFilter” from the GPUImage library

+1
source

You can use AVAssetWriter and set the size of the output video.

However, remember that you are going to reduce quality. If the orientation of the camera is portrait, then what you get is a video that (for arguments) is 720H ​​x 360W.

So, you want to make this landscape, if you keep the proportions, you will end up with a video (by cropping the input) that is 180H x 360W.

Remember that there is a difference between what the camera sees, what you send to the preview level and what you write to the file — all of them can be independent of each other (you talked about changing the preview frame, remember that has nothing to do with the video you are recording).

0
source

Have you tried to set gravity and preview boundaries?

 var bounds:CGRect = self.view.layer.bounds previewLayer?.videoGravity = AVLayerVideoGravityResizeAspectFill previewLayer?.bounds = bounds previewLayer?.position = CGPointMake(CGRectGetMidX(bounds), CGRectGetMidY(bounds)) 
0
source

Source: https://habr.com/ru/post/1269867/


All Articles