iOS - Capture video in landscape while the device is in portrait mode
Asked Answered
S

3

7

Is it possible to capture video in landscape while the device is in portrait mode?

something like this:
enter image description here

actually what i need is to capture in portrait but with width > height, i dont want the user to rotate the device, but i do want to capture a wider picture like in landscape mode.

just changing the preview layer frame to be wide (width>height) wont be enough of course.

i tried changing the video orientation of the preview layer, but that will rotate the picture, and thats not what i want.

previewLayer.connection.videoOrientation = .landscapeRight  

is that make any sense?

Sleepwalk answered 16/7, 2017 at 13:12 Comment(1)
Same here, Yet, there is no solution answered thus far.Jackinthebox
P
1

No its not possible as you would have to physically rotate the camera.

You can CROP the output video to whatever aspect ratio you desire.

This will however make your vertical resolution be at most what your horizontal resolution currently is.

As well as decreasing your field of view.

If you still wanna crop the video to simulate this "smaller landscape mode" in real time i suggest you use the "GPUImageCropFilter" from the library GPUImage

Publish answered 21/7, 2017 at 8:51 Comment(0)
H
0

You can, you need to use AVAssetWriter and set the dimensions of the output video.

However, remember that you're going to be reducing quality. If the camera orientation is portrait, then what you're receiving is a video that is (for arguments sake) 720H x 360W.

So you want to make that landscape, if you preserve the aspect ratio, you're going to end up with a video (by cropping the input) that's 180H x 360W.

Remember, there is a difference between what the camera sees, what you send to the preview layer and what you record to a file - they can all be independent of each other (you spoke about changing the preview layer frame, remember that has nothing to do with the video you write out).

Horal answered 19/7, 2017 at 16:16 Comment(0)
O
0

Have you tried with setting gravity & bounds of previewLayer?

var bounds:CGRect = self.view.layer.bounds
previewLayer?.videoGravity = AVLayerVideoGravityResizeAspectFill
previewLayer?.bounds = bounds
previewLayer?.position = CGPointMake(CGRectGetMidX(bounds), CGRectGetMidY(bounds))
Ouidaouija answered 21/7, 2017 at 4:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.