2013-11-25 13 views
11

Używam UIImagePickerController, aby wybrać wideo z galerii i skompresować ten film. Chcę wyłączyć kompresję, ale nie znajduję sposobu, aby to zrobić. Próbowałem również z ELCImagePickerController pokazuje wideo, ale wygląda jak obraz tylko tam nie ma ikony wideo lub czas trwania jak pokazuje w UIImagePickercontroller. Jak mogę to zrobić?Jak uniknąć kompresji po wybraniu wideo z UIImagePickerController w ios

Dzięki.

Odpowiedz

18

Wygląda na to, że nie można uniknąć kompresji za pomocą UIImagePickerController. Zobacz tę odpowiedź:

https://stackoverflow.com/a/5893066/406152

Próbowałem została, używając imagePicker.videoQuality = UIImagePickerControllerQualityTypeHigh; ale nadal robi kompresji. Ugh.

EDYTOWANIE:

Można jednak samodzielnie toczyć. Umożliwi to dostęp do surowych plików wideo:

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 
    }]; 
} 

Spójrz na dokumentacji PhotoKit o dostępie do zbiorów (chwile) i inne opcje.

Tutaj jest app próbki od firmy Apple PhotoKit, które mogą być modyfikowane za zdjęcia do kompletacji: https://developer.apple.com/library/ios/samplecode/UsingPhotosFramework/Introduction/Intro.html

Tutaj jest biblioteką zdjęć kompletacji na GitHub, który wykorzystuje PhotoKit który wygląda obiecująco, ponieważ daje PHAsset obiektów dla wszystkich wybranych zdjęć/wideo: https://github.com/guillermomuntaner/GMImagePicker

iOS 7 i poniżej

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); 
}]; 
4

Właściwie można uzyskać Oryginalny URL wideo bez kompresji wersja, za pomocą następującego kodu:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { 
    NSString *mediaType = info[UIImagePickerControllerMediaType]; 
    NSString *videoString = (NSString *)kUTTypeVideo; 
    NSString *movieString = (NSString *)kUTTypeMovie; 

    if ([mediaType isEqualToString:videoString] || [mediaType isEqualToString:movieString]) { 
     NSURL *videoRef = info[UIImagePickerControllerReferenceURL]; 
     PHFetchResult *refResult = [PHAsset fetchAssetsWithALAssetURLs:@[videoRef] options:nil];                                   
     PHVideoRequestOptions *videoRequestOptions = [[PHVideoRequestOptions alloc] init]; 
     videoRequestOptions.version = PHVideoRequestOptionsVersionOriginal; 
     [[PHImageManager defaultManager] requestAVAssetForVideo:[refResult firstObject] options:videoRequestOptions resultHandler:^(AVAsset *asset, AVAudioMix *audioMix, NSDictionary *info) { 
      if ([asset isKindOfClass:[AVURLAsset class]]) { 
        NSURL *originURL = [(AVURLAsset *)asset URL]; 
        // Now you have the URL of the original video. 
      } 
     }]; 
    } 
} 

Przypominamy, wywołanie requestAVAssetForVideo jest asynchroniczne, więc należy być ostrożnym, jeśli chcesz zapisać url z zablokowanym zmiennej zewnętrznej bloku metoda wywołującego .

1

W systemie iOS 11 można użyć właściwości "videoExportPreset". To nie jest oryginalny, ale przynajmniej mogę dostać więcej niż 1280x720 ...

if #available(iOS 11.0, *) { 
     picker.videoExportPreset = AVAssetExportPreset1920x1080 
} else { 
      // Fallback on earlier versions 
} 

//AVAssetExportPreset640x480 
//AVAssetExportPreset960x540 
//AVAssetExportPreset1280x720 
//AVAssetExportPreset1920x1080 
//AVAssetExportPreset3840x2160 
1

z IOS 11 można ustawić właściwość videoExportPreset do AVAssetExportPresetPassthrough dostać oryginalny:

if #available(iOS 11.0, *) { 
    picker.videoExportPreset = AVAssetExportPresetPassthrough 
} 

„Video kompresja ... "etykieta miga przez kilka milisekund, a następnie eksport jest zakończony.

@Diego Renau prawie miał poprawną odpowiedź.

Powiązane problemy