PHAssetChangeRequest以低分辨率保存

时间:2018-06-09 17:26:01

标签: swift phphotolibrary

我正在应用中捕捉实时视频并使用PHAssetChangeRequest保存它但是,视频以非常低的分辨率保存到相机胶卷。如果我从相机应用程序中拍摄相同的视频(同一部手机),它会以更高的分辨率保存到相机胶卷。

在应用程序内部,360X480正在保存肖像,而从相机应用程序拍摄的同一视频则保存在720X1200。

下面是从我的应用程序中保存视频的代码。为什么分辨率会下降?

PHPhotoLibrary.shared().performChanges({
        PHAssetChangeRequest.creationRequestForAssetFromVideo(atFileURL: self.sharedManager.videoFileLocalURL)
    }, completionHandler: { (saved, error) in
        if error != nil
        {
            print ("Asset Saving Error: \(error.debugDescription)")
        }

        if saved == true
        {
            print ("Asset saved to library")
            let fetchOptions = PHFetchOptions()
            fetchOptions.sortDescriptors = [NSSortDescriptor(key: "creationDate", ascending: true)]
            if let fetchedAsset = PHAsset.fetchAssets(with: .video, options: fetchOptions).lastObject
            {
                self.sharedManager.newzInfoInDraft.videoCreateDate = Date()
                self.processVideo(asset: fetchedAsset)
            }
            else
            {
                print ("Cannot fetch asset from library")
            }
        }
        else
        {
            print ("Asset not saved to library")
        }
    })
}

更新:调用捕获视频

let recordActionButton = UIAlertAction(title: "Record a video", style: .destructive)
        { _ in
            self.imagePickerController.sourceType = .camera
            self.imagePickerController.mediaTypes = [kUTTypeMovie as String]
            self.imagePickerController.delegate = self

            self.present(self.imagePickerController, animated: true, completion: nil)

        }

1 个答案:

答案 0 :(得分:0)

感谢Leo Dabus对问题的本质提出了一个指示。解决问题的一行代码如下。不依赖于感知的默认值是一个很好的教训......

self.imagePickerController.videoQuality = .typeHigh