19

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?

Avalanchis
  • 4,500
  • 3
  • 39
  • 48

5 Answers5

15

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 to UIImagePickerControllerQualityTypeHigh and once with it set to UIImagePickerControllerQualityTypeLow. 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.

memmons
  • 40,222
  • 21
  • 149
  • 183
  • Is there any news about this? Would really appreciate that the users didnt have to wait for the "compressing" dialog when picking video to be uploaded. – David K Sep 05 '11 at 11:45
  • I agree. Your best bet is to file a radar with Apple. – memmons Sep 05 '11 at 15:45
  • Well it's a year later now and nothing has changed - iOS 6 still does not allow for importing the media URL directly :( – KPK Oct 20 '12 at 18:14
  • @Answerbot I totally agree. I also tried other qualities and it doesn't affect the result at all. – Stavash Nov 06 '13 at 09:39
4

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

cdeutsch
  • 3,847
  • 27
  • 25
  • Looks like on the iPhone 4 it will still compress even when set to "High" but the quality is much better then the default. I can see why they would compress at "High" since the original 720p video is encoded at more then 10 Mbit/sec! – cdeutsch Aug 03 '10 at 20:35
  • I have similar findings, even setting it to High results in some compression (and the 'Compressing Video' dialog). – Shizam Sep 07 '10 at 00:16
  • In the docs for `UIImagePickerControllerQualityTypeHigh` the last line says: "**If displaying a recorded movie in the image picker, specifies that you do not want to reduce the video quality of the movie.**". This seems to indicate that for picking videos (rather than recording) this property affects how they are displayed in the image picker's edit screen. – memmons May 05 '11 at 04:46
  • 2
    I just did some quick tests. I picked the same video two times -- once with QualityTypeHigh and once with QualityTypeLow. The resulting files that were copied over are _exactly the same size_, 15.1MB with a frame size of 360x480 while the original was 72.5MB with a frame size of 480x640. Apparently this property doesn't affect the compression used _at all_. – memmons May 05 '11 at 05:24
  • Having the same problem on iPhone 4S. 1080p video is compressed to 720p. Does anyone know if this happens on iPhone 5 as well? – Mihai Damian May 23 '13 at 07:55
4

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

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

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

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);
}];
jDutton
  • 941
  • 11
  • 13
2

Starting from iOS 11, you can specify the videoExportPreset and set it to AVAssetExportPresetPassthrough:

picker.videoExportPreset = AVAssetExportPresetPassthrough

This will still show the "compressing" progress bar though, but will be much faster, especially for smaller videos.

maxkonovalov
  • 3,651
  • 34
  • 36
0

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.