使用 UIImagePickerController 选择电影时避免视频压缩?
我正在使用 UIImagePickerController 允许我的用户从资源库中选择视频。
当用户选择第二个屏幕上的“选择”按钮时,视图会显示进度条和“正在压缩视频...”消息。
为什么会发生这种情况?
有什么方法可以避免这种压缩操作吗?
I'm using UIImagePickerController to allow my user to select a video from the asset library.
When the user selects the "Choose" button on the second screen, the view displays a progress bar and a "Compressing Video..." message.
Why is this happening?
Is there some way I can avoid this compression operation?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
答:目前无法控制 UIImagePickerController 如何压缩选取的视频。
我刚刚做了一些快速测试。使用我创建的测试应用程序,我两次选择相同的视频 - 一次将
videoQuality
属性设置为UIImagePickerControllerQualityTypeHigh
,一次将其设置为UIImagePickerControllerQualityTypeLow
代码>.复制的结果文件大小完全相同,均为 15.1MB,帧大小为 360x480。原件大小为 72.5MB,帧大小为 480x640。显然这个属性根本不影响所使用的压缩。Answer: There is currently no way to control how UIImagePickerController compresses the picked video.
I just did some quick tests. Using a test app I created, I picked the same video two times -- once with the
videoQuality
property set toUIImagePickerControllerQualityTypeHigh
and once with it set toUIImagePickerControllerQualityTypeLow
. The resulting files that were copied over are exactly the same size, 15.1MB with a frame size of 360x480. The original was 72.5MB with a frame size of 480x640. Apparently this property doesn't affect the compression used at all.将 UIImagePickerController 的 videoQuality 属性设置为“高”(UIImagePickerControllerQualityTypeHigh = 0)
从 SDK 文档中:
“如果在图像选择器中显示录制的影片,请指定您不想降低影片的视频质量。”
http://developer.apple.com/iphone/library/documentation/uikit/reference/UIImagePickerController_Class/UIImagePickerController/UIImagePickerController.html#//apple_ref/doc/c_ref/UIImagePickerControllerQualityType
Set the videoQuality property of the UIImagePickerController to "High" (UIImagePickerControllerQualityTypeHigh = 0)
From the SDK documentation:
"If displaying a recorded movie in the image picker, specifies that you do not want to reduce the video quality of the movie."
http://developer.apple.com/iphone/library/documentation/uikit/reference/UIImagePickerController_Class/UIImagePickerController/UIImagePickerController.html#//apple_ref/doc/c_ref/UIImagePickerControllerQualityType
由于还没有办法避免使用 UIImagePickerController 进行压缩,因此我想包括一些关于如何创建自己的图像选择器来避免压缩的想法。
这将允许访问原始视频文件:
iOS 8
查看 PhotoKit 文档以访问集合(时刻)和其他选项。
以下是 Apple 使用 PhotoKit 的示例应用程序,可以将其修改为照片选择器: https://developer.apple.com/library/ios/samplecode/UsingPhotosFramework/Introduction/Intro.html
这是 GitHub 上的一个照片选择器库,它使用 PhotoKit,看起来很有前途,因为它为您提供了所有选定图像/视频的 PHAsset 对象: https://github.com/guillermomuntaner/GMImagePicker
iOS 7及以下
Since there is no way yet to avoid compression using UIImagePickerController, I wanted to include some ideas of how you can create your own image picker that will avoid compression.
This will allow access to the raw video files:
iOS 8
Look at the PhotoKit documentation for accessing collections (moments) and other options.
Here is a sample app from Apple using PhotoKit that could be modified to be a photo picker: https://developer.apple.com/library/ios/samplecode/UsingPhotosFramework/Introduction/Intro.html
Here is a photo picker library on GitHub that uses PhotoKit that looks promising since it gives you the PHAsset objects for all the selected images/videos: https://github.com/guillermomuntaner/GMImagePicker
iOS 7 and below
从 iOS 11 开始,您可以指定
videoExportPreset
并将其设置为AVAssetExportPresetPassthrough
:这仍然会显示“压缩”进度条,但速度会快得多,特别是对于较小的视频。
Starting from iOS 11, you can specify the
videoExportPreset
and set it toAVAssetExportPresetPassthrough
:This will still show the "compressing" progress bar though, but will be much faster, especially for smaller videos.
对于那些提供使用 videoQuality 属性建议的人,文档明确指出它是视频捕获选项,而不是选择器选项。正如 Jack 在下面提到的,它也用于转码。看起来我读文档的速度太快了,因为我没有注意到转码的提及。
For those giving the advice to use the videoQuality property, documentation is clearly stating that it is a video capture option, not a picker option.As Jack is mentioning it below, it is also for transcoding. Looks like I read the doc too quickly because I didn't notice the transcoding mention.