简体   繁体   English

从 PHPickerViewController xcode swift 获取结果后如何压缩视频

[英]How to compress video after getting result from PHPickerViewController xcode swift

I know that UIImagePickerController allows you to compress media content upon selection.我知道 UIImagePickerController 允许您在选择时压缩媒体内容。 However, I'm not sure how to do the same with PHPickerViewController.但是,我不确定如何对 PHPickerViewController 做同样的事情。 How can I compress a video after getting a result ( didFinishPicking ), (so I can reduce the amount of time to upload and download the data from then on)获得结果后如何压缩视频( didFinishPicking ),(这样我可以减少从那时起上传和下载数据的时间)

I don't think PHPickerViewController does that, but there are other ways to do it depending on how you work with the picker:我不认为PHPickerViewController ,但是根据您使用选择器的方式,还有其他方法可以做到这一点:

  1. If you're using the default picker configuration (ie creating a PHPickerConfiguration without passing the photo library and therefore not having the need to request permissions), you'll have to work with NSItemProvider .如果您使用默认选择器配置(即创建PHPickerConfiguration而不传递照片库,因此不需要请求权限),则必须使用NSItemProvider From what I learned, the only option might be to save the video to a temporary file using the item provider and the convert it to a lower resolution/bitrate using AVAssetExportSession (see some examples here: How can I reduce the file size of a video created with UIImagePickerController? ).据我所知,唯一的选择可能是使用项目提供程序将视频保存到临时文件中,然后使用AVAssetExportSession将其转换为较低的分辨率/比特率(请参阅此处的一些示例:如何减少视频的文件大小用 UIImagePickerController 创建的? )。

  2. If you are using the picker with an explicitly passed photo library, the PHPickerResult will have the assetIdentifier provided to you, and you can use it to get a respective PHAsset .如果您将选择器与显式传递的照片库一起使用, PHPickerResult将提供给您的assetIdentifier ,您可以使用它来获取相应的PHAsset Then, use PHImageManager 's requestAVAsset method to get a video asset of a desired quality.然后,使用PHImageManagerrequestAVAsset方法获取所需质量的视频资产。 You'll still need to export the AVAsset via AVAssetExportSession though, but with this approach you won't have a (potentially large) full-res temporary file on disk.不过,您仍然需要通过AVAssetExportSession导出AVAsset ,但使用这种方法,您不会在磁盘上有(可能很大)全分辨率临时文件。 I was recently working on a open source app that uses this technique, you can find some examples here: https://github.com/vadimbelyaev/TbilisiCleanups/blob/main/TbilisiCleanups/Services/MediaUploadService.swift我最近正在开发一个使用这种技术的开源应用程序,您可以在此处找到一些示例: https://github.com/vadimbelyaev/TbilisiCleanups/blob/main/TbilisiCleanups/Services/MediaUploadService.swift

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何快速压缩视频? - How to compress a video in swift? 当用户尝试使用具有选定照片权限的 PHPickerViewController 在 IOS 14、swift 5 中检索视频时,获取视频数据为零 - Getting video data nil when user tries to retrieve video using PHPickerViewController with selected photos permission in IOS 14, swift 5 Swift iOS-如何压缩存储的嵌入式视频文件的大小? - Swift iOS -How to compress stored embedded video file size? 将视频从UIPickerViewController压缩到特定大小,以MB为单位,用于Swift 2中的网络连接 - Compress Video from UIPickerViewController to Specific Size in MB for Networking in Swift 2 从后台转换到活动状态后,如何恢复mp4视频? Xcode 10.1,Swift 4.2 - How can I resume the mp4 video after transition from the background to the active state? Xcode 10.1, Swift 4.2 如何在Swift 3 Xcode 8.2.1中播放视频 - how to play video in swift 3 Xcode 8.2.1 如何在 Xcode swift 5 中制作视频循环? - How to make a video loop in Xcode swift 5? 快速压缩视频大小,然后快速附加到电子邮件 - Compress video size before attach to an email in swift Swift xcode IOS,选择搜索结果后返回tableview - Swift xcode IOS, return to tableview after selecting a search result 来自 PHPickerViewController 的多个按钮图像 - Multiple Button Images from PHPickerViewController
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM