使用 UIImagePickerController 似乎无法避免压缩。看到这个答案:
https://stackoverflow.com/a/5893066/406152
我尝试过使用imagePicker.videoQuality = UIImagePickerControllerQualityTypeHigh;,但它仍然会进行压缩。呃。
编辑:
但是,您可以自己滚动。这将允许访问原始视频文件:
iOS 8
PHFetchResult *assetsFetchResult = [PHAsset fetchAssetsWithMediaType:PHAssetMediaTypeVideo options:nil];
for (PHAsset *asset in assetsFetchResult) {
PHVideoRequestOptions *videoRequestOptions = [[PHVideoRequestOptions alloc] init];
videoRequestOptions.version = PHVideoRequestOptionsVersionOriginal;
[[PHImageManager defaultManager] requestAVAssetForVideo:asset options:videoRequestOptions resultHandler:^(AVAsset *asset, AVAudioMix *audioMix, NSDictionary *info) {
// the AVAsset object represents the original video file
}];
}
查看 PhotoKit 文档以访问集合(时刻)和其他选项。
这是一个来自 Apple 的示例应用,它使用 PhotoKit,可以修改为照片选择器:https://developer.apple.com/library/ios/samplecode/UsingPhotosFramework/Introduction/Intro.html
这是 GitHub 上的一个照片选择器库,它使用 PhotoKit 看起来很有前途,因为它为您提供了所有选定图像/视频的 PHAsset 对象:https://github.com/guillermomuntaner/GMImagePicker
iOS 7 及更低版本
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
if (group) {
// If you want, you can filter just pictures or videos
// I just need videos so I do this:
[group setAssetsFilter:[ALAssetsFilter allVideos]];
[group enumerateAssetsUsingBlock:^(ALAsset *asset, NSUInteger index, BOOL *stop){
if (asset){
// You can now add this ALAsset in your own video picker.
// Note that you can only access the ALAsset as long as
// you maintain a reference to the ALAssetsLibrary
// Or if you want to process the video, you can create an AVAsset:
NSURL *url = asset.defaultRepresentation.url;
AVAsset *videoAsset = [AVAsset assetWithURL:url];
}
}];
}
} failureBlock:^(NSError *error) {
NSLog(@"error enumerating AssetLibrary groups %@\n", error);
}];