AVCaptureSession vs. UIImagePickerController speed

2019-09-14 01:28发布

At the moment I am using a custom overlay on a UIImagePickerController, calling takePicture() to capture images. However, it takes a good few seconds to call the delegate method didFinishPickingMediaWithInfo. I've heard about using AVCaptureSession for my control over the camera. Would this allow me to get faster picture-taking speeds (similar to that of Snapchat)? Or are there any other ways that I can

Thanks

EDIT

I'm implementing my image capture as follows.

First I initialise a UIImagePickerController, using a UIView subclass called CustomCameraOverlayView for the overlay view, and present it in a modal view. The delegate of the CustomCameraOverlayView is set to the UIImagePickerControllerDelegate (self) so that I can call takePicture from the CustomCameraOverlayView.

imagePickerController = UIImagePickerController()
    if UIImagePickerController.isSourceTypeAvailable(.Camera) {
        imagePickerController.sourceType = UIImagePickerControllerSourceType.Camera
        imagePickerController.cameraDevice = UIImagePickerControllerCameraDevice.Rear
        imagePickerController.editing = true
        imagePickerController.delegate = self
        imagePickerController.showsCameraControls = false

        var customCameraOverlayView = CustomCameraOverlayView()
        customCameraOverlayView.delegate = self
        imagePickerController.cameraOverlayView = customCameraOverlayView
        imagePickerController.cameraOverlayView!.frame = self.view.frame
        var screenBounds: CGSize = UIScreen.mainScreen().bounds.size
        var imageHeight = (screenBounds.width/3)*4
        var scale = screenBounds.height / imageHeight
        imagePickerController.cameraViewTransform = CGAffineTransformConcat(CGAffineTransformMakeScale(scale, scale), CGAffineTransformMakeTranslation(0, (screenBounds.height - imageHeight)/2))
        self.presentViewController(imagePickerController, animated: true, completion: nil)
    }

Then inside the CustomCameraOverlayView I have a action set up from the "take picture" button in IB to my code. It sends a message back to the delegate to take the picture:

@IBAction func takePicture(sender: UIButton) {
    delegate!.imagePickerController.takePicture()
}

A few seconds later the delegate method is called. What could be slowing my implementation down?

1条回答
贪生不怕死
2楼-- · 2019-09-14 01:54

There is no performance differences between the two(at least not which can be noticed with naked eye). Its just the trade off between complexity and control.

AVFoundation is complex and a bit difficult to implement. But it comes with enormous amount of control over every bit of data. For any type of file processing involved, AVFoundation is the way to go.

On the other hand UIImagePickerController is easy to implement and useful if you want to do only primitive tasks, such as recording and capturing images.

But if any of them seems to be responding slow, then most probably it is because of your implementation. You need to post the code to deal with that. So, performance won't be a good criteria to choose between the two.

查看更多
登录 后发表回答