我正在使用UIImagePickerController來允許我的用戶從資產庫中選擇一個視頻。使用UIImagePickerController選擇電影時避免視頻壓縮?
當用戶在第二個屏幕上選擇「選擇」按鈕時,視圖顯示進度條和「壓縮視頻...」消息。
這是怎麼發生的?
有沒有辦法可以避免這種壓縮操作?
我正在使用UIImagePickerController來允許我的用戶從資產庫中選擇一個視頻。使用UIImagePickerController選擇電影時避免視頻壓縮?
當用戶在第二個屏幕上選擇「選擇」按鈕時,視圖顯示進度條和「壓縮視頻...」消息。
這是怎麼發生的?
有沒有辦法可以避免這種壓縮操作?
答:目前還沒有辦法控制的UIImagePickerController如何壓縮挑視頻。
我剛做了一些快速測試。使用我創建的測試應用程序,我選取了兩次相同的視頻 - 一次將videoQuality
屬性設置爲UIImagePickerControllerQualityTypeHigh
,一次將其設置爲UIImagePickerControllerQualityTypeLow
。複製的結果文件大小完全相同,大小爲15.1MB,幀大小爲360x480。原始大小爲72.5MB,幀大小爲480x640。顯然這個屬性不會影響所使用的壓縮。
設置的UIImagePickerController的視頻質量屬性設置爲「高」(UIImagePickerControllerQualityTypeHigh = 0)
從SDK文檔: 「如果顯示在圖像選擇器中錄製的電影,指定你不想要降低電影的視頻質量。「
看起來像在iPhone 4上,即使設置爲「高」,它仍然會壓縮,但質量比默認好得多。由於原始720p視頻編碼速度超過10 Mbit/sec,因此我可以看到它們爲什麼會以「高」壓縮! – CDeutsch 2010-08-03 20:35:10
我有類似的發現,甚至在某些壓縮中將其設置爲高結果(和「壓縮視頻」對話框)。 – Shizam 2010-09-07 00:16:30
在'UIImagePickerControllerQualityTypeHigh'的文檔中,最後一行說:「**如果在圖像選擇器中顯示錄製的影片,則指定您不想降低影片的視頻質量。這似乎表明,對於選擇視頻(而不是記錄),此屬性會影響它們在圖像選擇器的編輯屏幕中的顯示方式。 – memmons 2011-05-05 04:46:52
對於那些給出使用videoQuality屬性的建議,文檔明確指出它是視頻捕獲選項,而不是選擇器選項。
由於傑克在下面提到它,它也用於轉碼。看起來我太快閱讀文檔,因爲我沒有注意到轉碼提及。
該文件稱「視頻錄製**和轉碼質量**」。 – 2014-11-19 07:30:27
由於目前還沒有辦法避免使用UIImagePickerController進行壓縮,所以我想包含一些關於如何創建自己的圖像選擇器以免壓縮的想法。
這將允許訪問原始視頻文件:
的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文檔。
這裏是蘋果公司使用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);
}];
至今還沒有找到一個解決這個。有人有主意嗎? – Avalanchis 2010-07-08 13:47:24
看看下面的答案。它看起來不像開發人員可以影響壓縮。 – memmons 2011-05-05 05:31:29
Avalanchis - 這是2年前回答的。可能獲得接受? – memmons 2013-05-02 14:28:30