Georg
Georg

Reputation: 3930

How to crop a video in iOS

I was having a look at the RosyWriter Sample Code provided by Apple as a starting point and I'd like to find a way how to crop a video.

So i have the full resolution video from the iPhones Camera, but I just want to use a cropped part of it (and also rotate this subpart).

I figured that in captureOutput:didOutputSampleBuffer: fromConnection: i can modify each frame by modifying the CMSampleBufferRef that i get passed in.

So my questions now are:

  1. Is this the right place to crop my video?

  2. Where do I specify that the final video (that get's saved to disc) has a smaller resolution than the full video captured by AVCaptureSession? Setting the AVVideoWidthKey and AVVideoHeightKey has no effect.

  3. How can I crop the video and still have good performance?

Any help is appreciated!

Thanks a lot!

EDIT:

Maybe I just need to know how I can make a video that was shot in portrait a landscape one by turning the images of the video by 90 degrees and then zoom in to fit the width again...?!?

Upvotes: 3

Views: 2769

Answers (1)

Steve McFarlin
Steve McFarlin

Reputation: 3596

In AVVideoSetttings.h there is the AVVideoScalingModeKey. This key combined with the defined values control how the video is scaled/cropped when encoding the images to the video container. For example if you specified a value of AVVideoScalingModeFit then cropping is used. Check out the header for how other values effect the video images.

Upvotes: 7

Related Questions