PHAssetChangeRequest 以低分辨率保存
PHAssetChangeRequest Saving at Low Resolution
我正在应用程序中捕获实时视频并使用 PHAssetChangeRequest
保存它,但是,视频以非常低的分辨率保存到相机胶卷。如果我从相机应用程序中拍摄完全相同的视频(相同 phone),它会以更高分辨率保存到相机胶卷中。
在应用程序中,肖像以 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)
}
感谢 Leo Dabus 为我指明了问题的本质。解决问题的一行代码如下。不依赖感知默认值是一个很好的教训....
self.imagePickerController.videoQuality = .typeHigh
我正在应用程序中捕获实时视频并使用 PHAssetChangeRequest
保存它,但是,视频以非常低的分辨率保存到相机胶卷。如果我从相机应用程序中拍摄完全相同的视频(相同 phone),它会以更高分辨率保存到相机胶卷中。
在应用程序中,肖像以 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)
}
感谢 Leo Dabus 为我指明了问题的本质。解决问题的一行代码如下。不依赖感知默认值是一个很好的教训....
self.imagePickerController.videoQuality = .typeHigh