1

When you offer the possibility to a user to use a video previously registered in the gallery of the iPhone with a UIImagePickerController, it's imported and compressed to 1280x720 regardless of the original resolution. Is it possible to get the original video at the original quality with UIImagePickerController ?

The url returned by UIImagePickerController.InfoKey.mediaURL seem to be a temporary url to the compressed file, so not usable to get the original file.

Mathieu Robert
  • 325
  • 1
  • 5
  • 17

2 Answers2

2

Two ways I can think of for that problem. First, there is a property of UIImagePickerController called videoExportPreset. You can set that property to AVAssetExportPresetPassthrough.

videoExportPreset can be used to specify the transcoding quality for videos (via a AVAssetExportPreset* string). If the value is nil (the default) then the transcodeQuality is determined by videoQuality instead. Not valid if the source type is UIImagePickerControllerSourceTypeCamera.

Remember to do import AVFoundation.


Second way is to implement your own picker, that is, using PHAsset.

Example:

 let fetchResult = PHAsset.fetchAssets(with: .video, options: nil)

 let videoRequestOptions = PHVideoRequestOptions()
 videoRequestOptions.version = .original

 fetchResult.enumerateObjects { (asset, index, _) in
     PHImageManager.default().requestAVAsset(forVideo: asset, options: videoRequestOptions) { (avAsset, audioMix, infoDic) in
         //----
     }
 }
Glenn Posadas
  • 12,555
  • 6
  • 54
  • 95
0

you can set AVCaptureSession.Preset according to your need.

var session: AVCaptureSession?

func video(){

        // Don't trigger camera access for the background
    guard AVCaptureDevice.authorizationStatus(for: AVMediaType.video) == .authorized else {
        return
    }

    do {
        // Prepare avcapture session
        session = AVCaptureSession()
        session?.sessionPreset = AVCaptureSession.Preset.high //medium or low

        // Hook upp device
        let device = AVCaptureDevice.default(for: AVMediaType.video)
        let input = try AVCaptureDeviceInput(device: device!)
        session?.addInput(input)

        // Setup capture layer

        guard session != nil else {
            return
        }

        let captureLayer = AVCaptureVideoPreviewLayer(session: session!)
        captureLayer.frame = bounds
        captureLayer.videoGravity = AVLayerVideoGravity.resizeAspectFill
        cameraBackground.layer.addSublayer(captureLayer)

        self.captureLayer = captureLayer
    } catch {
        session = nil
    }
}
Anil Kumar
  • 1,830
  • 15
  • 24