Eyal
Eyal

Reputation: 10828

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

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?

Upvotes: 7

Views: 1445

Answers (3)

Pochi
Pochi

Reputation: 13459

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

Upvotes: 1

Ellen
Ellen

Reputation: 5190

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))

Upvotes: 0

Tim Bull
Tim Bull

Reputation: 2505

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).

Upvotes: 0

Related Questions